43 #define DEFAULT_VEH_LENGTH_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap)
45 #define MESO_MIN_SPEED (0.05)
51 #define DEBUG_COND (myEdge.isSelected())
52 #define DEBUG_COND2(obj) ((obj != 0 && (obj)->isSelected()))
89 const double length,
const double speed,
91 const bool multiQueue,
101 const std::vector<MSLane*>& lanes = parent.
getLanes();
103 for (
MSLane*
const l : lanes) {
113 if (next ==
nullptr) {
115 const std::vector<MSLane*>*
const allowed = parent.
allowedLanes(*edge);
116 assert(allowed !=
nullptr);
117 assert(allowed->size() > 0);
118 for (
MSLane*
const l : *allowed) {
119 std::vector<MSLane*>::const_iterator it = std::find(lanes.begin(), lanes.end(), l);
129 initSegment(edgeType, parent, length * usableLanes);
137 const double laneScale = capacity /
myLength;
177 myEdge(myDummyParent),
178 myNextSegment(nullptr), myLength(0), myIndex(0),
179 myTau_ff(0), myTau_fj(0), myTau_jf(0), myTau_jj(0),
181 myCheckMinorPenalty(false),
183 myJunctionControl(false),
193 myQueues[lane->getIndex()].setPermissions(lane->getPermissions());
223 return std::numeric_limits<double>::max();
225 #ifdef DEBUG_JAMTHRESHOLD
239 for (
MEVehicle*
const v : q.getVehicles()) {
240 v->addReminder(data);
253 for (
MEVehicle*
const v : q.getVehicles()) {
254 v->removeReminder(data);
264 SUMOTime earliestExitTime = currentTime;
265 for (std::vector<MEVehicle*>::const_reverse_iterator i = q.getVehicles().rbegin(); i != q.getVehicles().rend(); ++i) {
266 const SUMOTime exitTime =
MAX2(earliestExitTime, (*i)->getEventTime());
267 (*i)->updateDetectorForWriting(&data, currentTime, exitTime);
268 earliestExitTime = exitTime +
tauWithVehLength(
myTau_ff, (*i)->getVehicleType().getLengthWithGap(), (*i)->getVehicleType().getCarFollowModel().getHeadwayTime());
283 return earliestEntry;
287 int minSize = std::numeric_limits<int>::max();
289 for (
int i = 0; i < (int)
myQueues.size(); i++) {
321 if (minSize == std::numeric_limits<int>::max()) {
322 return earliestEntry;
332 receive(veh, qIdx, time,
true);
353 SUMOTime earliestExitTime = currentTime;
355 for (std::vector<MEVehicle*>::const_reverse_iterator veh = q.getVehicles().rbegin(); veh != q.getVehicles().rend(); ++veh) {
356 v += (*veh)->getConservativeSpeed(earliestExitTime);
357 earliestExitTime +=
tauWithVehLength(tau, (*veh)->getVehicleType().getLengthWithGap(), (*veh)->getVehicleType().getCarFollowModel().getHeadwayTime());
373 for (
const MEVehicle*
const veh : q.getVehicles()) {
396 SUMOTime earliestLeave = earliestEntry;
399 earliestLeave =
MAX2(earliestLeave, q.getBlockTime());
400 latestEntry =
MAX2(latestEntry, q.getEntryBlockTime());
403 return MAX2(earliestEntry, latestEntry);
420 if (&link->getLane()->getEdge() == nextEdge) {
426 if (lane != bestLane) {
427 for (
MSLink*
const link : lane->getLinkCont()) {
428 if (&link->getLane()->getEdge() == nextEdge) {
448 std::cout <<
" link=0";
470 return (link ==
nullptr
481 assert(link !=
nullptr);
497 if (link !=
nullptr) {
544 const double n_jam_threshold = headwayCapacity * nextJamThreshold / nextQueueCapacity;
613 if (!isDepart && leaderOut > tleave &&
overtake()) {
614 if (cars.size() == 1) {
618 cars.insert(cars.begin() + 1, veh);
620 tleave =
MAX2(leaderOut +
tauWithVehLength(
myTau_ff, cars[0]->getVehicleType().getLengthWithGap(), cars[0]->getVehicleType().getCarFollowModel().getHeadwayTime()), tleave);
621 cars.insert(cars.begin(), veh);
626 if (!isDepart && !isTeleport) {
639 }
else if (newEdge) {
647 if (newLeader !=
nullptr) {
658 for (
MEVehicle*
const veh : q.getVehicles()) {
681 for (std::vector<MEVehicle*>::const_reverse_iterator i = vehs.rbegin() + 1; i != vehs.rend(); ++i) {
682 (*i)->updateDetectors(currentTime,
false);
685 (*i)->setEventTime(newEvent);
715 if (q.size() != 0 && q.getVehicles().back()->getEventTime() < result) {
716 result = q.getVehicles().back()->getEventTime();
730 if (q.getBlockTime() != -1 || !q.getVehicles().empty()) {
750 q.getModifiableVehicles().clear();
757 for (
const std::string&
id : vehIds) {
778 std::vector<const MEVehicle*>
780 std::vector<const MEVehicle*> result;
782 result.insert(result.end(), q.getVehicles().begin(), q.getVehicles().end());
791 if (q.size() > 0 && q.getVehicles().back()->getWaitingTime() > 0) {
808 if (link !=
nullptr) {
833 for (
const MEVehicle* veh : q.getVehicles()) {
834 result += veh->getWaitingSeconds();
#define DEFAULT_VEH_LENGTH_WITH_GAP
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_VIEWSETTINGS_VEHICLES
@ SUMO_TAG_SEGMENT
segment of a lane
@ TRAFFIC_LIGHT_RIGHT_ON_RED
@ TRAFFIC_LIGHT_NOJUNCTION
@ SUMO_ATTR_TIME
trigger: the time of the step
bool gDebugFlag1
global utility flags for debugging
static bool isEnteringRoundabout(const MSEdge &e)
whether the given edge is entering a roundabout
SUMOTime changeSegment(MEVehicle *veh, SUMOTime leaveTime, MESegment *const toSegment, MSMoveReminder::Notification reason, const bool ignoreLink=false) const
change to the next segment this handles combinations of the following cases: (ending / continuing rou...
MESegment * getSegmentForEdge(const MSEdge &e, double pos=0)
Get the segment for a given edge at a given position.
bool removeLeaderCar(MEVehicle *v)
Removes the given car from the leading vehicles.
void addLeaderCar(MEVehicle *veh, MSLink *link)
Adds the given car to the leading vehicles.
void setOccupancy(const double occ)
MEVehicle * remove(MEVehicle *v)
void setBlockTime(SUMOTime t)
SUMOTime getBlockTime() const
double myOccupancy
The occupied space (in m) in the queue.
bool allows(SUMOVehicleClass vclass) const
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
double getOccupancy() const
const std::vector< MEVehicle * > & getVehicles() const
std::vector< MEVehicle * > myVehicles
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
std::vector< MEVehicle * > & getModifiableVehicles()
A single mesoscopic segment (cell)
void addReminders(MEVehicle *veh) const
add this lanes MoveReminders to the given vehicle
double myQueueCapacity
The number of lanes represented by the queue * the length of the lane.
SUMOTime tauWithVehLength(SUMOTime tau, double lengthWithGap, double vehicleTau) const
convert net time gap (leader back to follower front) to gross time gap (leader front to follower fron...
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
bool initialise(MEVehicle *veh, SUMOTime time)
Inserts (emits) vehicle into the segment.
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
double getBruttoOccupancy() const
Returns the occupany of the segment (the sum of the vehicle lengths + minGaps)
SUMOTime myLastHeadway
the last headway
static const int PARKING_QUEUE
bool limitedControlOverride(const MSLink *link) const
whether the given link may be passed because the option meso-junction-control.limited is set
bool isOpen(const MEVehicle *veh) const
Returns whether the vehicle may use the next link.
void clearState()
Remove all vehicles before quick-loading state.
void receive(MEVehicle *veh, const int qIdx, SUMOTime time, const bool isDepart=false, const bool isTeleport=false, const bool newEdge=false)
Adds the vehicle to the segment, adapting its parameters.
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
std::map< const MSEdge *, int > myFollowerMap
The follower edge to allowed que index mapping for multi queue segments.
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
int myNumVehicles
The cached value for the number of vehicles.
void setSpeedForQueue(double newSpeed, SUMOTime currentTime, SUMOTime blockTime, const std::vector< MEVehicle * > &vehs)
SUMOTime hasSpaceFor(const MEVehicle *const veh, const SUMOTime entryTime, int &qIdx, const bool init=false) const
Returns whether the given vehicle would still fit into the segment.
void updatePermissions()
called when permissions change due to Rerouter or TraCI
void removeDetector(MSMoveReminder *data)
Removes a data collector for a detector from this segment.
void saveState(OutputDevice &out) const
Saves the state of this segment into the given stream.
void initSegment(const MesoEdgeType &edgeType, const MSEdge &parent, const double capacity)
set model parameters (may be updated from additional file after network loading is complete)
void prepareDetectorForWriting(MSMoveReminder &data)
Updates data of a detector for all vehicle queues.
static MESegment myVaporizationTarget
double myJamThreshold
The space (in m) which needs to be occupied before the segment is considered jammed.
const int myIndex
Running number of the segment in the edge.
void send(MEVehicle *veh, MESegment *const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason)
Removes the vehicle from the segment, adapting its parameters.
double myMeanSpeed
the mean speed on this segment. Updated at event time or on demand
bool myCheckMinorPenalty
penalty for minor links
std::vector< MSMoveReminder * > myDetectorData
The data collection for all kinds of detectors.
double jamThresholdForSpeed(double speed, double jamThresh) const
compute jam threshold for the given speed and jam-threshold option
SUMOTime myLastMeanSpeedUpdate
the time at which myMeanSpeed was last updated
MESegment * myNextSegment
The next segment of this edge, 0 if this is the last segment of this edge.
const MSEdge & getEdge() const
Returns the edge this segment belongs to.
bool hasBlockedLeader() const
whether a leader in any queue is blocked
double getWaitingSeconds() const
Get the waiting time for vehicles in all queues.
const double myLength
The segment's length.
SUMOTime getEventTime() const
Returns the (planned) time at which the next vehicle leaves this segment.
const MSEdge & myEdge
The microsim edge this segment belongs to.
MESegment(const std::string &id, const MSEdge &parent, MESegment *next, const double length, const double speed, const int idx, const bool multiQueue, const MesoEdgeType &edgeType)
constructor
MEVehicle * removeCar(MEVehicle *v, SUMOTime leaveTime, const MSMoveReminder::Notification reason)
Removes the given car from the edge's que.
std::vector< const MEVehicle * > getVehicles() const
returns all vehicles (for debugging)
void addDetector(MSMoveReminder *data)
Adds a data collector for a detector to this segment.
static MSEdge myDummyParent
void recomputeJamThreshold(double jamThresh)
compute a value for myJamThreshold if jamThresh is negative, compute a value which allows free flow a...
double getMeanSpeed() const
wrapper to satisfy the FunctionBinding signature
int getCarNumber() const
Returns the total number of cars on the segment.
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
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.
double myTau_length
Headway parameter for computing gross time headyway from net time headway, length and edge speed.
SUMOTime newArrival(const MEVehicle *const v, double newSpeed, SUMOTime currentTime)
compute the new arrival time when switching speed
bool myJunctionControl
Whether junction control is enabled.
bool myTLSPenalty
Whether tls penalty is enabled.
static const double DO_NOT_PATCH_JAM_THRESHOLD
double getFlow() const
returns flow based on headway
static bool isInvalid(const MESegment *segment)
whether the given segment is 0 or encodes vaporization
SUMOTime getNextInsertionTime(SUMOTime earliestEntry) const
return a time after earliestEntry at which a vehicle may be inserted at full speed
double myCapacity
The number of lanes represented by the queue * the length of the lane.
bool myOvertaking
Whether overtaking is permitted on this segment.
bool vaporizeAnyCar(SUMOTime currentTime, const MSDetectorFileOutput *filter)
tries to remove any car from this segment
SUMOTime getTauJJ(double nextQueueSize, double nextQueueCapacity, double nextJamThreshold) const
A vehicle from the mesoscopic point of view.
double estimateLeaveSpeed(const MSLink *link) const
Returns the vehicle's estimated speed after driving accross the link.
void processStop()
ends the current stop and performs loading/unloading
bool hasArrived() const
Returns whether this vehicle has already arived (reached the arrivalPosition on its final edge)
bool moveRoutePointer()
Update when the vehicle enters a new edge in the move step.
SUMOTime checkStop(SUMOTime time)
Returns until when to stop at the current segment and sets the information that the stop has been rea...
void updateDetectors(SUMOTime currentTime, const bool isLeave, const MSMoveReminder::Notification reason=MSMoveReminder::NOTIFICATION_JUNCTION)
Updates all vehicle detectors.
SUMOTime getLastEntryTime() const
Returns the time the vehicle entered the current segment.
void setEventTime(SUMOTime t, bool hasDelay=true)
Sets the (planned) time at which the vehicle leaves his current cell.
MESegment * getSegment() const
Returns the current segment the vehicle is on.
void setLastEntryTime(SUMOTime t)
Sets the entry time for the current segment.
int getQueIndex() const
Returns the index of the que the vehicle is in.
SUMOTime getWaitingTime() const
Returns the duration for which the vehicle was blocked.
virtual void setSegment(MESegment *s, int idx=0)
Sets the current segment the vehicle is at together with its que.
SUMOTime getEventTime() const
Returns the (planned) time at which the vehicle leaves his current cell.
void setBlockTime(const SUMOTime t)
Sets the time at which the vehicle was blocked.
double getSpeed() const
Returns the vehicle's estimated speed assuming no delays.
double getImpatience() const
Returns this vehicles impatience.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
bool isParking() const
Returns whether the vehicle is parking.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
void onDepart()
Called when the vehicle is inserted into the network.
bool isStopped() const
Returns whether the vehicle is at a stop.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Base of value-generating classes (detectors)
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
A road/street connecting two junctions.
virtual void unlock() const
release exclusive access to the mesoscopic state
SVCPermissions getPermissions() const
Returns the combined permissions of all lanes of this edge.
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.
double getSpeedLimit() const
Returns the speed limit of the edge @caution The speed limit of the first lane is retured; should pro...
static SVCPermissions getMesoPermissions(SVCPermissions p, SVCPermissions ignoreIgnored=0)
bool isRoundabout() const
bool isVaporizing() const
Returns whether vehicles on this edge shall be vaporized.
void addWaiting(SUMOVehicle *vehicle) const
Adds a vehicle to the list of waiting vehicles.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
bool hasMinorLink() const
whether any lane has a minor link
const MSJunction * getToJunction() const
virtual void lock() const
grant exclusive access to the mesoscopic state
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
static bool gMesoLimitedJunctionControl
SumoXMLNodeType getType() const
return the type of this Junction
Representation of a lane in the micro simulation.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
MSEdge & getEdge() const
Returns the lane's edge.
bool isTLSControlled() const
MSLane * getLane() const
Returns the connected lane.
bool havePriority() const
Returns whether this link is a major link.
SUMOTime getMesoTLSPenalty() const
Returns the time penalty for passing a tls-controlled link (meso)
void removeApproaching(const SUMOVehicle *veh)
removes the vehicle from myApproachingVehicles
bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength, double impatience, double decel, SUMOTime waitingTime, double posLat=0, BlockingFoes *collectFoes=nullptr, bool ignoreRed=false, const SUMOTrafficObject *ego=nullptr) const
Returns the information whether the link may be passed.
double getGreenFraction() const
Returns the average proportion of green time to cycle time.
Something on a lane to be noticed about vehicle movement.
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_VAPORIZED_CALIBRATOR
The vehicle got removed by a calibrator.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_SEGMENT
The vehicle changes the segment (meso only)
@ NOTIFICATION_VAPORIZED_VAPORIZER
The vehicle got vaporized with a vaporizer.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
The class responsible for building and deletion of vehicles.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
static void writeVehicle(OutputDevice &of, const MSBaseVehicle &veh)
Writes the dump of the given vehicle into the given device.
Base class for objects which have an id.
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
edge type specific meso parameters