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"));
68 WRITE_WARNINGF(
TL(
"bluelight device is not compatible with mesosim (ignored for vehicle '%')"), v.
getID());
72 into.push_back(device);
82 double reactionDist) :
84 myReactionDist(reactionDist) {
86 std::cout <<
SIMTIME <<
" initialized device '" <<
id <<
"' with myReactionDist=" <<
myReactionDist <<
"\n";
97 double ,
double newSpeed) {
99 std::cout <<
SIMTIME <<
" device '" <<
getID() <<
"' notifyMove: newSpeed=" << newSpeed <<
"\n";
135 std::vector<const MSEdge*> upcomingEdges;
136 std::set<MSVehicle*, ComparatorIdLess> upcomingVehicles;
138 std::vector<MSLink*> upcomingLinks;
141 upcomingEdges.push_back(&l->getEdge());
143 affectedJunctionDist -= l->getLength();
144 if (affectedJunctionDist > 0 && l->isInternal()) {
145 upcomingLinks.push_back(l->getIncomingLanes()[0].viaLink);
149 for (
const MSEdge*
const e : upcomingEdges) {
153 if (lastStepInfluencedVehicles.count(v->getID()) > 0) {
154 lastStepInfluencedVehicles.erase(v->getID());
159 for (std::string vehID : lastStepInfluencedVehicles) {
169 for (
MSVehicle* veh2 : upcomingVehicles) {
170 assert(veh2 !=
nullptr);
171 if (veh2->getLane() ==
nullptr) {
174 if (std::find(upcomingEdges.begin(), upcomingEdges.end(), &veh2->getLane()->getEdge()) != upcomingEdges.end()) {
179 const int numLanes = (int)veh2->getLane()->getEdge().getNumLanes();
186 if (veh2->getLane()->getIndex() == numLanes - 1) {
190#ifdef DEBUG_BLUELIGHT_RESCUELANE
191 std::cout <<
"Refresh alignment for vehicle: " << veh2->getID()
192 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
193 <<
" alignment=" <<
toString(align) <<
"\n";
199 if (distanceDelta <= 10 && veh.
getID() != veh2->getID() &&
myInfluencedVehicles.count(veh2->getID()) > 0 && veh2->getSpeed() < 1) {
201 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
217 double reactionProb = (
223 if (veh2->isActionStep(
SIMSTEP) && reaction < reactionProb * veh2->getActionStepLengthSecs()) {
225 myInfluencedTypes.insert(std::make_pair(veh2->getID(), veh2->getVehicleType().getID()));
231 if (veh2->getLane()->getIndex() == numLanes - 1) {
236#ifdef DEBUG_BLUELIGHT_RESCUELANE
237 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" formingRescueLane=" << veh2->getID()
238 <<
" laneIndex=" << veh2->getLane()->getIndex() <<
" numLanes=" << numLanes
239 <<
" alignment=" <<
toString(align) <<
"\n";
242 if (std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID()) == influencedBy.end()) {
265 for (
MSLink* link : upcomingLinks) {
266 auto avi = link->getApproaching(&ego);
268 link->opened(avi.arrivalTime, avi.arrivalSpeed, avi.arrivalSpeed, ego.
getLength(),
279 const double timeToBrake = foe->
getSpeed() / 4.5;
280 if (timeToArrival <
TIME2STEPS(timeToBrake + 1)) {
282 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
283 speedTimeLine.push_back(std::make_pair(
SIMSTEP, foe->getSpeed()));
284 speedTimeLine.push_back(std::make_pair(avi.arrivalTime, 0));
297 && upcomingEdges.size() > 1) {
301 if (next ==
nullptr) {
302 next = upcomingEdges[1];
307 double bestJump = std::numeric_limits<double>::max();
308 double newPosLat = 0;
309 if (allowed !=
nullptr) {
310 for (
MSLane* nextCand : *allowed) {
311 for (
auto ili : nextCand->getIncomingLanes()) {
312 if (&ili.lane->getEdge() == currentEdge) {
314 if (jump < bestJump) {
321 newPosLat =
MAX2(-maxVehOffset, newPosLat);
322 newPosLat =
MIN2(maxVehOffset, newPosLat);
344 if (targetType !=
nullptr) {
345#ifdef DEBUG_BLUELIGHT_RESCUELANE
346 std::cout <<
SIMTIME <<
" device=" <<
getID() <<
" reset " << veh2->
getID() <<
"\n";
350 auto it = std::find(influencedBy.begin(), influencedBy.end(),
myHolder.
getID());
351 if (it != influencedBy.end()) {
352 influencedBy.erase(it);
355 if (influencedBy.size() == 0) {
368#ifdef DEBUG_BLUELIGHT
381#ifdef DEBUG_BLUELIGHT
393 if (tripinfoOut !=
nullptr) {
394 tripinfoOut->
openTag(
"bluelight");
401 if (key ==
"reactiondist") {
416 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_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
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists, nullptr otherwise.
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.
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
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.
MSDevice_Bluelight(SUMOVehicle &holder, const std::string &id, double reactionDist)
Constructor.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Saves arrival info.
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, double deflt, bool required)
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) 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 SUMOVehicle * > 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
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.
void setPreferredLateralAlignment(const LatAlignmentDefinition &latAlignment, double latAlignmentOffset=0.0)
Set vehicle's preferred lateral alignment.
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.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
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.
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 dimension
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)
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