 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
45 #define DEFAULT_VEH_LENGTH_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap)
47 #define MESO_MIN_SPEED (0.05)
53 #define DEBUG_COND (myEdge.isSelected())
54 #define DEBUG_COND2(obj) ((obj != 0 && (obj)->isSelected()))
68 double length,
double speed,
72 double jamThresh,
bool multiQueue,
bool junctionControl) :
73 Named(id), myEdge(parent), myNextSegment(next),
74 myLength(length), myIndex(idx),
75 myTau_ff((
SUMOTime)(tauff / parent.getLanes().size())),
76 myTau_fj((
SUMOTime)(taufj / parent.getLanes().size())),
77 myTau_jf((
SUMOTime)(taujf / parent.getLanes().size())),
78 myTau_jj((
SUMOTime)(taujj / parent.getLanes().size())),
81 myCapacity(length * parent.getLanes().size()),
83 myJunctionControl(junctionControl),
84 myTLSPenalty(
MSGlobals::gMesoTLSPenalty > 0 &&
86 myNextSegment == nullptr && (
90 myMinorPenalty(
MSGlobals::gMesoMinorPenalty > 0 &&
92 myNextSegment == nullptr &&
96 parent.hasMinorLink()),
102 myCarQues.push_back(std::vector<MEVehicle*>());
105 const std::vector<MSLane*>& lanes = parent.
getLanes();
106 while (
myCarQues.size() < lanes.size()) {
107 myCarQues.push_back(std::vector<MEVehicle*>());
112 const std::vector<MSLane*>*
const allowed = parent.
allowedLanes(*edge);
113 assert(allowed != 0);
114 assert(allowed->size() > 0);
115 for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
116 std::vector<MSLane*>::const_iterator it = std::find(lanes.begin(), lanes.end(), *j);
117 myFollowerMap[edge].push_back((
int)distance(lanes.begin(), it));
127 myEdge(myDummyParent),
128 myNextSegment(nullptr), myLength(0), myIndex(0),
129 myTau_ff(0), myTau_fj(0), myTau_jf(0), myTau_jj(0), myTau_length(1),
130 myHeadwayCapacity(0), myCapacity(0), myJunctionControl(false),
132 myMinorPenalty(false) {
198 return std::numeric_limits<double>::max();
200 #ifdef DEBUG_JAMTHRESHOLD
214 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
215 (*i)->addReminder(data);
223 std::vector<MSMoveReminder*>::iterator it = std::find(
229 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
230 (*i)->removeReminder(data);
240 SUMOTime earliestExitTime = currentTime;
241 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
242 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
243 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
301 SUMOTime earliestExitTime = currentTime;
302 count += (int)k->size();
303 for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
304 v += (*veh)->getConservativeSpeed(earliestExitTime);
305 earliestExitTime +=
tauWithVehLength(tau, (*veh)->getVehicleType().getLengthWithGap());
321 for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
332 assert(std::find(cars.begin(), cars.end(), v) != cars.end());
337 if (v == cars.back()) {
344 cars.erase(std::find(cars.begin(), cars.end(), v));
363 SUMOTime earliestLeave = earliestEntry;
364 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
379 if (nextEdge ==
nullptr) {
385 if (&link->getLane()->getEdge() == nextEdge) {
391 if (lane != bestLane) {
392 for (
MSLink*
const link : lane->getLinkCont()) {
393 if (&link->getLane()->getEdge() == nextEdge) {
412 std::cout <<
" link=0";
433 return (link ==
nullptr
459 if (link !=
nullptr) {
512 int nextQueIndex = 0;
518 nextQueIndex = indices[0];
519 for (std::vector<int>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
526 std::vector<MEVehicle*>& cars =
myCarQues[nextQueIndex];
538 if (!isDepart && leaderOut > tleave &&
overtake()) {
539 if (cars.size() == 1) {
543 cars.insert(cars.begin() + 1, veh);
546 cars.insert(cars.begin(), veh);
563 }
else if (
myIndex == 0 || afterTeleport) {
568 if (newLeader !=
nullptr) {
581 if (k->size() == 1) {
602 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
603 (*i)->updateDetectors(currentTime,
false);
606 (*i)->setEventTime(newEvent);
624 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
635 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
637 result =
myCarQues[i].back()->getEventTime();
650 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
661 for (
const std::string&
id : vehIds) {
682 std::vector<const MEVehicle*>
684 std::vector<const MEVehicle*> result;
686 result.insert(result.end(), k->begin(), k->end());
695 if (k->size() > 0 && (*k).back()->getWaitingTime() > 0) {
712 if (link !=
nullptr) {
734 if (link !=
nullptr) {
746 double maxPenalty = 0;
750 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
double getGreenFraction() const
Returns the average proportion of green time to cycle time.
A vehicle from the mesoscopic point of view.
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
bool isRoundabout() const
@ NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
bool havePriority() const
Returns whether this link is a major link.
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
virtual void unlock() const
release exclusive access to the mesoscopic state
Representation of a lane in the micro simulation.
Base class for objects which have an id.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
double getTLSCapacity(const MEVehicle *veh) const
Returns the average green time as fraction of cycle time.
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
void addWaiting(SUMOVehicle *vehicle) const
Adds a vehicle to the list of waiting vehicles.
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
A single mesoscopic segment (cell)
Static storage of an output device and its base (abstract) implementation.
int myNumCars
The cached value for the number of cars.
void loadState(const std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const int queIdx)
Loads the state of this segment with the given parameters.
bool changeSegment(MEVehicle *veh, SUMOTime leaveTime, MESegment *const toSegment, const bool ignoreLink=false)
change to the next segment this handles combinations of the following cases: (ending / continuing rou...
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
SUMOTime myLastHeadway
the last headway
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
bool hasSpaceFor(const MEVehicle *veh, SUMOTime entryTime, bool init=false) const
Returns whether the given vehicle would still fit into the segment.
const MSEdge & myEdge
The microsim edge this segment belongs to.
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
@ SUMO_TAG_VIEWSETTINGS_VEHICLES
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
static MSEdge myDummyParent
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
bool isTLSControlled() const
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge's que.
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
Something on a lane to be noticed about vehicle movement.
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
double getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
static bool gMesoOvertaking
bool hasBlockedLeader() const
whether a leader in any queue is blocked
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
void addLeaderCar(MEVehicle *veh, MSLink *link)
Adds the given car to the leading vehicles.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
static const double DO_NOT_PATCH_JAM_THRESHOLD
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
MSLane * getLane() const
Returns the connected lane.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
bool isStopped() const
Returns whether the vehicle is at a stop.
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
double getImpatience() const
Returns this vehicles impatience.
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
@ NODETYPE_TRAFFIC_LIGHT_NOJUNCTION
const double myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
@ SUMO_TAG_SEGMENT
segment of a lane
static SUMOTime gMesoMinorPenalty
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength, double impatience, double decel, SUMOTime waitingTime, double posLat=0, BlockingFoes *collectFoes=nullptr, bool ignoreRed=false, const SUMOVehicle *ego=nullptr) const
Returns the information whether the link may be passed.
#define DEFAULT_VEH_LENGTH_WITH_GAP
double getFlow() const
returns flow based on headway
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
const int myIndex
Running number of the segment in the edge.
SUMOTime getStoptime(const MESegment *const seg, SUMOTime time) const
Returns until when to stop at the given segment.
void processStop()
ends the current stop and performs loading/unloading
A road/street connecting two junctions.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
@ SUMO_ATTR_TIME
trigger: the time of the step
SUMOTime getMesoTLSPenalty() const
Returns the time penalty for passing a tls-controlled link (meso)
@ NOTIFICATION_SEGMENT
The vehicle changes the segment (meso only)
const bool myTLSPenalty
Whether tls penalty is enabled.
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
SUMOTime myEntryBlockTime
MSEdge & getEdge() const
Returns the lane's edge.
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
MESegment * getSegment() const
Returns the current segment the vehicle is on.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static MELoop * gMesoNet
mesoscopic simulation infrastructure
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
std::vector< SUMOTime > myBlockTimes
The block times.
bool free() const
return whether this segment is considered free as opposed to jammed
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
const bool myJunctionControl
Whether junction control is enabled.
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge)
double myA
slope and axis offset for the jam-jam headway function
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed
const bool myMinorPenalty
Whether minor penalty is enabled.
void send(MEVehicle *veh, MESegment *next, SUMOTime time, const MSMoveReminder::Notification reason)
Removes the vehicle from the segment, adapting its parameters.
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
const std::string & getID() const
Returns the name of the vehicle.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
int getQueIndex() const
Returns the index of the que the vehicle is in.
const double myLength
The segment's length.
const double myCapacity
The number of lanes * the length.
SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
void onDepart()
Called when the vehicle is inserted into the network.
The class responsible for building and deletion of vehicles.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
static bool gMesoLimitedJunctionControl
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, double length, double speed, int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, double jamThresh, bool multiQueue, bool junctionControl)
constructor
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0)
void writeVehicles(OutputDevice &of) const
void setSpeed(double newSpeed, SUMOTime currentTime, double jamThresh=DO_NOT_PATCH_JAM_THRESHOLD)
reset mySpeed and patch the speed of all vehicles in it. Also set/recompute myJamThreshold
virtual void lock() const
grant exclusive access to the mesoscopic state
static MESegment myVaporizationTarget
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
const std::string & getID() const
Returns the id.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
static bool useMultiQueue(bool multiQueue, const MSEdge &parent)
whether the segment requires use of multiple queues
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
double myOccupancy
The occupied space (in m) on the segment.
int getCarNumber() const
Returns the total number of cars on the segment.
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.