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>
46#include "MEVehicle.h"
47#include "MELoop.h"
48#include "MELSegment.h"
49
50#define DEFAULT_VEH_LENGTH_WITH_GAP (SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap)
51
52//#define DEBUG_OPENED
53//#define DEBUG_JAMTHRESHOLD
54//#define DEBUG_COND (getID() == "blocker")
55//#define DEBUG_COND (true)
56#define DEBUG_COND (myEdge.isSelected())
57#define DEBUG_COND2(obj) ((obj != 0 && (obj)->isSelected()))
58
59
60// ===========================================================================
61// static member definition
62// ===========================================================================
63
64
65// ===========================================================================
66// MELSegment method definitions
67// ===========================================================================
68MELSegment::MELSegment(const std::string& id,
69 const MSEdge& parent, MESegment* next,
70 const double length, const double speed,
71 const int idx,
72 const bool multiQueue,
73 const MesoEdgeType& edgeType):
74 MESegment(id, parent, next, length, speed, idx, multiQueue, edgeType) {
75 myGapTimes.resize(myQueues.size());
76}
77
78
80MELSegment::computeHeadway(Queue& /*q*/, const Queue& /*qNext*/, const MESegment* const /*next*/, const MEVehicle* veh) const {
81 // @note: it might seem sensible to check veh->getQueuingTimeLoss() here but
82 // then the queing state would be "sticky" because queuingTimeLoss is computed with tau_ff
83 // and every leader car that uses tau_jf applies queing timeLoss to it's followers
87 if (myTLSPenalty) {
88 const MSLink* const tllink = getLink(veh, true);
89 if (tllink != nullptr && tllink->isTLSControlled()) {
90 assert(tllink->getGreenFraction() > 0);
91 headway = (SUMOTime)((double)headway / tllink->getGreenFraction());
92 }
93 }
94 return headway;
95}
96
97
98void
99MELSegment::send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason) {
100 GapTimes& gapTimes = myGapTimes[veh->getQueIndex()];
101 // record time when the gap vacated by ego will reach the upstream end of the segment
102 // gaps travel quickly in free flow (the number of gaps and vehicles stays below the segment capacity)
103 // but they travel more slowly when queued (startupDelay)
104 gapTimes.insert(gapTimes.begin(), time + (SUMOTime)(myLength * (double)(veh->getQueuingTimeLoss() > 0 ? myTau_jj : myTau_ff) / DEFAULT_VEH_LENGTH_WITH_GAP));
105 MESegment::send(veh, next, nextQIdx, time, reason);
106}
107
108
109void
111 for (int qIdx = 0; qIdx < (int)myQueues.size(); qIdx++) {
112 Queue& q = myQueues[qIdx];
113 GapTimes& gapTimes = myGapTimes[qIdx];
114 while (!gapTimes.empty() && gapTimes.back() <= time) {
115 gapTimes.pop_back();
116 }
117 if (!gapTimes.empty() && q.getOccupancy() + (double)gapTimes.size() * DEFAULT_VEH_LENGTH_WITH_GAP > myQueueCapacity) {
118 // segment is jammed because the empty spaces have not yet reached the upstream end.
119 q.setEntryBlockTime(MAX2(q.getEntryBlockTime(), gapTimes.back()));
120 }
121 }
122}
123
124
125bool
126MELSegment::hasSpaceForInsertion(const Queue& q, int qIdx, double /*newOccupancy*/, SUMOTime entryTime) const {
127 GapTimes& gapTimes = const_cast<GapTimes&>(myGapTimes[qIdx]);
128 while (!gapTimes.empty() && gapTimes.back() <= entryTime) {
129 gapTimes.pop_back();
130 }
131 return q.getOccupancy() + (double)gapTimes.size() * DEFAULT_VEH_LENGTH_WITH_GAP <= myQueueCapacity;
132}
133
134
135std::string
137 return joinToString(myGapTimes[qIdx], " ");
138}
139
140
141void
142MELSegment::loadQueueExtraState(int qIdx, const std::string& state, SUMOTime offset) {
143 GapTimes& gapTimes = myGapTimes[qIdx];
144 gapTimes.clear();
145 for (const std::string& t : StringTokenizer(state).getVector()) {
146 gapTimes.push_back(StringUtils::toLong(t) - offset);
147 }
148}
149
150
151/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define DEFAULT_VEH_LENGTH_WITH_GAP
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition ToString.h:322
void loadQueueExtraState(int qIdx, const std::string &state, SUMOTime offset) override
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:87
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:86
std::string getQueueExtraState(int qIdx) const override
the gap times of the given queue for saving / loading
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:104
double getOccupancy() const
Definition MESegment.h:88
SUMOTime getEntryBlockTime() const
return the next time at which a vehicle may enter this queue
Definition MESegment.h:99
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:620
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:555
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:597
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition MESegment.h:626
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:597
const double myLength
The segment's length.
Definition MESegment.h:588
SUMOTime myTau_jj
Definition MESegment.h:597
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:600
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:319
SUMOTime getQueuingTimeLoss() const
Returns the time lost compare to free flow.
Definition MEVehicle.h:325
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:268
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:78
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)
std::vector< std::string > getVector()
return vector of strings
static long long int toLong(const std::string &sData)
converts a string into the long value described by it by calling the char-type converter,...
edge type specific meso parameters
Definition MESegment.h:58