SUMO - Simulation of Urban MObility
NLEdgeControlBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // Interface for building edges
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <string>
29 #include <map>
30 #include <algorithm>
31 #include <iterator>
32 #include <microsim/MSGlobals.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSEdge.h>
35 #include <microsim/MSEdgeControl.h>
38 #include "NLBuilder.h"
39 #include "NLEdgeControlBuilder.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0), myCurrentLaneIndex(-1) {
49  myActiveEdge = (MSEdge*) 0;
50  myLaneStorage = new std::vector<MSLane*>();
51 }
52 
53 
55  delete myLaneStorage;
56 }
57 
58 
59 void
61  const std::string& id, const SumoXMLEdgeFunc function,
62  const std::string& streetName,
63  const std::string& edgeType,
64  int priority) {
65  // closeEdge might not have been called because the last edge had an error, so we clear the lane storage
66  myLaneStorage->clear();
67  myActiveEdge = buildEdge(id, function, streetName, edgeType, priority);
68  if (MSEdge::dictionary(id) != 0) {
69  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
70  }
71  myEdges.push_back(myActiveEdge);
72 }
73 
74 
75 MSLane*
76 NLEdgeControlBuilder::addLane(const std::string& id,
77  double maxSpeed, double length,
78  const PositionVector& shape, double width,
79  SVCPermissions permissions, int index, bool isRampAccel) {
80  MSLane* lane = new MSLane(id, maxSpeed, length, myActiveEdge, myCurrentNumericalLaneID++, shape, width, permissions, index, isRampAccel);
81  myLaneStorage->push_back(lane);
82  myCurrentLaneIndex = index;
83  return lane;
84 }
85 
86 
87 void
88 NLEdgeControlBuilder::addStopOffsets(const std::map<SVCPermissions, double>& stopOffsets) {
89 
90  if (myCurrentLaneIndex == -1) {
91  setDefaultStopOffsets(stopOffsets);
92  } else {
93  updateCurrentLaneStopOffsets(stopOffsets);
94  }
95 }
96 
97 
98 
99 std::string
101  std::stringstream ss;
102  if (myCurrentLaneIndex != -1) {
103  ss << "lane " << myCurrentLaneIndex << " of ";
104  }
105  ss << "edge '" << myActiveEdge->getID() << "'";
106  return ss.str();
107 }
108 
109 
110 void
111 NLEdgeControlBuilder::updateCurrentLaneStopOffsets(const std::map<SVCPermissions, double>& stopOffsets) {
112  assert(myLaneStorage->size() != 0);
113  if (stopOffsets.size() == 0) {
114  return;
115  }
116  if (myLaneStorage->back()->getStopOffsets().size() != 0) {
117  std::stringstream ss;
118  ss << "Duplicate stopOffset definition for lane " << myLaneStorage->back()->getIndex() << " on edge " << myActiveEdge->getID() << "!";
119  WRITE_WARNING(ss.str())
120  } else {
121  myLaneStorage->back()->setStopOffsets(stopOffsets);
122  }
123 }
124 
125 
126 void
127 NLEdgeControlBuilder::setDefaultStopOffsets(std::map<SVCPermissions, double> stopOffsets) {
128  if (myCurrentDefaultStopOffsets.size() != 0) {
129  std::stringstream ss;
130  ss << "Duplicate stopOffset definition for edge " << myActiveEdge->getID() << ". Ignoring duplicate specification.";
131  WRITE_WARNING(ss.str())
132  } else {
133  myCurrentDefaultStopOffsets = stopOffsets;
134  }
135 }
136 
137 
138 void
140  assert(myActiveEdge != 0);
141  if (myCurrentDefaultStopOffsets.size() == 0) {
142  return;
143  }
144  for (MSLane* l : *myLaneStorage) {
145  if (l->getStopOffsets().size() == 0) {
146  l->setStopOffsets(myCurrentDefaultStopOffsets);
147  }
148  }
149 }
150 
151 
152 void
153 NLEdgeControlBuilder::addNeigh(const std::string id) {
154  myLaneStorage->back()->addNeigh(id);
155 }
156 
157 
158 MSEdge*
161  std::vector<MSLane*>* lanes = new std::vector<MSLane*>();
162  lanes->reserve(myLaneStorage->size());
163  copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
164  myLaneStorage->clear();
165  myActiveEdge->initialize(lanes);
167  return myActiveEdge;
168 }
169 
170 
171 void
173  myCurrentLaneIndex = -1;
174 }
175 
176 
179  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
180  (*i1)->closeBuilding();
181  }
182  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
183  (*i1)->buildLaneChanger();
184  }
185  // mark internal edges belonging to a roundabout (after all edges are build)
187  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
188  MSEdge* edge = *i1;
189  if (edge->isInternal()) {
190  if (edge->getNumSuccessors() != 1 || edge->getNumPredecessors() != 1) {
191  throw ProcessError("Internal edge '" + edge->getID() + "' is not properly connected (probably a manually modified net.xml).");
192  }
193  if (edge->getSuccessors()[0]->isRoundabout() || edge->getPredecessors()[0]->isRoundabout()) {
194  edge->markAsRoundabout();
195  }
196  }
197  }
198  }
199  if (!deprecatedVehicleClassesSeen.empty()) {
200  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
202  }
203  // check for bi-directional edges (this are edges in opposing direction and superposable/congruent shapes)
204  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
205  (*i1)->checkAndRegisterBiDirEdge();
206  }
207  return new MSEdgeControl(myEdges);
208 }
209 
210 
211 MSEdge*
212 NLEdgeControlBuilder::buildEdge(const std::string& id, const SumoXMLEdgeFunc function,
213  const std::string& streetName, const std::string& edgeType, const int priority) {
214  return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName, edgeType, priority);
215 }
216 
217 void NLEdgeControlBuilder::addCrossingEdges(const std::vector<std::string>& crossingEdges) {
218  myActiveEdge->setCrossingEdges(crossingEdges);
219 }
220 
221 /****************************************************************************/
222 
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:329
std::set< std::string > deprecatedVehicleClassesSeen
virtual MSEdge * closeEdge()
Closes the building of an edge; The edge is completely described by now and may not be opened again...
const MSEdgeVector & getPredecessors() const
Definition: MSEdge.h:337
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
void setCrossingEdges(const std::vector< std::string > &crossingEdges)
Sets the crossed edge ids for a crossing edge.
Definition: MSEdge.h:281
void addStopOffsets(const std::map< SVCPermissions, double > &stopOffsets)
process a stopOffset element (originates either from the active edge or lane).
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:742
MSEdgeVector myEdges
Temporary, internal storage for built edges.
void initialize(const std::vector< MSLane *> *lanes)
Initialize the edge.
Definition: MSEdge.cpp:101
const std::string & getID() const
Returns the id.
Definition: Named.h:69
virtual MSEdge * buildEdge(const std::string &id, const SumoXMLEdgeFunc function, const std::string &streetName, const std::string &edgeType, const int priority)
Builds an edge instance (MSEdge in this case)
MSEdge * myActiveEdge
pointer to the currently chosen edge
void updateCurrentLaneStopOffsets(const std::map< SVCPermissions, double > &stopOffsets)
set the stopOffset for the last added lane.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:307
void setDefaultStopOffsets(std::map< SVCPermissions, double > stopOffsets)
set the stopOffset for the last added lane.
A road/street connecting two junctions.
Definition: MSEdge.h:75
MSEdgeControl * build()
builds the MSEdgeControl-class which holds all edges
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
A list of positions.
std::vector< MSLane * > * myLaneStorage
pointer to a temporary lane storage
NLEdgeControlBuilder()
Constructor.
Stores edges and lanes, performs moving of vehicle.
Definition: MSEdgeControl.h:67
virtual ~NLEdgeControlBuilder()
Destructor.
std::string reportCurrentEdgeOrLane() const
Return info about currently processed edge or lane.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:69
int myCurrentNumericalEdgeID
A running number for edge numbering.
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:224
virtual void addNeigh(const std::string id)
Adds a neighbor to the current lane.
int myCurrentLaneIndex
The index of the currently active lane (-1 if none is active)
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition: MSEdge.cpp:926
void closeLane()
Closes the building of a lane; The edge is completely described by now and may not be opened again...
virtual MSLane * addLane(const std::string &id, double maxSpeed, double length, const PositionVector &shape, double width, SVCPermissions permissions, int index, bool isRampAccel)
Adds a lane to the current edge.
SumoXMLEdgeFunc
Numbers representing special SUMO-XML-attribute values for representing edge functions used in netbui...
void beginEdgeParsing(const std::string &id, const SumoXMLEdgeFunc function, const std::string &streetName, const std::string &edgeType, int priority)
Begins building of an MSEdge.
int myCurrentNumericalLaneID
A running number for lane numbering.
virtual void addCrossingEdges(const std::vector< std::string > &)
add the crossingEdges in a crossing edge if present
void markAsRoundabout()
Definition: MSEdge.h:618
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
std::map< SVCPermissions, double > myCurrentDefaultStopOffsets
The default stop offset for all lanes belonging to the active edge (this is set if the edge was given...