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";
142 std::vector<const MSEdge*> upcomingEdges;
143 std::set<MSVehicle*, ComparatorIdLess> upcomingVehicles;
145 std::vector<MSLink*> upcomingLinks;
148 upcomingEdges.push_back(&l->getEdge());
150 affectedJunctionDist -= l->getLength();
151 if (affectedJunctionDist > 0 && l->isInternal()) {
152 upcomingLinks.push_back(l->getIncomingLanes()[0].viaLink);
156 for (
const MSEdge*
const e : upcomingEdges) {
160 if (lastStepInfluencedVehicles.count(v->getID()) > 0) {
161 lastStepInfluencedVehicles.erase(v->getID());
166 for (std::string vehID : lastStepInfluencedVehicles) {
176 for (
MSVehicle* veh2 : upcomingVehicles) {
177 assert(veh2 !=
nullptr);
178 if (veh2->getLane() ==
nullptr) {
181 if (std::find(upcomingEdges.begin(), upcomingEdges.end(), &veh2->getLane()->getEdge()) != upcomingEdges.end()) {
186 const int numLanes = (int)veh2->getLane()->getEdge().getNumLanes();
193 if (veh2->getLane()->getIndex() == numLanes - 1) {
197#ifdef DEBUG_BLUELIGHT_RESCUELANE
198 std::cout <<
"Refresh alignment for vehicle: " << veh2->getID()
199 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
200 <<
" alignment=" <<
toString(align) <<
"\n";
206 if (distanceDelta <= 10 && veh.
getID() != veh2->getID() &&
myInfluencedVehicles.count(veh2->getID()) > 0 && veh2->getSpeed() < 1) {
208 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
224 double reactionProb = (
230 if (veh2->isActionStep(
SIMSTEP) && reaction < reactionProb * veh2->getActionStepLengthSecs()) {
232 myInfluencedTypes.insert(std::make_pair(veh2->getID(), veh2->getVehicleType().getID()));
242 if (veh2->getLane()->getIndex() == numLanes - 1) {
249#ifdef DEBUG_BLUELIGHT_RESCUELANE
250 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" formingRescueLane=" << veh2->getID()
251 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
252 <<
" alignment=" <<
toString(align) <<
"\n";
255 if (std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID()) == influencedBy.end()) {
278 for (
MSLink* link : upcomingLinks) {
279 auto avi = link->getApproaching(&ego);
281 link->opened(avi.arrivalTime, avi.arrivalSpeed, avi.arrivalSpeed, ego.
getLength(),
285 if (!foe->isVehicle()) {
296 if (timeToArrival <
TIME2STEPS(timeToBrake + 1)) {
298 const double decel = 0.5 * foe->getSpeed() * foe->getSpeed() / avi.dist;
299 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
300 speedTimeLine.push_back(std::make_pair(
SIMSTEP, foe->getSpeed()));
301 speedTimeLine.push_back(std::make_pair(
SIMSTEP +
TIME2STEPS(foe->getSpeed() / decel), 0));
314 && upcomingEdges.size() > 1) {
318 if (next ==
nullptr) {
319 next = upcomingEdges[1];
324 double bestJump = std::numeric_limits<double>::max();
325 double newPosLat = 0;
326 if (allowed !=
nullptr) {
327 for (
MSLane* nextCand : *allowed) {
328 for (
auto ili : nextCand->getIncomingLanes()) {
329 if (&ili.lane->getEdge() == currentEdge) {
331 if (jump < bestJump) {
338 newPosLat =
MAX2(-maxVehOffset, newPosLat);
339 newPosLat =
MIN2(maxVehOffset, newPosLat);
361 if (targetType !=
nullptr) {
362#ifdef DEBUG_BLUELIGHT_RESCUELANE
363 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" reset " << veh2->
getID() <<
"\n";
367 auto it = std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID());
368 if (it != influencedBy.end()) {
369 influencedBy.erase(it);
372 if (influencedBy.size() == 0) {
385#ifdef DEBUG_BLUELIGHT
398#ifdef DEBUG_BLUELIGHT
410 if (tripinfoOut !=
nullptr) {
411 tripinfoOut->
openTag(
"bluelight");
418 if (key ==
"reactiondist") {
433 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_SPEEDGAIN_REMAIN_TIME
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
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.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
double getFloatParam(const std::string ¶mName, const bool required=false, const double deflt=INVALID_DOUBLE, bool checkDist=true) const
Retrieve a floating point parameter for the traffic object.
Structure representing possible vehicle parameter.
static double getDefaultDecel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default deceleration for the given vehicle class This needs to be a function because the ...
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
#define UNUSED_PARAMETER(x)