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 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
77void
78MELSegment::updateBlockTime(Queue& q, const Queue& /*qNext*/, const MESegment* const /*next*/, const MEVehicle* veh) {
80 if (myTLSPenalty) {
81 const MSLink* const tllink = getLink(veh, true);
82 if (tllink != nullptr && tllink->isTLSControlled()) {
83 assert(tllink->getGreenFraction() > 0);
85 }
86 }
88}
89
90
91void
92MELSegment::send(MEVehicle* veh, MESegment* const next, const int nextQIdx, SUMOTime time, const MSMoveReminder::Notification reason) {
93 // record time when the gap vacated by ego will reach the upstream end of the segment
94 GapTimes& gapTimes = myGapTimes[veh->getQueIndex()];
95 gapTimes.insert(gapTimes.begin(), time + myLength * myTau_jj / DEFAULT_VEH_LENGTH_WITH_GAP);
96 MESegment::send(veh, next, nextQIdx, time, reason);
97}
98
99
100void
102 for (int qIdx = 0; qIdx < (int)myQueues.size(); qIdx++) {
103 Queue& q = myQueues[qIdx];
104 GapTimes& gapTimes = myGapTimes[qIdx];
105 while (!gapTimes.empty() && gapTimes.back() <= time) {
106 gapTimes.pop_back();
107 }
108 if (!gapTimes.empty() && q.getOccupancy() + gapTimes.size() * DEFAULT_VEH_LENGTH_WITH_GAP > myQueueCapacity) {
109 // segment is jammed because the empty spaces have not yet reached the upstream end.
110 q.setEntryBlockTime(MAX2(q.getEntryBlockTime(), gapTimes.back()));
111 }
112 }
113}
114
115
116bool
117MELSegment::hasSpaceForInsertion(const Queue& q, int qIdx, double /*newOccupancy*/, SUMOTime entryTime) const {
118 GapTimes& gapTimes = const_cast<GapTimes&>(myGapTimes[qIdx]);
119 while (!gapTimes.empty() && gapTimes.back() <= entryTime) {
120 gapTimes.pop_back();
121 }
122 return q.getOccupancy() + gapTimes.size() * DEFAULT_VEH_LENGTH_WITH_GAP < myQueueCapacity;
123}
124
125
126/****************************************************************************/
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 updateBlockTime(Queue &q, const Queue &qNext, const MESegment *const next, const MEVehicle *veh) override
update blockTime of Queue q
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
void setBlockTime(SUMOTime t)
Definition MESegment.h:110
SUMOTime getBlockTime() const
Definition MESegment.h:107
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:583
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:531
SUMOTime myTau_ff
The time headway parameters, see the Eissfeldt thesis.
Definition MESegment.h:560
std::vector< Queue > myQueues
The car queues. Vehicles are inserted in the front and removed in the back.
Definition MESegment.h:589
SUMOTime myLastHeadway
the last headway
Definition MESegment.h:598
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.
const double myLength
The segment's length.
Definition MESegment.h:551
SUMOTime myTau_jj
Definition MESegment.h:560
bool myTLSPenalty
Whether tls penalty is enabled.
Definition MESegment.h:563
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
int getQueIndex() const
Returns the index of the que the vehicle is in.
Definition MEVehicle.h:242
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