Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NLEdgeControlBuilder.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-2024 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/****************************************************************************/
21// Interface for building edges
22/****************************************************************************/
23#include <config.h>
24
25#include <vector>
26#include <string>
27#include <map>
28#include <algorithm>
29#include <iterator>
30#include <mesosim/MELoop.h>
31#include <microsim/MSGlobals.h>
32#include <microsim/MSLane.h>
33#include <microsim/MSEdge.h>
38#include "NLBuilder.h"
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
47 : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0), myCurrentLaneIndex(-1) {
48 myActiveEdge = (MSEdge*) nullptr;
49 myLaneStorage = new std::vector<MSLane*>();
50}
51
52
56
57
58void
60 const std::string& id, const SumoXMLEdgeFunc function,
61 const std::string& streetName,
62 const std::string& edgeType,
63 int priority,
64 const std::string& bidi,
65 double distance) {
66 // closeEdge might not have been called because the last edge had an error, so we clear the lane storage
67 myLaneStorage->clear();
68 myActiveEdge = buildEdge(id, function, streetName, edgeType, priority, distance);
69 if (MSEdge::dictionary(id) != nullptr) {
70 throw InvalidArgument("Another edge with the id '" + id + "' exists.");
71 }
72 myEdges.push_back(myActiveEdge);
73 if (bidi != "") {
75 }
76}
77
78
79MSLane*
80NLEdgeControlBuilder::addLane(const std::string& id,
81 double maxSpeed, double friction, double length,
82 const PositionVector& shape, double width,
83 SVCPermissions permissions,
84 SVCPermissions changeLeft, SVCPermissions changeRight,
85 int index, bool isRampAccel,
86 const std::string& type,
87 const PositionVector& outlineShape) {
88 MSLane* lane = new MSLane(id, maxSpeed, friction, length, myActiveEdge, myCurrentNumericalLaneID++, shape, width, permissions, changeLeft, changeRight, index, isRampAccel, type, outlineShape);
89 myLaneStorage->push_back(lane);
90 myCurrentLaneIndex = index;
91 return lane;
92}
93
94
95void
97 if (myCurrentLaneIndex == -1) {
98 setDefaultStopOffset(stopOffset);
99 } else {
100 updateCurrentLaneStopOffset(stopOffset);
101 }
102}
103
104
105std::string
107 std::stringstream ss;
108 if (myCurrentLaneIndex != -1) {
109 ss << "lane " << myCurrentLaneIndex << " of ";
110 }
111 ss << "edge '" << myActiveEdge->getID() << "'";
112 return ss.str();
113}
114
115
116void
118 if (myLaneStorage->size() == 0) {
119 throw ProcessError("myLaneStorage cannot be empty");
120 }
121 if (stopOffset.isDefined()) {
122 if (myLaneStorage->back()->getLaneStopOffsets().isDefined()) {
123 WRITE_WARNING("Duplicate stopOffset definition for lane " + toString(myLaneStorage->back()->getIndex()) +
124 " on edge " + myActiveEdge->getID() + "!")
125 } else {
126 myLaneStorage->back()->setLaneStopOffset(stopOffset);
127 }
128 }
129}
130
131
132void
135 WRITE_WARNING("Duplicate stopOffset definition for edge " + myActiveEdge->getID() + ". Ignoring duplicate specification.")
136 } else {
137 myCurrentDefaultStopOffset = stopOffsets;
138 }
139}
140
141
142void
144 if (myActiveEdge == nullptr) {
145 throw ProcessError("myActiveEdge cannot be nullptr");
146 }
148 for (const auto& l : *myLaneStorage) {
149 if (!l->getLaneStopOffsets().isDefined()) {
150 l->setLaneStopOffset(myCurrentDefaultStopOffset);
151 }
152 }
153 }
154}
155
156
157void
158NLEdgeControlBuilder::addNeigh(const std::string id) {
159 myOppositeLanes.push_back({myLaneStorage->back(), id});
160}
161
162
163MSEdge*
166 std::vector<MSLane*>* lanes = new std::vector<MSLane*>();
167 lanes->reserve(myLaneStorage->size());
168 copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
169 myLaneStorage->clear();
170 myActiveEdge->initialize(lanes);
172 return myActiveEdge;
173}
174
175
176void
180
181
184 if (MSGlobals::gUseMesoSim && !OptionsCont::getOptions().getBool("meso-lane-queue")) {
185 MSEdge::setMesoIgnoredVClasses(parseVehicleClasses(OptionsCont::getOptions().getStringVector("meso-ignore-lanes-by-vclass")));
186 }
187 // connecting opposite lanes must happen before MSEdge::closeBuilding
188 for (auto item : myOppositeLanes) {
189 MSLane* oppo = MSLane::dictionary(item.second);
190 if (oppo == nullptr) {
191 WRITE_ERRORF("Unknown neigh lane '%' for lane '%'", item.second, item.first->getID());
192 } else {
193 item.first->setOpposite(oppo);
194 }
195 }
196 // consistency check
197 for (auto item : myOppositeLanes) {
198 if (item.first->getOpposite() != nullptr && item.first->getOpposite()->getOpposite() != item.first) {
199 WRITE_WARNINGF(TL("Asymmetrical neigh lane '%' for lane '%'"), item.second, item.first->getID());
200 item.first->getOpposite()->setOpposite(item.first);
201 }
202 }
203 for (MSEdge* const edge : myEdges) {
204 edge->closeBuilding();
205 }
206 for (MSEdge* const edge : myEdges) {
207 edge->rebuildAllowedTargets(false);
208 // segment building depends on the finished list of successors (for multi-queue)
209 if (MSGlobals::gUseMesoSim && !edge->getLanes().empty()) {
211 }
212 }
213 // mark internal edges belonging to a roundabout (after all edges are build)
215 for (MSEdge* const edge : myEdges) {
216 if (edge->isInternal()) {
217 if (edge->getNumSuccessors() != 1 || edge->getNumPredecessors() != 1) {
218 throw ProcessError(TLF("Internal edge '%' is not properly connected (probably a manually modified net.xml).", edge->getID()));
219 }
220 if (edge->getSuccessors()[0]->isRoundabout() || edge->getPredecessors()[0]->isRoundabout()) {
221 edge->markAsRoundabout();
222 }
223 }
224 }
225 }
226 if (!deprecatedVehicleClassesSeen.empty()) {
227 WRITE_WARNINGF(TL("Deprecated vehicle classes '%' in input network."), toString(deprecatedVehicleClassesSeen));
229 }
230 // check for bi-directional edges (this are edges in opposing direction and superposable/congruent shapes)
231 if (myBidiEdges.size() > 0 || networkVersion > MMVersion(1, 0)) {
232 for (auto& item : myBidiEdges) {
233 item.first->checkAndRegisterBiDirEdge(item.second);
234 }
235 //WRITE_MESSAGEF(TL("Loaded % bidirectional edges"), toString(myBidiEdges.size()));
236 } else {
237 // legacy network
238 for (MSEdge* e : myEdges) {
239 e->checkAndRegisterBiDirEdge();
240 }
241 }
242 // take into account bidi lanes when deciding on whether an edge allows changing
243 for (MSEdge* const edge : myEdges) {
244 edge->buildLaneChanger();
245 }
246 return new MSEdgeControl(myEdges);
247}
248
249
250MSEdge*
251NLEdgeControlBuilder::buildEdge(const std::string& id, const SumoXMLEdgeFunc function,
252 const std::string& streetName, const std::string& edgeType, const int priority, const double distance) {
253 return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName, edgeType, priority, distance);
254}
255
256void NLEdgeControlBuilder::addCrossingEdges(const std::vector<std::string>& crossingEdges) {
257 myActiveEdge->setCrossingEdges(crossingEdges);
258}
259
260
261/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define WRITE_ERRORF(...)
Definition MsgHandler.h:305
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
std::set< std::string > deprecatedVehicleClassesSeen
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
SumoXMLEdgeFunc
Numbers representing special SUMO-XML-attribute values for representing edge functions used in netbui...
std::pair< int, double > MMVersion
(M)ajor/(M)inor version for written networks and default version for loading
Definition StdDefs.h:67
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
void buildSegmentsFor(const MSEdge &e, const OptionsCont &oc)
Build the segments for a given edge.
Definition MELoop.cpp:297
Stores edges and lanes, performs moving of vehicle.
A road/street connecting two junctions.
Definition MSEdge.h:77
void setCrossingEdges(const std::vector< std::string > &crossingEdges)
Sets the crossed edge ids for a crossing edge.
Definition MSEdge.h:351
static void setMesoIgnoredVClasses(SVCPermissions ignored)
Definition MSEdge.h:819
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
Definition MSEdge.cpp:102
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1047
static bool gUseMesoSim
Definition MSGlobals.h:106
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition MSGlobals.h:112
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
Representation of a lane in the micro simulation.
Definition MSLane.h:84
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2414
virtual MSEdge * closeEdge()
Closes the building of an edge; The edge is completely described by now and may not be opened again.
virtual void addNeigh(const std::string id)
Adds a neighbor to the current lane.
MSEdgeVector myEdges
Temporary, internal storage for built edges.
MSEdge * myActiveEdge
pointer to the currently chosen edge
void updateCurrentLaneStopOffset(const StopOffset &stopOffset)
set the stopOffset for the last added lane.
void closeLane()
Closes the building of a lane; The edge is completely described by now and may not be opened again.
int myCurrentLaneIndex
The index of the currently active lane (-1 if none is active)
std::vector< std::pair< MSLane *, std::string > > myOppositeLanes
std::string reportCurrentEdgeOrLane() const
Return info about currently processed edge or lane.
int myCurrentNumericalLaneID
A running number for lane numbering.
void beginEdgeParsing(const std::string &id, const SumoXMLEdgeFunc function, const std::string &streetName, const std::string &edgeType, int priority, const std::string &bidi, double distance)
Begins building of an MSEdge.
void setDefaultStopOffset(const StopOffset &stopOffset)
set the stopOffset for the last added lane.
virtual void addCrossingEdges(const std::vector< std::string > &)
add the crossingEdges in a crossing edge if present
void addStopOffsets(const StopOffset &stopOffsets)
process a stopOffset element (originates either from the active edge or lane).
virtual MSLane * addLane(const std::string &id, double maxSpeed, double friction, double length, const PositionVector &shape, double width, SVCPermissions permissions, SVCPermissions changeLeft, SVCPermissions changeRight, int index, bool isRampAccel, const std::string &type, const PositionVector &outlineShape)
Adds a lane to the current edge.
virtual MSEdge * buildEdge(const std::string &id, const SumoXMLEdgeFunc function, const std::string &streetName, const std::string &edgeType, const int priority, const double distance)
Builds an edge instance (MSEdge in this case)
std::vector< MSLane * > * myLaneStorage
pointer to a temporary lane storage
int myCurrentNumericalEdgeID
A running number for edge numbering.
StopOffset myCurrentDefaultStopOffset
The default stop offset for all lanes belonging to the active edge (this is set if the edge was given...
virtual ~NLEdgeControlBuilder()
Destructor.
std::map< MSEdge *, std::string, ComparatorNumericalIdLess > myBidiEdges
temporary storage for bidi attributes (to be resolved after loading all edges)
MSEdgeControl * build(const MMVersion &networkVersion)
builds the MSEdgeControl-class which holds all edges
const std::string & getID() const
Returns the id.
Definition Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
A list of positions.
stop offset
bool isDefined() const
check if stopOffset was defined
void reset()
reset stopOffset