36 #define DEBUG_COND (true)
50 oc.
addDescription(
"device.glosa.range",
"GLOSA Device",
TL(
"The communication range to the traffic light"));
53 oc.
addDescription(
"device.glosa.max-speedfactor",
"GLOSA Device",
TL(
"The maximum speed factor when approaching a green light"));
56 oc.
addDescription(
"device.glosa.min-speed",
"GLOSA Device",
TL(
"Minimum speed when coasting towards a red light"));
59 oc.
addDescription(
"device.glosa.add-switchtime",
"GLOSA Device",
TL(
"Additional time the vehicle shall need to reach the intersection after the signal turns green"));
62 oc.
addDescription(
"device.glosa.override-safety",
"GLOSA Device",
TL(
"Override safety features - ignore the current light state, always follow GLOSA's predicted state"));
65 oc.
addDescription(
"device.glosa.ignore-cfmodel",
"GLOSA Device",
TL(
"Vehicles follow a perfect speed calculation - ignore speed calculations from the CF model if not safety critical"));
80 into.push_back(device);
93 double addSwitchTime,
bool overrideSafety,
bool ignoreCFModel) :
96 myNextTLSLink(nullptr),
100 myMaxSpeedFactor(maxSpeedFactor),
101 myAddSwitchTime(addSwitchTime),
102 myOverrideSafety(overrideSafety),
103 myIgnoreCFModel(ignoreCFModel),
104 mySpeedAdviceActive(false)
117 double newPos,
double ) {
125 std::cout <<
SIMTIME <<
" veh=" <<
myVeh.
getID() <<
" d=" <<
myDistance <<
" ttJ=" << timeToJunction <<
" ttS=" << timeToSwitch <<
"\n";
131 if (timeToJunction > timeToSwitch) {
139 std::cout <<
" vMax2=" << vMax2 <<
" ttJ2=" << timetoJunction2 <<
" yellowSlack=" << yellowSlack <<
"\n";
142 if (timetoJunction2 <= (timeToSwitch + yellowSlack)) {
173 if ((*linkIt)->isTLSControlled()) {
179 lane = (*linkIt)->getViaLaneOrLane();
192 double tlsRange = 1e10;
197 WRITE_WARNINGF(
TL(
"Invalid value '%' for parameter 'device.glosa.range' of traffic light '%'"),
214 assert(tlsLink !=
nullptr);
216 assert(tl !=
nullptr);
218 const int n = (int)phases.size();
221 for (
int i = 1; i < n; i++) {
222 const auto& phase = phases[(cur + i) % n];
223 const char ls = phase->getState()[tlsLink->
getTLIndex()];
224 if ((tlsLink->
haveRed() && (ls ==
'g' || ls ==
'G'))
225 || (tlsLink->
haveGreen() && ls !=
'g' && ls !=
'G')) {
228 result += phase->duration;
241 const double remaining_time = remaining_dist / vMax;
242 return accel_time + remaining_time;
274 const double v = speed;
275 const double t = time;
278 return v * t + a * t * t / 2;
287 const double p_half = v / a;
288 const double t = -p_half + sqrt(p_half * p_half + 2 * d / a);
306 const double t = timeToSwitch;
309 const double w = vMax;
310 const double s = distance;
321 const double rootConst = a * a * t * t - 2.0 * a * w * t + 2 * a * s;
323 if (rootConst >= 0) {
324 vConst = sqrt(rootConst) - a * t + w;
332 const double sign0 = -1;
333 const double root_argument = a * d * ((2.0 * d * (s - (w * t))) - ((v - w) * (v - w)) + (a * ((d * (t * t)) + (2.0 * (s - (t * v))))));
334 if (root_argument < 0) {
336 WRITE_WARNINGF(
"GLOSA error 1 root_argument=% s=% t=% v=%", root_argument, s, t, v);
340 const double x = (((a * (v - (d * t))) + (d * w) - sign0 * sqrt(root_argument)) / (d + a));
341 double y = (v - x) / d;
345 if (s < (w * w - x * x) / 2.0 / a) {
348 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
358 if (!(x >= u && x <= w && y < t)) {
360 WRITE_WARNINGF(
"GLOSA error 2 x=% y=% s=% t=% v=%", x, y, s, t, v);
367 const double targetSpeed = x;
368 const double duration =
MAX2(y,
TS);
371 std::cout <<
" targetSpeed=" << targetSpeed <<
" duration=" << y <<
"\n";
375 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
398 if (key ==
"minSpeed") {
413 if (key ==
"minSpeed") {
#define WRITE_WARNINGF(...)
@ SUMO_ATTR_JM_DRIVE_AFTER_YELLOW_TIME
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void setChosenSpeedFactor(const double factor)
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
double getChosenSpeedFactor() const
Returns the precomputed factor by which the driver wants to be faster than the speed limit.
SUMOTime getDeparture() const
Returns this vehicle's real departure time.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
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)
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
const MSLink * myNextTLSLink
the upcoming traffic light
MSVehicle & myVeh
myHolder cast to needed type
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
bool mySpeedAdviceActive
If speedFactor is currently beeing changed by the GLOSA device.
double myAddSwitchTime
Additional time the vehicle shall need to reach the intersection after the signal turns green.
double myMaxSpeedFactor
maximum speed factor when trying to reach green light
double myRange
maximum communication range
void adaptSpeed(double distance, double timeToJunction, double timeToSwitch)
adapt speed to reach junction at green
double myMinSpeed
minimum approach speed towards red light
~MSDevice_GLOSA()
Destructor.
MSDevice_GLOSA(SUMOVehicle &holder, const std::string &id, double minSpeed, double range, double maxSpeedFactor, double addSwitchTime, bool overrideSafety, bool ignoreCFModel)
Constructor.
double time_to_junction_at_continuous_accel(double d, double v)
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_GLOSA-options.
double myDistance
the distance to the upcoming traffic light
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
updates next tls link
double distance_at_continuous_accel(double speed, double time)
double earliest_arrival(double speed, double distance)
return minimum number of seconds to reach the junction
double myOriginalSpeedFactor
original speed factor
static void cleanup()
resets counters
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
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
updates distance and computes speed advice
static double getTimeToSwitch(const MSLink *tlsLink)
compute time to next (relevant) switch
const std::string deviceName() const
return the name for this type of device
bool myIgnoreCFModel
if true ignore non-critical speed calculations from the CF model, follow GLOSA's perfect speed calcul...
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.
bool isInternal() const
return whether this edge is an internal edge
Representation of a lane in the micro simulation.
static std::vector< MSLink * >::const_iterator succLinkSec(const SUMOVehicle &veh, int nRouteSuccs, const MSLane &succLinkSource, const std::vector< MSLane * > &conts)
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
double getLength() const
Returns the lane's length.
bool isLinkEnd(std::vector< MSLink * >::const_iterator &i) const
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.
int getTLIndex() const
Returns the TLS index.
const MSTrafficLightLogic * getTLLogic() const
Returns the TLS index.
bool haveRed() const
Returns whether this link is blocked by a red (or redyellow) traffic light.
Notification
Definition of a vehicle state.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The parent class for traffic light logics.
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
virtual const Phases & getPhases() const =0
Returns the phases of this tls program.
void setSpeedTimeLine(const std::vector< std::pair< SUMOTime, double > > &speedTimeLine)
Sets a new velocity timeline.
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
void updateBestLanes(bool forceRebuild=false, const MSLane *startLane=0)
computes the best lanes to use in order to continue the route
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
Influencer & getInfluencer()
double getSpeed() const
Returns the vehicle's current speed.
double getPositionOnLane() const
Get the vehicle's position along the lane.
const MSLane * getLane() const
Returns the lane the vehicle is on.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
const SUMOVTypeParameter & getParameter() const
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.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
Representation of a vehicle, person, or container.
bool getBoolParam(const std::string ¶mName, const bool required=false, const bool deflt=false) const
Retrieve a boolean parameter for the traffic object.
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.
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.
Representation of a vehicle.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter