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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Interface for building edges
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <vector>
33 #include <string>
34 #include <map>
35 #include <algorithm>
36 #include <iterator>
37 #include <microsim/MSGlobals.h>
38 #include <microsim/MSLane.h>
39 #include <microsim/MSEdge.h>
40 #include <microsim/MSEdgeControl.h>
43 #include "NLBuilder.h"
44 #include "NLEdgeControlBuilder.h"
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
54  myActiveEdge = (MSEdge*) 0;
55  myLaneStorage = new std::vector<MSLane*>();
56 }
57 
58 
60  delete myLaneStorage;
61 }
62 
63 
64 void
66  const std::string& id, const SumoXMLEdgeFunc function,
67  const std::string& streetName,
68  const std::string& edgeType,
69  int priority) {
70  // closeEdge might not have been called because the last edge had an error, so we clear the lane storage
71  myLaneStorage->clear();
72  myActiveEdge = buildEdge(id, function, streetName, edgeType, priority);
73  if (MSEdge::dictionary(id) != 0) {
74  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
75  }
76  myEdges.push_back(myActiveEdge);
77 }
78 
79 
80 MSLane*
81 NLEdgeControlBuilder::addLane(const std::string& id,
82  double maxSpeed, double length,
83  const PositionVector& shape, double width,
84  SVCPermissions permissions, int index, bool isRampAccel) {
85  MSLane* lane = new MSLane(id, maxSpeed, length, myActiveEdge, myCurrentNumericalLaneID++, shape, width, permissions, index, isRampAccel);
86  myLaneStorage->push_back(lane);
87  return lane;
88 }
89 
90 
91 void
92 NLEdgeControlBuilder::addNeigh(const std::string id) {
93  myLaneStorage->back()->addNeigh(id);
94 }
95 
96 
97 MSEdge*
99  std::vector<MSLane*>* lanes = new std::vector<MSLane*>();
100  lanes->reserve(myLaneStorage->size());
101  copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
102  myLaneStorage->clear();
103  myActiveEdge->initialize(lanes);
104  return myActiveEdge;
105 }
106 
107 
110  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
111  (*i1)->closeBuilding();
112  }
113  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
114  (*i1)->buildLaneChanger();
115  }
116  // mark internal edges belonging to a roundabout (after all edges are build)
118  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
119  MSEdge* edge = *i1;
120  if (edge->isInternal()) {
121  if (edge->getNumSuccessors() != 1 || edge->getNumPredecessors() != 1) {
122  throw ProcessError("Internal edge '" + edge->getID() + "' is not properly connected (probably a manually modified net.xml).");
123  }
124  if (edge->getSuccessors()[0]->isRoundabout() || edge->getPredecessors()[0]->isRoundabout()) {
125  edge->markAsRoundabout();
126  }
127  }
128  }
129  }
130  if (!deprecatedVehicleClassesSeen.empty()) {
131  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
133  }
134  // check for bi-directional edges (this are edges in opposing direction and superposable/congruent shapes)
135  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
136  (*i1)->checkAndRegisterBiDirEdge();
137  }
138  return new MSEdgeControl(myEdges);
139 }
140 
141 
142 MSEdge*
143 NLEdgeControlBuilder::buildEdge(const std::string& id, const SumoXMLEdgeFunc function,
144  const std::string& streetName, const std::string& edgeType, const int priority) {
145  return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName, edgeType, priority);
146 }
147 
148 void NLEdgeControlBuilder::addCrossingEdges(const std::vector<std::string>& crossingEdges) {
149  myActiveEdge->setCrossingEdges(crossingEdges);
150 }
151 
152 /****************************************************************************/
153 
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:335
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:343
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:286
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:744
MSEdgeVector myEdges
Temporary, internal storage for built edges.
void initialize(const std::vector< MSLane *> *lanes)
Initialize the edge.
Definition: MSEdge.cpp:107
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:312
A road/street connecting two junctions.
Definition: MSEdge.h:80
MSEdgeControl * build()
builds the MSEdgeControl-class which holds all edges
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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:73
virtual ~NLEdgeControlBuilder()
Destructor.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:75
int myCurrentNumericalEdgeID
A running number for edge numbering.
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:229
virtual void addNeigh(const std::string id)
Adds a neighbor to the current lane.
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...
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:319
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:623
Representation of a lane in the micro simulation.
Definition: MSLane.h:77