53 #ifdef CHECK_MEMORY_LEAKS 55 #endif // CHECK_MEMORY_LEAKS 57 #define DEFAULT_VEH_LENGHT_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap) 59 #define MESO_MIN_SPEED ((SUMOReal)0.05) 77 SUMOReal jamThresh,
bool multiQueue,
bool junctionControl) :
78 Named(id), myEdge(parent), myNextSegment(next),
79 myLength(length), myIndex(idx),
80 myTau_ff((
SUMOTime)(tauff / parent.getLanes().size())),
81 myTau_fj((
SUMOTime)(taufj / parent.getLanes().size())),
82 myTau_jf((
SUMOTime)(taujf / parent.getLanes().size())),
83 myTau_jj((
SUMOTime)(taujj / parent.getLanes().size())),
86 myCapacity(length * parent.getLanes().size()),
88 myJunctionControl(junctionControl),
89 myTLSPenalty(
MSGlobals::gMesoTLSPenalty > 0 &&
91 myNextSegment == 0 && (
95 myMinorPenalty(
MSGlobals::gMesoMinorPenalty > 0 &&
101 parent.hasMinorLink()),
106 myCarQues.push_back(std::vector<MEVehicle*>());
109 const std::vector<MSLane*>& lanes = parent.
getLanes();
110 while (
myCarQues.size() < lanes.size()) {
111 myCarQues.push_back(std::vector<MEVehicle*>());
116 const std::vector<MSLane*>*
const allowed = parent.
allowedLanes(*edge);
117 assert(allowed != 0);
118 assert(allowed->size() > 0);
119 for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
120 std::vector<MSLane*>::const_iterator it = find(lanes.begin(), lanes.end(), *j);
121 myFollowerMap[edge].push_back((
int)distance(lanes.begin(), it));
212 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
213 (*i)->addReminder(data);
221 std::vector<MSMoveReminder*>::iterator it = find(
227 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
228 (*i)->removeReminder(data);
254 SUMOTime earliestExitTime = currentTime;
255 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
256 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
257 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
310 total += (int)k->size();
325 SUMOTime earliestExitTime = currentTime;
326 count += (int)k->size();
327 for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
328 v += (*veh)->getConservativeSpeed(earliestExitTime);
329 earliestExitTime +=
tauWithVehLength(tau, (*veh)->getVehicleType().getLengthWithGap());
345 for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
356 assert(std::find(cars.begin(), cars.end(), v) != cars.end());
360 if (v == cars.back()) {
367 cars.erase(std::find(cars.begin(), cars.end(), v));
386 SUMOTime earliestLeave = earliestEntry;
387 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
408 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
409 if (&(*j)->getLane()->getEdge() == nextEdge) {
415 if ((*l) != bestLane) {
416 const MSLinkCont& links = (*l)->getLinkCont();
417 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
418 if (&(*j)->getLane()->getEdge() == nextEdge) {
463 link->removeApproaching(veh);
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];
535 if (!isDepart && leaderOut > tleave &&
overtake()) {
536 if (cars.size() == 1) {
540 cars.insert(cars.begin() + 1, veh);
543 cars.insert(cars.begin(), veh);
559 }
else if (
myIndex == 0 || afterTeleport) {
564 if (newLeader != 0) {
577 if (k->size() == 1) {
598 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
599 (*i)->updateDetectors(currentTime,
false);
602 (*i)->setEventTime(newEvent);
620 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
631 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
633 result =
myCarQues[i].back()->getEventTime();
646 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
657 for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {
675 std::vector<const MEVehicle*>
677 std::vector<const MEVehicle*> result;
679 result.insert(result.end(), k->begin(), k->end());
688 if (k->size() > 0 && (*k).back()->getWaitingTime() > 0) {
743 for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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...
static MESegment myVaporizationTarget
SUMOReal getTLSCapacity(const MEVehicle *veh) const
Returns the average green time as fraction of cycle time.
MSEdge & getEdge() const
Returns the lane's edge.
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
SUMOReal getFlow() const
returns flow based on headway
const SUMOReal myCapacity
The number of lanes * the length.
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
A vehicle from the mesoscopic point of view.
const bool myMinorPenalty
Whether minor penalty is enabled.
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge's que.
SUMOReal jamThresholdForSpeed(SUMOReal speed, SUMOReal jamThresh) const
compute jam threshold for the given speed and jam-threshold option
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set ...
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
SUMOReal getImpatience() const
Returns this vehicles impatience.
SUMOTime getMesoTLSPenalty() const
Returns the time penalty for passing a tls-controlled link (meso)
The vehicle arrived at a junction.
virtual void lock() const
grant exclusive access to the mesoscopic state
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
SUMOTime myEntryBlockTime
static const SUMOReal DO_NOT_PATCH_JAM_THRESHOLD
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
SUMOReal getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
SUMOReal myOccupancy
The occupied space (in m) on the segment.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
static bool useMultiQueue(bool multiQueue, const MSEdge &parent)
whether the segment requires use of multiple queues
SUMOReal getGreenFraction() const
Returns the average proportion of green time to cycle time.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
SUMOReal getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
SUMOTime newArrival(const MEVehicle *const v, SUMOReal newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
The vehicle got vaporized.
The vehicle changes the segment (meso only)
void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
bool hasBlockedLeader() const
whether a leader in any queue is blocked
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
static bool gMesoOvertaking
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
The purpose of the edge is not known.
Queues myCarQues
The car queues. Vehicles are inserted in the front and removed in the back.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
void loadState(std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const int queIdx)
Loads the state of this segment with the given parameters.
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
A road/street connecting two junctions.
bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime, SUMOReal posLat=0, std::vector< const SUMOVehicle * > *collectFoes=0) const
Returns the information whether the link may be passed.
const SUMOReal myHeadwayCapacity
The capacity of the segment in number of cars, used only in time headway calculation This parameter h...
void receive(MEVehicle *veh, SUMOTime time, bool isDepart=false, bool afterTeleport=false)
Adds the vehicle to the segment, adapting its parameters.
void writeVehicles(OutputDevice &of) const
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
SUMOTime getLinkPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a link (if using gMesoTLSPenalty > 0 or gMesoMinorPenalty > 0) ...
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
bool free() const
return whether this segment is considered free as opposed to jammed
MSLane * getLane() const
Returns the connected lane.
bool isTLSControlled() const
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
static MSEdge myDummyParent
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
void updateDetectorsOnLeave(MEVehicle *v, SUMOTime currentTime, MESegment *next)
Updates data of all detectors for a leaving vehicle.
The vehicle arrived at its destination (is deleted)
SUMOReal myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed...
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
static SUMOTime gMesoMinorPenalty
const SUMOReal myLength
The segment's length.
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
Something on a lane to be noticed about vehicle movement.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
bool vaporizeAnyCar(SUMOTime currentTime)
tries to remove any car from this segment
SUMOReal myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Base class for objects which have an id.
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
const MSEdge & myEdge
The microsim edge this segment belongs to.
SUMOReal myA
slope and axis offset for the jam-jam headway function
void setSpeed(SUMOReal newSpeed, SUMOTime currentTime, SUMOReal jamThresh=DO_NOT_PATCH_JAM_THRESHOLD)
reset mySpeed and patch the speed of all vehicles in it. Also set/recompute myJamThreshold ...
trigger: the time of the step
The vehicle has departed (was inserted into the network)
void scheduleVehicleRemoval(SUMOVehicle *veh)
Removes a vehicle after it has ended.
const bool myTLSPenalty
Whether tls penalty is enabled.
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
bool havePriority() const
Returns whether this link is a major link.
virtual void unlock() const
release exclusive access to the mesoscopic state
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
SUMOTime myLastHeadway
the last headway
virtual void activateReminders(const MSMoveReminder::Notification reason)
"Activates" all current move reminder
A single mesoscopic segment (cell)
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
bool hasSpaceFor(const MEVehicle *veh, SUMOTime entryTime, bool init=false) const
Returns whether the given vehicle would still fit into the segment.
void onDepart()
Called when the vehicle is inserted into the network.
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
int getQueIndex() const
Returns the index of the que the vehicle is in.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
const bool myJunctionControl
Whether junction control is enabled.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
int getCarNumber() const
Returns the total number of cars on the segment.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
void saveState(OutputDevice &out)
Saves the state of this segment into the given stream.
const MSEdgeVector & getSuccessors() const
Returns the following edges.
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, SUMOReal length, SUMOReal speed, int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, SUMOReal jamThresh, bool multiQueue, bool junctionControl)
constructor
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
std::vector< SUMOTime > myBlockTimes
The block times.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
The class responsible for building and deletion of vehicles.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
SUMOTime getTimeHeadway(const MESegment *pred, const MEVehicle *veh)
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
#define DEFAULT_VEH_LENGHT_WITH_GAP
SUMOReal myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
const int myIndex
Running number of the segment in the edge.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
const SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
static bool gMesoLimitedJunctionControl
void addLeaderCar(MEVehicle *veh, MSLink *link)
Adds the given car to the leading vehicles.
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
MESegment * getSegment() const
Returns the current segment the vehicle is on.
SUMOReal estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
SUMOReal getMaxPenaltySeconds() const
return the maximum tls penalty for all links from this edge
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOTime tauWithVehLength(SUMOTime tau, SUMOReal lengthWithGap) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
void recomputeJamThreshold(SUMOReal jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
const std::string & getID() const
Returns the name of the vehicle.