Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MELSegment.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// A LTM (LIFT)-model segment
19/****************************************************************************/
20#include <config.h>
21
22#include <algorithm>
23#include <limits>
25#include <microsim/MSGlobals.h>
26#include <microsim/MSEdge.h>
27#include <microsim/MSJunction.h>
28#include <microsim/MSNet.h>
29#include <microsim/MSLane.h>
30#include <microsim/MSLink.h>
43#include "MEVehicle.h"
44#include "MELoop.h"
45#include "MELSegment.h"
46
47#define DEFAULT_VEH_LENGTH_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap)
48
49//#define DEBUG_OPENED
50//#define DEBUG_JAMTHRESHOLD
51//#define DEBUG_COND (getID() == "blocker")
52//#define DEBUG_COND (true)
53#define DEBUG_COND (myEdge.isSelected())
54#define DEBUG_COND2(obj) ((obj != 0 && (obj)->isSelected()))
55
56
57// ===========================================================================
58// static member definition
59// ===========================================================================
60
61
62// ===========================================================================
63// MELSegment method definitions
64// ===========================================================================
65MELSegment::MELSegment(const std::string& id,
66 const MSEdge& parent, MESegment* next,
67 const double length, const double speed,
68 const int idx,
69 const bool multiQueue,
70 const MesoEdgeType& edgeType):
71 MESegment(id, parent, next, length, speed, idx, multiQueue, edgeType)
72{
73 myGapTimes.resize(myQueues.size());
74}
75
76
78MELSegment::computeHeadway(Queue& /*q*/, const Queue& /*qNext*/, const MESegment* const /*next*/, const MEVehicle* veh) const {
79 // @note: it might seem sensible to check veh->getQueuingTimeLoss() here but
80 // then the queing state would be "sticky" because queuingTimeLoss is computed with tau_ff
81 // and every leader car that uses tau_jf applies queing timeLoss to it's followers
85 if (myTLSPenalty) {
86 const MSLink* const tllink = getLink(veh, true);
87 if (tllink != nullptr && tllink->isTLSControlled()) {
88 assert(tllink->getGreenFraction() > 0);
89 headway = (SUMOTime)((double)headway / tllink->getGreenFraction());
90 }
91 }
92 return headway;
93}
94
95
96void
97MELSegment::send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason) {
98 GapTimes& gapTimes = myGapTimes[veh->getQueIndex()];
99 // record time when the gap vacated by ego will reach the upstream end of the segment
100 // gaps travel quickly in free flow (the number of gaps and vehicles stays below the segment capacity)
101 // but they travel more slowly when queued (startupDelay)
102 gapTimes.insert(gapTimes.begin(), time + myLength * (veh->getQueuingTimeLoss() > 0 ? myTau_jj : myTau_ff) / DEFAULT_VEH_LENGTH_WITH_GAP);
103 MESegment::send(veh, next, nextQIdx, time, reason);
104}
105
106
107void
109 for (int qIdx = 0; qIdx < (int)myQueues.size(); qIdx++) {
110 Queue& q = myQueues[qIdx];
111 GapTimes& gapTimes = myGapTimes[qIdx];
112 while (!gapTimes.empty() && gapTimes.back() <= time) {
113 gapTimes.pop_back();
114 }
115 if (!gapTimes.empty() && q.getOccupancy() + gapTimes.size() * DEFAULT_VEH_LENGTH_WITH_GAP > myQueueCapacity) {
116 // segment is jammed because the empty spaces have not yet reached the upstream end.
117 q.setEntryBlockTime(MAX2(q.getEntryBlockTime(), gapTimes.back()));
118 }
119 }
120}
121
122
123bool
124MELSegment::hasSpaceForInsertion(const Queue& q, int qIdx, double /*newOccupancy*/, SUMOTime entryTime) const {
125 GapTimes& gapTimes = const_cast<GapTimes&>(myGapTimes[qIdx]);
126 while (!gapTimes.empty() && gapTimes.back() <= entryTime) {
127 gapTimes.pop_back();
128 }
129 return q.getOccupancy() + gapTimes.size() * DEFAULT_VEH_LENGTH_WITH_GAP < myQueueCapacity;
130}
131
132
133/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEFAULT_VEH_LENGTH_WITH_GAP
T MAX2(T a, T b)
Definition StdDefs.h:86
void send(MEVehicle *veh, MESegment *const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason) override
Removes the vehicle from the segment, adapting its parameters.
void updateEntryBlockTime(SUMOTime time) override
update entry blockTime for all queues
bool hasSpaceForInsertion(const Queue &q, int qIdx, double newOccupancy, SUMOTime entryTime) const override
check jam-avoidance constraints during insertion
std::vector< GapTimes > myGapTimes
Definition MELSegment.h:83
MELSegment(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
std::vector< SUMOTime > GapTimes
upstream arrival times of traveling gaps between cars (for each queue)
Definition MELSegment.h:82
SUMOTime computeHeadway(Queue &q, const Queue &qNext, const MESegment *const next, const MEVehicle *veh) const override
compute current headway depending on traffic state
void setEntryBlockTime(SUMOTime entryBlockTime)
set the next time at which a vehicle may enter this queue
Definition MESegment.h:103
double getOccupancy() const
Definition MESegment.h:87
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition MESegment.h:98
A single mesoscopic segment (cell)
Definition MESegment.h:50
double myQueueCapacity
The number of lanes represented by the queue * the length of the lane.
Definition MESegment.h:590
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...
Definition MESegment.h:538
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:567
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition MESegment.h:596
MSLink * getLink(const MEVehicle *veh, bool tlsPenalty=false) const
Returns the link the given car will use when passing the next junction.
virtual 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.
SUMOTime myTau_jf
Definition MESegment.h:567
const double myLength
The segment's length.
Definition MESegment.h:558
SUMOTime myTau_jj
Definition MESegment.h:567
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:570
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the duration for which the vehicle was blocked.
Definition MEVehicle.h:306
SUMOTime getQueuingTimeLoss() const
Returns the time lost compare to free flow.
Definition MEVehicle.h:312
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:255
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition MSCFModel.h:355
A road/street connecting two junctions.
Definition MSEdge.h:77
Notification
Definition of a vehicle state.
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)
edge type specific meso parameters
Definition MESegment.h:58