53 #ifdef CHECK_MEMORY_LEAKS 55 #endif // CHECK_MEMORY_LEAKS 73 SUMOReal jamThresh,
bool multiQueue,
bool junctionControl,
75 Named(id), myEdge(parent), myNextSegment(next),
76 myLength(length), myIndex(idx),
77 myTau_ff((
SUMOTime)(tauff / parent.getLanes().size())),
78 myTau_fj((
SUMOTime)(taufj / parent.getLanes().size())),
79 myTau_jf((
SUMOTime)(taujf / parent.getLanes().size())),
80 myTau_jj((
SUMOTime)(taujj / parent.getLanes().size())),
81 myHeadwayCapacity(length / 7.5f * parent.getLanes().size()),
82 myCapacity(length * parent.getLanes().size()),
84 myJunctionControl(junctionControl),
85 myTLSPenalty(
MSGlobals::gMesoTLSPenalty > 0 && myNextSegment == 0 && (
90 myLengthGeometryFactor(lengthGeometryFactor),
93 myCarQues.push_back(std::vector<MEVehicle*>());
95 const std::vector<MSLane*>& lanes = parent.
getLanes();
96 if (multiQueue && lanes.size() > 1) {
98 if (numFollower > 1) {
100 myCarQues.push_back(std::vector<MEVehicle*>());
103 for (
unsigned int i = 0; i < numFollower; ++i) {
106 const std::vector<MSLane*>* allowed = parent.
allowedLanes(*edge);
107 assert(allowed != 0);
108 assert(allowed->size() > 0);
109 for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
110 std::vector<MSLane*>::const_iterator it = find(lanes.begin(), lanes.end(), *j);
162 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
163 (*i)->addReminder(data);
171 std::vector<MSMoveReminder*>::iterator it = find(
177 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
178 (*i)->removeReminder(data);
204 SUMOTime earliestExitTime = currentTime;
205 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
206 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
207 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
208 earliestExitTime = exitTime +
myTau_ff;
271 SUMOTime earliestExitTime = currentTime;
273 for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
274 v += (*veh)->getConservativeSpeed(earliestExitTime);
275 earliestExitTime += tau;
291 for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
302 assert(std::find(cars.begin(), cars.end(), v) != cars.end());
306 if (v == cars.back()) {
313 cars.erase(std::find(cars.begin(), cars.end(), v));
322 if (predecessorIsFree) {
340 SUMOTime earliestLeave = earliestEntry;
341 for (
size_t i = 0; i <
myCarQues.size(); ++i) {
362 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
363 if (&(*j)->getLane()->getEdge() == nextEdge) {
369 if ((*l) != bestLane) {
370 const MSLinkCont& links = (*l)->getLinkCont();
371 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
372 if (&(*j)->getLane()->getEdge() == nextEdge) {
417 link->removeApproaching(veh);
465 size_t nextQueIndex = 0;
471 nextQueIndex = indices[0];
472 for (std::vector<size_t>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
479 std::vector<MEVehicle*>& cars =
myCarQues[nextQueIndex];
488 if (!isDepart && leaderOut > tleave &&
overtake()) {
489 if (cars.size() == 1) {
493 cars.insert(cars.begin() + 1, veh);
496 cars.insert(cars.begin(), veh);
512 }
else if (
myIndex == 0 || afterTeleport) {
517 if (newLeader != 0) {
530 if (k->size() == 1) {
551 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
552 (*i)->updateDetectors(currentTime,
false);
554 (*i)->setEventTime(newEvent);
571 for (
size_t i = 0; i <
myCarQues.size(); ++i) {
582 for (
size_t i = 0; i <
myCarQues.size(); ++i) {
584 result =
myCarQues[i].back()->getEventTime();
597 for (
size_t i = 0; i <
myCarQues.size(); ++i) {
608 for (std::vector<std::string>::const_iterator it = vehIds.begin(); it != vehIds.end(); ++it) {
626 std::vector<const MEVehicle*>
628 std::vector<const MEVehicle*> result;
630 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.
const unsigned int myIndex
Running number of the segment in the edge.
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.
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, SUMOReal length, SUMOReal speed, unsigned int idx, SUMOTime tauff, SUMOTime taufj, SUMOTime taujf, SUMOTime taujj, SUMOReal jamThresh, bool multiQueue, bool junctionControl, SUMOReal lengthGeometryFactor)
constructor
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, MESegment *next)
Removes the given car from the edge's que.
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 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
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 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.
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
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.
void loadState(std::vector< std::string > &vehIDs, MSVehicleControl &vc, const SUMOTime blockTime, const unsigned int queIdx)
Loads the state of this segment with the given parameters.
static MSEdge myDummyParent
size_t getCarNumber() const
Returns the total number of cars on the segment.
const MSEdge * succEdge(unsigned int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
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)
SUMOTime getTimeHeadway(bool predecessorIsFree)
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...
SUMOReal jamThresholdForSpeed(SUMOReal speed) const
compute jam threshold for the given speed
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.
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.
bool havePriority() const
Returns whether this link is a major link.
virtual void unlock() const
release exclusive access to the mesoscopic state
size_t getQueIndex() const
Returns the index of the que the vehicle is in.
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.
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.
const SUMOReal myLengthGeometryFactor
std::map< const MSEdge *, std::vector< size_t > > myFollowerMap
The follower edge to que index mapping for multi queue segments.
bool hasValidRoute(std::string &msg) const
Validates the current route.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
unsigned int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
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.
virtual void setSegment(MESegment *s, size_t idx=0)
Sets the current segment the vehicle is at together with its que.
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.
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
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.
bool opened(SUMOTime arrivalTime, SUMOReal arrivalSpeed, SUMOReal leaveSpeed, SUMOReal vehicleLength, SUMOReal impatience, SUMOReal decel, SUMOTime waitingTime, std::vector< const SUMOVehicle * > *collectFoes=0) const
Returns the information whether the link may be passed.
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.
SUMOReal minGap
This class' free space in front of the vehicle itself.