 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
46 #define DEFAULT_VEH_LENGHT_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap)
48 #define MESO_MIN_SPEED (0.05)
54 #define DEBUG_COND (myEdge.isSelected())
55 #define DEBUG_COND2(obj) ((obj != 0 && (obj)->isSelected()))
69 double length,
double speed,
73 double jamThresh,
bool multiQueue,
bool junctionControl) :
74 Named(id), myEdge(parent), myNextSegment(next),
75 myLength(length), myIndex(idx),
76 myTau_ff((
SUMOTime)(tauff / parent.getLanes().size())),
77 myTau_fj((
SUMOTime)(taufj / parent.getLanes().size())),
78 myTau_jf((
SUMOTime)(taujf / parent.getLanes().size())),
79 myTau_jj((
SUMOTime)(taujj / parent.getLanes().size())),
82 myCapacity(length * parent.getLanes().size()),
84 myJunctionControl(junctionControl),
85 myTLSPenalty(
MSGlobals::gMesoTLSPenalty > 0 &&
87 myNextSegment == nullptr && (
91 myMinorPenalty(
MSGlobals::gMesoMinorPenalty > 0 &&
93 myNextSegment == nullptr &&
97 parent.hasMinorLink()),
103 myCarQues.push_back(std::vector<MEVehicle*>());
106 const std::vector<MSLane*>& lanes = parent.
getLanes();
107 while (
myCarQues.size() < lanes.size()) {
108 myCarQues.push_back(std::vector<MEVehicle*>());
113 const std::vector<MSLane*>*
const allowed = parent.
allowedLanes(*edge);
114 assert(allowed != 0);
115 assert(allowed->size() > 0);
116 for (std::vector<MSLane*>::const_iterator j = allowed->begin(); j != allowed->end(); ++j) {
117 std::vector<MSLane*>::const_iterator it = std::find(lanes.begin(), lanes.end(), *j);
118 myFollowerMap[edge].push_back((
int)distance(lanes.begin(), it));
128 myEdge(myDummyParent),
129 myNextSegment(nullptr), myLength(0), myIndex(0),
130 myTau_ff(0), myTau_fj(0), myTau_jf(0), myTau_jj(0), myTau_length(1),
131 myHeadwayCapacity(0), myCapacity(0), myJunctionControl(false),
133 myMinorPenalty(false) {
199 return std::numeric_limits<double>::max();
201 #ifdef DEBUG_JAMTHRESHOLD
215 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
216 (*i)->addReminder(data);
224 std::vector<MSMoveReminder*>::iterator it = std::find(
230 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
231 (*i)->removeReminder(data);
241 SUMOTime earliestExitTime = currentTime;
242 for (std::vector<MEVehicle*>::const_reverse_iterator i = k->rbegin(); i != k->rend(); ++i) {
243 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
244 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
302 SUMOTime earliestExitTime = currentTime;
303 count += (int)k->size();
304 for (std::vector<MEVehicle*>::const_reverse_iterator veh = k->rbegin(); veh != k->rend(); ++veh) {
305 v += (*veh)->getConservativeSpeed(earliestExitTime);
306 earliestExitTime +=
tauWithVehLength(tau, (*veh)->getVehicleType().getLengthWithGap());
322 for (std::vector<MEVehicle*>::const_iterator veh = k->begin(); veh != k->end(); ++veh) {
333 assert(std::find(cars.begin(), cars.end(), v) != cars.end());
338 if (v == cars.back()) {
345 cars.erase(std::find(cars.begin(), cars.end(), v));
364 SUMOTime earliestLeave = earliestEntry;
365 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
380 if (nextEdge ==
nullptr) {
386 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
387 if (&(*j)->getLane()->getEdge() == nextEdge) {
393 if ((*l) != bestLane) {
394 const MSLinkCont& links = (*l)->getLinkCont();
395 for (std::vector<MSLink*>::const_iterator j = links.begin(); j != links.end(); ++j) {
396 if (&(*j)->getLane()->getEdge() == nextEdge) {
415 std::cout <<
" link=0";
436 return (link ==
nullptr
462 if (link !=
nullptr) {
463 link->removeApproaching(veh);
515 int nextQueIndex = 0;
521 nextQueIndex = indices[0];
522 for (std::vector<int>::const_iterator i = indices.begin() + 1; i != indices.end(); ++i) {
529 std::vector<MEVehicle*>& cars =
myCarQues[nextQueIndex];
541 if (!isDepart && leaderOut > tleave &&
overtake()) {
542 if (cars.size() == 1) {
546 cars.insert(cars.begin() + 1, veh);
549 cars.insert(cars.begin(), veh);
566 }
else if (
myIndex == 0 || afterTeleport) {
571 if (newLeader !=
nullptr) {
584 if (k->size() == 1) {
605 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
606 (*i)->updateDetectors(currentTime,
false);
609 (*i)->setEventTime(newEvent);
627 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
638 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
640 result =
myCarQues[i].back()->getEventTime();
653 for (
int i = 0; i < (int)
myCarQues.size(); ++i) {
664 for (
const std::string&
id : vehIds) {
685 std::vector<const MEVehicle*>
687 std::vector<const MEVehicle*> result;
689 result.insert(result.end(), k->begin(), k->end());
698 if (k->size() > 0 && (*k).back()->getWaitingTime() > 0) {
715 if (link !=
nullptr) {
737 if (link !=
nullptr) {
749 double maxPenalty = 0;
753 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
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.
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)
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
void addWaiting(const MSEdge *const edge, SUMOVehicle *vehicle)
Adds a vehicle to the list of waiting vehicles for the given edge.
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
bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength, double impatience, double decel, SUMOTime waitingTime, double posLat=0, std::vector< const SUMOVehicle * > *collectFoes=0, bool ignoreRed=false, const SUMOVehicle *ego=0) const
Returns the information whether the link may be passed.
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
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].
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.
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.
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
trigger: the time of the step
SUMOTime getMesoTLSPenalty() const
Returns the time penalty for passing a tls-controlled link (meso)
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
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
#define DEFAULT_VEH_LENGHT_WITH_GAP
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.
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.