35 #define DEBUG_COND (true)
49 oc.
addDescription(
"device.glosa.range",
"GLOSA Device",
TL(
"The communication range to the traffic light"));
52 oc.
addDescription(
"device.glosa.max-speedfactor",
"GLOSA Device",
TL(
"The maximum speed factor when approaching a green light"));
55 oc.
addDescription(
"device.glosa.min-speed",
"GLOSA Device",
TL(
"Minimum speed when coasting towards a red light"));
67 into.push_back(device);
82 myNextTLSLink(nullptr),
86 myMaxSpeedFactor(maxSpeedFactor)
99 double newPos,
double ) {
107 std::cout <<
SIMTIME <<
" veh=" <<
myVeh.
getID() <<
" d=" <<
myDistance <<
" ttJ=" << timeToJunction <<
" ttS=" << timeToSwitch <<
"\n";
111 if (timeToJunction > timeToSwitch) {
119 std::cout <<
" vMax2=" << vMax2 <<
" ttJ2=" << timetoJunction2 <<
" yellowSlack=" << yellowSlack <<
"\n";
122 if (timetoJunction2 <= (timeToSwitch + yellowSlack)) {
148 if ((*linkIt)->isTLSControlled()) {
154 lane = (*linkIt)->getViaLaneOrLane();
166 double tlsRange = 1e10;
171 WRITE_WARNINGF(
TL(
"Invalid value '%' for parameter 'device.glosa.range' of traffic light '%'"),
187 assert(tlsLink !=
nullptr);
189 assert(tl !=
nullptr);
191 const int n = (int)phases.size();
194 for (
int i = 1; i < n; i++) {
195 const auto& phase = phases[(cur + i) % n];
196 const char ls = phase->getState()[tlsLink->
getTLIndex()];
197 if ((tlsLink->
haveRed() && (ls ==
'g' || ls ==
'G'))
198 || (tlsLink->
haveGreen() && ls !=
'g' && ls !=
'G')) {
201 result += phase->duration;
214 const double remaining_time = remaining_dist / vMax;
215 return accel_time + remaining_time;
247 const double v = speed;
248 const double t = time;
251 return v * t + a * t * t / 2;
260 const double p_half = v / a;
261 const double t = -p_half + sqrt(p_half * p_half + 2 * d / a);
277 if (timeToJunction < timeToSwitch
280 const double t = timeToSwitch;
284 const double w = vMax;
285 const double s = distance;
293 const double sign0 = -1;
294 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))))));
295 if (root_argument < 0) {
297 WRITE_WARNINGF(
"GLOSA error 1 root_argument=% s=% t=% v=%", root_argument, s, t, v);
301 const double x = (((a * (v - (d * t))) + (d * w) - sign0 * sqrt(root_argument)) / (d + a));
302 const double y = t - (w - x) / d;
303 if (!(x >= u && x <= w && y > 0 && y < t)) {
305 WRITE_WARNINGF(
"GLOSA error 2 x=% y=% s=% t=% v=%", x, y, s, t, v);
309 const double targetSpeed = x;
310 const double duration = y;
313 std::cout <<
" targetSpeed=" << targetSpeed <<
" duration=" << duration <<
"\n";
316 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
322 std::vector<std::pair<SUMOTime, double> > speedTimeLine;
324 speedTimeLine.push_back(std::make_pair(
MSNet::getInstance()->getCurrentTimeStep(), vMax));
342 if (key ==
"minSpeed") {
357 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.
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.
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.
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
MSDevice_GLOSA(SUMOVehicle &holder, const std::string &id, double minSpeed, double range, double maxSpeedFactor)
Constructor.
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string ¶mName, const double deflt, bool required=false)
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 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).
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.
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.
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