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";
104 double ,
double newSpeed) {
105#ifdef DEBUG_BLUELIGHT
106 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) {
209 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
225 double reactionProb = (
231 if (veh2->isActionStep(
SIMSTEP) && reaction < reactionProb * veh2->getActionStepLengthSecs()) {
233 myInfluencedTypes.insert(std::make_pair(veh2->getID(), veh2->getVehicleType().getID()));
243 if (veh2->getLane()->getIndex() == numLanes - 1) {
250#ifdef DEBUG_BLUELIGHT_RESCUELANE
251 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" formingRescueLane=" << veh2->getID()
252 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
253 <<
" alignment=" <<
toString(align) <<
"\n";
256 if (std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID()) == influencedBy.end()) {
279 for (
MSLink* link : upcomingLinks) {
280 auto avi = link->getApproaching(&ego);
282 link->opened(avi.arrivalTime, avi.arrivalSpeed, avi.arrivalSpeed, ego.
getLength(),
286 if (!foe->isVehicle()) {
297 if (timeToArrival <
TIME2STEPS(timeToBrake + 1)) {
299 const double decel = 0.5 * foe->getSpeed() * foe->getSpeed() / avi.dist;
300 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
301 speedTimeLine.push_back(std::make_pair(
SIMSTEP, foe->getSpeed()));
302 speedTimeLine.push_back(std::make_pair(
SIMSTEP +
TIME2STEPS(foe->getSpeed() / decel), 0));
317 if (targetType !=
nullptr) {
318#ifdef DEBUG_BLUELIGHT_RESCUELANE
319 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" reset " << veh2->
getID() <<
"\n";
323 auto it = std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID());
324 if (it != influencedBy.end()) {
325 influencedBy.erase(it);
328 if (influencedBy.size() == 0) {
341#ifdef DEBUG_BLUELIGHT
354#ifdef DEBUG_BLUELIGHT
366 if (tripinfoOut !=
nullptr) {
367 tripinfoOut->
openTag(
"bluelight");
374 if (key ==
"reactiondist") {
389 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
@ SUMO_ATTR_JM_STOPLINE_GAP
@ SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD
@ SUMO_ATTR_LCA_SPEEDGAIN_REMAIN_TIME
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
@ SUMO_ATTR_JM_DRIVE_RED_SPEED
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
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.
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.
Representation of a lane in the micro simulation.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
std::vector< const SUMOTrafficObject * > BlockingFoes
Notification
Definition of a vehicle state.
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...
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
MSAbstractLaneChangeModel & getLaneChangeModel()
Position getPosition(const double offset=0) const
Return current position (x/y, cartesian)
void replaceVehicleType(const MSVehicleType *type)
Replaces the current vehicle type by the one given.
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 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 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 ...
double getJMParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
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)