45#define INFLUENCED_BY "rescueLane"
59 oc.
addDescription(
"device.bluelight.reactiondist",
"Bluelight Device",
TL(
"Set the distance at which other drivers react to the blue light and siren sound"));
61 oc.
addDescription(
"device.bluelight.mingapfactor",
"Bluelight Device",
TL(
"Reduce the minGap for reacting vehicles by the given factor"));
70 WRITE_WARNINGF(
TL(
"bluelight device is not compatible with mesosim (ignored for vehicle '%')"), v.
getID());
75 into.push_back(device);
85 const double reactionDist,
const double minGapFactor) :
87 myReactionDist(reactionDist),
88 myMinGapFactor(minGapFactor) {
90 std::cout <<
SIMTIME <<
" initialized device '" <<
id <<
"' with myReactionDist=" <<
myReactionDist <<
"\n";
101 double ,
double newSpeed) {
102#ifdef DEBUG_BLUELIGHT
103 std::cout <<
SIMTIME <<
" device '" <<
getID() <<
"' notifyMove: newSpeed=" << newSpeed <<
"\n";
139 std::vector<const MSEdge*> upcomingEdges;
140 std::set<MSVehicle*, ComparatorIdLess> upcomingVehicles;
142 std::vector<MSLink*> upcomingLinks;
145 upcomingEdges.push_back(&l->getEdge());
147 affectedJunctionDist -= l->getLength();
148 if (affectedJunctionDist > 0 && l->isInternal()) {
149 upcomingLinks.push_back(l->getIncomingLanes()[0].viaLink);
153 for (
const MSEdge*
const e : upcomingEdges) {
157 if (lastStepInfluencedVehicles.count(v->getID()) > 0) {
158 lastStepInfluencedVehicles.erase(v->getID());
163 for (std::string vehID : lastStepInfluencedVehicles) {
173 for (
MSVehicle* veh2 : upcomingVehicles) {
174 assert(veh2 !=
nullptr);
175 if (veh2->getLane() ==
nullptr) {
178 if (std::find(upcomingEdges.begin(), upcomingEdges.end(), &veh2->getLane()->getEdge()) != upcomingEdges.end()) {
183 const int numLanes = (int)veh2->getLane()->getEdge().getNumLanes();
190 if (veh2->getLane()->getIndex() == numLanes - 1) {
194#ifdef DEBUG_BLUELIGHT_RESCUELANE
195 std::cout <<
"Refresh alignment for vehicle: " << veh2->getID()
196 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
197 <<
" alignment=" <<
toString(align) <<
"\n";
203 if (distanceDelta <= 10 && veh.
getID() != veh2->getID() &&
myInfluencedVehicles.count(veh2->getID()) > 0 && veh2->getSpeed() < 1) {
205 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
221 double reactionProb = (
227 if (veh2->isActionStep(
SIMSTEP) && reaction < reactionProb * veh2->getActionStepLengthSecs()) {
229 myInfluencedTypes.insert(std::make_pair(veh2->getID(), veh2->getVehicleType().getID()));
239 if (veh2->getLane()->getIndex() == numLanes - 1) {
246#ifdef DEBUG_BLUELIGHT_RESCUELANE
247 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" formingRescueLane=" << veh2->getID()
248 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
249 <<
" alignment=" <<
toString(align) <<
"\n";
252 if (std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID()) == influencedBy.end()) {
275 for (
MSLink* link : upcomingLinks) {
276 auto avi = link->getApproaching(&ego);
278 link->opened(avi.arrivalTime, avi.arrivalSpeed, avi.arrivalSpeed, ego.
getLength(),
282 if (!foe->isVehicle()) {
292 const double timeToBrake = foe->
getSpeed() / 4.5;
293 if (timeToArrival <
TIME2STEPS(timeToBrake + 1)) {
295 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
296 speedTimeLine.push_back(std::make_pair(
SIMSTEP, foe->getSpeed()));
297 speedTimeLine.push_back(std::make_pair(avi.arrivalTime, 0));
310 && upcomingEdges.size() > 1) {
314 if (next ==
nullptr) {
315 next = upcomingEdges[1];
320 double bestJump = std::numeric_limits<double>::max();
321 double newPosLat = 0;
322 if (allowed !=
nullptr) {
323 for (
MSLane* nextCand : *allowed) {
324 for (
auto ili : nextCand->getIncomingLanes()) {
325 if (&ili.lane->getEdge() == currentEdge) {
327 if (jump < bestJump) {
334 newPosLat =
MAX2(-maxVehOffset, newPosLat);
335 newPosLat =
MIN2(maxVehOffset, newPosLat);
357 if (targetType !=
nullptr) {
358#ifdef DEBUG_BLUELIGHT_RESCUELANE
359 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" reset " << veh2->
getID() <<
"\n";
363 auto it = std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID());
364 if (it != influencedBy.end()) {
365 influencedBy.erase(it);
368 if (influencedBy.size() == 0) {
381#ifdef DEBUG_BLUELIGHT
394#ifdef DEBUG_BLUELIGHT
406 if (tripinfoOut !=
nullptr) {
407 tripinfoOut->
openTag(
"bluelight");
414 if (key ==
"reactiondist") {
429 if (key ==
"reactiondist") {
#define WRITE_WARNINGF(...)
LatAlignmentDefinition
Possible ways to choose the lateral alignment, i.e., how vehicles align themselves within their lane.
@ RIGHT
drive on the right side
@ LEFT
drive on the left side
@ ARBITRARY
maintain the current alignment
@ SUMO_ATTR_JM_STOPLINE_GAP
@ SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual void prepareStep()
virtual void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getLength() const
Returns the vehicle's length.
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
void setCollisionMinGapFactor(const double factor)
Sets a new value for the factor of minGap that must be maintained to avoid a collision event.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
A device which collects info on the vehicle trip (mainly on departure and arrival)
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks for waiting steps when the vehicle moves.
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this device. Throw exception for unsupported key
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
std::set< std::string > myInfluencedVehicles
MSDevice_Bluelight(SUMOVehicle &holder, const std::string &id, const double reactionDist, const double minGapFactor)
Constructor.
double myMinGapFactor
min gap reduction of other vehicles
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Bluelight-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
void resetVehicle(MSVehicle *veh2, const std::string &targetTypeID)
restore type of influenced vehicle
double myReactionDist
reaction distance of other vehicle (i.e. due to different noise levels of the siren)
Parameterised::Map myInfluencedTypes
~MSDevice_Bluelight()
Destructor.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves departure info on insertion.
const std::string deviceName() const
return the name for this type of device
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves arrival info.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
A road/street connecting two junctions.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
Get the allowed lanes to reach the destination-edge.
const MSEdge * getInternalFollowingEdge(const MSEdge *followerAfterInternal, SUMOVehicleClass vClass) const
Representation of a lane in the micro simulation.
double getLength() const
Returns the lane's length.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
MSEdge & getEdge() const
Returns the lane's edge.
double getWidth() const
Returns the lane's width.
std::vector< const SUMOTrafficObject * > BlockingFoes
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Changes the wished vehicle speed / lanes.
void setLaneChangeMode(int value)
Sets lane changing behavior.
void setSpeedMode(int speedMode)
Sets speed-constraining behaviors.
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
The class responsible for building and deletion of vehicles.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
Representation of a vehicle in the micro simulation.
const std::vector< const MSLane * > getUpcomingLanesUntil(double distance) const
Returns the upcoming (best followed by default 0) sequence of lanes to continue the route starting at...
void setTentativeLaneAndPosition(MSLane *lane, double pos, double posLat=0)
set tentative lane and position during insertion to ensure that all cfmodels work (some of them requi...
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
MSAbstractLaneChangeModel & getLaneChangeModel()
void enterLaneAtMove(MSLane *enteredLane, bool onTeleporting=false)
Update when the vehicle enters a new lane in the move step.
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
void leaveLane(const MSMoveReminder::Notification reason, const MSLane *approachedLane=0)
Update of members if vehicle leaves a new lane in the lane change step or at arrival.
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
double getLatOffset(const MSLane *lane) const
Get the offset that that must be added to interpret myState.myPosLat for the given lane.
const MSLane * getLane() const
Returns the lane the vehicle is on.
Influencer & getInfluencer()
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
double getSpeed() const
Returns the vehicle's current speed.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
double getPositionOnLane() const
Get the vehicle's position along the lane.
The car-following model and parameter.
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
const std::string & getID() const
Returns the name of the vehicle type.
double getMinGap() const
Get the free space in front of vehicles of this class.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
void setPreferredLateralAlignment(const LatAlignmentDefinition &latAlignment, double latAlignmentOffset=0.0)
Set vehicle's preferred lateral alignment.
void setMinGap(const double &minGap)
Set a new value for this type's minimum gap.
const SUMOVTypeParameter & getParameter() const
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
virtual void setParameter(const std::string &key, const std::string &value)
Sets a parameter.
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimensions
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Representation of a vehicle, person, or container.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSpeed() const =0
Returns the object's current speed.
double getFloatParam(const std::string ¶mName, const bool required=false, const double deflt=INVALID_DOUBLE) const
Retrieve a floating point parameter for the traffic object.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
Structure representing possible vehicle parameter.
std::string getLCParamString(const SumoXMLAttr attr, const std::string &defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
Representation of a vehicle.
Structure representing possible vehicle parameter.
std::vector< std::string > getVector()
return vector of strings
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter