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) {
111 const std::vector<MSLane*>* allowed = parent.
allowedLanes(*edge);
112 assert(allowed != 0);
113 assert(allowed->size() > 0);
114 for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
115 std::vector<MSLane*>::const_iterator it = find(lanes.begin(), lanes.end(), *j);
197 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
198 (*i)->addReminder(data);
206 std::vector<MSMoveReminder*>::iterator it = find(
212 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
213 (*i)->removeReminder(data);
239 SUMOTime earliestExitTime = currentTime;
240 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
241 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
242 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
243 earliestExitTime = exitTime +
myTau_ff;
291 total += (int)k->size();
306 SUMOTime earliestExitTime = currentTime;
307 count += (int)k->size();
308 for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
309 v += (*veh)->getConservativeSpeed(earliestExitTime);
310 earliestExitTime += tau;
326 for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
337 assert(std::find(cars.begin(), cars.end(), v) != cars.end());
341 if (v == cars.back()) {
348 cars.erase(std::find(cars.begin(), cars.end(), v));
357 if (predecessorIsFree) {
374 SUMOTime earliestLeave = earliestEntry;
375 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
396 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
397 if (&(*j)->getLane()->getEdge() == nextEdge) {
403 if ((*l) != bestLane) {
404 const MSLinkCont& links = (*l)->getLinkCont();
405 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
406 if (&(*j)->getLane()->getEdge() == nextEdge) {
451 link->removeApproaching(veh);
499 int nextQueIndex = 0;
505 nextQueIndex = indices[0];
506 for (std::vector<int>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
513 std::vector<MEVehicle*>& cars =
myCarQues[nextQueIndex];
522 if (!isDepart && leaderOut > tleave &&
overtake()) {
523 if (cars.size() == 1) {
527 cars.insert(cars.begin() + 1, veh);
530 cars.insert(cars.begin(), veh);
546 }
else if (
myIndex == 0 || afterTeleport) {
551 if (newLeader != 0) {
564 if (k->size() == 1) {
585 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
586 (*i)->updateDetectors(currentTime,
false);
589 (*i)->setEventTime(newEvent);
607 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
618 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
620 result =
myCarQues[i].back()->getEventTime();
633 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
644 for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {
662 std::vector<const MEVehicle*>
664 std::vector<const MEVehicle*> result;
666 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
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.
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.
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
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 length
The physical vehicle length.
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).
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)
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
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 paramter for computing gross time headyway from net time heawdway, length and edge speed...
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
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.
SUMOTime getTLSPenalty(const MEVehicle *veh) const
Returns the penalty time for passing a tls-controlled link (if using gMesoTLSPenalty > 0) ...
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 ...
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.
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.
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.
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 ...
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.
void send(MEVehicle *veh, MESegment *next, SUMOTime time)
Removes the vehicle from the segment, adapting its parameters.
#define DEFAULT_VEH_LENGHT_WITH_GAP
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.
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.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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.
SUMOTime getTimeHeadway(bool predecessorIsFree, SUMOReal leaderLength)
SUMOReal minGap
This class' free space in front of the vehicle itself.