53 #ifdef CHECK_MEMORY_LEAKS 55 #endif // CHECK_MEMORY_LEAKS 57 #define DEFAULT_VEH_LENGHT_WITH_GAP 7.5f 59 #define MESO_MIN_SPEED ((SUMOReal)0.05) 77 SUMOReal jamThresh,
bool multiQueue,
bool junctionControl,
79 Named(id), myEdge(parent), myNextSegment(next),
80 myLength(length), myIndex(idx),
81 myTau_ff((
SUMOTime)(tauff / parent.getLanes().size())),
82 myTau_fj((
SUMOTime)(taufj / parent.getLanes().size())),
83 myTau_jf((
SUMOTime)(taujf / parent.getLanes().size())),
84 myTau_jj((
SUMOTime)(taujj / parent.getLanes().size())),
87 myCapacity(length * parent.getLanes().size()),
89 myJunctionControl(junctionControl),
90 myTLSPenalty(
MSGlobals::gMesoTLSPenalty > 0 && myNextSegment == 0 && (
95 myLengthGeometryFactor(lengthGeometryFactor),
98 myCarQues.push_back(std::vector<MEVehicle*>());
100 const std::vector<MSLane*>& lanes = parent.
getLanes();
101 if (multiQueue && lanes.size() > 1) {
103 if (numFollower > 1) {
104 while (
myCarQues.size() < lanes.size()) {
105 myCarQues.push_back(std::vector<MEVehicle*>());
108 for (
int i = 0; i < numFollower; ++i) {
110 const std::vector<MSLane*>*
const allowed = parent.
allowedLanes(*edge);
111 assert(allowed != 0);
112 assert(allowed->size() > 0);
113 for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
114 std::vector<MSLane*>::const_iterator it = find(lanes.begin(), lanes.end(), *j);
115 myFollowerMap[edge].push_back((
int)distance(lanes.begin(), it));
196 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
197 (*i)->addReminder(data);
205 std::vector<MSMoveReminder*>::iterator it = find(
211 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
212 (*i)->removeReminder(data);
238 SUMOTime earliestExitTime = currentTime;
239 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
240 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
241 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
242 earliestExitTime = exitTime +
myTau_ff;
290 total += (int)k->size();
305 SUMOTime earliestExitTime = currentTime;
306 count += (int)k->size();
307 for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
308 v += (*veh)->getConservativeSpeed(earliestExitTime);
309 earliestExitTime += tau;
325 for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
336 assert(std::find(cars.begin(), cars.end(), v) != cars.end());
340 if (v == cars.back()) {
347 cars.erase(std::find(cars.begin(), cars.end(), v));
356 if (predecessorIsFree) {
373 SUMOTime earliestLeave = earliestEntry;
374 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
395 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
396 if (&(*j)->getLane()->getEdge() == nextEdge) {
402 if ((*l) != bestLane) {
403 const MSLinkCont& links = (*l)->getLinkCont();
404 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
405 if (&(*j)->getLane()->getEdge() == nextEdge) {
450 link->removeApproaching(veh);
498 int nextQueIndex = 0;
504 nextQueIndex = indices[0];
505 for (std::vector<int>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
512 std::vector<MEVehicle*>& cars =
myCarQues[nextQueIndex];
521 if (!isDepart && leaderOut > tleave &&
overtake()) {
522 if (cars.size() == 1) {
526 cars.insert(cars.begin() + 1, veh);
529 cars.insert(cars.begin(), veh);
545 }
else if (
myIndex == 0 || afterTeleport) {
550 if (newLeader != 0) {
563 if (k->size() == 1) {
584 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
585 (*i)->updateDetectors(currentTime,
false);
588 (*i)->setEventTime(newEvent);
606 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
617 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
619 result =
myCarQues[i].back()->getEventTime();
632 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
643 for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {
661 std::vector<const MEVehicle*>
663 std::vector<const MEVehicle*> result;
665 result.insert(result.end(), k->begin(), k->end());
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
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
SUMOTime getTLSPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a tls-controlled link (if using gMesoTLSPenalty > 0) ...
MSEdge & getEdge() const
Returns the lane's edge.
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
const SUMOReal myCapacity
The number of lanes * the length.
A vehicle from the mesoscopic point of view.
int getCarNumber() const
Returns the total number of cars on the segment.
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge's que.
MSLane * getLane() const
Returns the connected lane.
SUMOTime getMesoTLSPenalty() const
Returns the time penalty for passing a tls-controlled link (meso)
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
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, SUMOReal lengthGeometryFactor)
constructor
void setSpeedForQueue(SUMOReal newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle *> &vehs)
virtual void unlock() const
release exclusive access to the mesoscopic state
The vehicle arrived at a junction.
SUMOTime myEntryBlockTime
static const SUMOReal DO_NOT_PATCH_JAM_THRESHOLD
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
SUMOReal length
The physical vehicle length.
Notification
Definition of a vehicle state.
static SUMOReal rand()
Returns a random real number in [0, 1)
SUMOReal getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
SUMOReal myOccupancy
The occupied space (in m) on the segment.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
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)
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
static bool gMesoOvertaking
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.
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
SUMOReal getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
bool isTLSControlled() const
bool hasSpaceFor(const MEVehicle *veh, SUMOTime entryTime, bool init=false) const
Returns whether the given vehicle would still fit into the segment.
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 writeVehicles(OutputDevice &of) const
void removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
SUMOReal getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
A road/street connecting two junctions.
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the maximum speed the vehicle may use on this edge.
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.
SUMOReal jamThresholdForSpeed(SUMOReal speed, SUMOReal jamThresh) const
compute jam threshold for the given speed and jam-threshold option
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
bool free() const
return whether this segment is considered free as opposed to jammed
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
std::map< const MSEdge *, std::vector< int > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
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)
bool havePriority() const
Returns whether this link is a major link.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
SUMOReal myTau_length
Headway paramter for computing gross time headyway from net time heawdway, length and edge speed...
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge) ...
const SUMOReal myLength
The segment's length.
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
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.
Something on a lane to be noticed about vehicle movement.
int getQueIndex() const
Returns the index of the que the vehicle is in.
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.
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
Base class for objects which have an id.
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
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed ...
SUMOTime getStoptime(const MESegment *const seg) const
Returns how long to stop at the given segment.
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 ...
The vehicle has departed (was inserted into the network)
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
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 MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set ...
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
virtual void activateReminders(const MSMoveReminder::Notification reason)
"Activates" all current move reminder
A single mesoscopic segment (cell)
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.
MESegment * getSegmentForEdge(const MSEdge &e, SUMOReal pos=0)
Get the segment for a given edge at a given position.
const MSEdgeVector & getSuccessors() const
Returns the following edges.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
const bool myJunctionControl
Whether junction control is enabled.
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
virtual void lock() const
grant exclusive access to the mesoscopic state
SUMOReal estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
const SUMOReal myLengthGeometryFactor
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.
std::vector< SUMOTime > myBlockTimes
The block times.
The class responsible for building and deletion of vehicles.
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
#define DEFAULT_VEH_LENGHT_WITH_GAP
SUMOReal getImpatience() const
Returns this vehicles impatience.
static const SUMOVTypeParameter & getDefault()
return the default parameters, this is a function due to the http://www.parashift.com/c++-faq/static-init-order.html
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.
const std::string & getID() const
Returns the name of the vehicle.
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.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOReal getFlow() const
returns flow based on headway
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
void recomputeJamThreshold(SUMOReal jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
SUMOTime getTimeHeadway(bool predecessorIsFree, SUMOReal leaderLength)
SUMOReal minGap
This class' free space in front of the vehicle itself.