SUMO - Simulation of Urban MObility
NLEdgeControlBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Interface for building edges
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <string>
35 #include <map>
36 #include <algorithm>
37 #include <iterator>
38 #include <microsim/MSGlobals.h>
39 #include <microsim/MSLane.h>
40 #include <microsim/MSEdge.h>
41 #include <microsim/MSEdgeControl.h>
44 #include "NLBuilder.h"
45 #include "NLEdgeControlBuilder.h"
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
54  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
55  myActiveEdge = (MSEdge*) 0;
56  myLaneStorage = new std::vector<MSLane*>();
57 }
58 
59 
61  delete myLaneStorage;
62 }
63 
64 
65 void
67  const std::string& id, const SumoXMLEdgeFunc function,
68  const std::string& streetName,
69  const std::string& edgeType,
70  int priority) {
71  // closeEdge might not have been called because the last edge had an error, so we clear the lane storage
72  myLaneStorage->clear();
73  myActiveEdge = buildEdge(id, function, streetName, edgeType, priority);
74  if (MSEdge::dictionary(id) != 0) {
75  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
76  }
77  myEdges.push_back(myActiveEdge);
78 }
79 
80 
81 MSLane*
82 NLEdgeControlBuilder::addLane(const std::string& id,
83  double maxSpeed, double length,
84  const PositionVector& shape, double width,
85  SVCPermissions permissions, int index, bool isRampAccel) {
86  MSLane* lane = new MSLane(id, maxSpeed, length, myActiveEdge, myCurrentNumericalLaneID++, shape, width, permissions, index, isRampAccel);
87  myLaneStorage->push_back(lane);
88  return lane;
89 }
90 
91 
92 void
93 NLEdgeControlBuilder::addNeigh(const std::string id) {
94  myLaneStorage->back()->addNeigh(id);
95 }
96 
97 
98 MSEdge*
100  std::vector<MSLane*>* lanes = new std::vector<MSLane*>();
101  lanes->reserve(myLaneStorage->size());
102  copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
103  myLaneStorage->clear();
104  myActiveEdge->initialize(lanes);
105  return myActiveEdge;
106 }
107 
108 
111  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
112  (*i1)->closeBuilding();
113  }
114  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
115  (*i1)->buildLaneChanger();
116  }
117  // mark internal edges belonging to a roundabout (after all edges are build)
119  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
120  MSEdge* edge = *i1;
121  if (edge->isInternal()) {
122  if (edge->getNumSuccessors() != 1 || edge->getNumPredecessors() != 1) {
123  throw ProcessError("Internal edge '" + edge->getID() + "' is not properly connected (probably a manually modified net.xml).");
124  }
125  if (edge->getSuccessors()[0]->isRoundabout() || edge->getPredecessors()[0]->isRoundabout()) {
126  edge->markAsRoundabout();
127  }
128  }
129  }
130  }
131  if (!deprecatedVehicleClassesSeen.empty()) {
132  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
134  }
135  // check for bi-directional edges (this are edges in opposing direction and superposable/congruent shapes)
136  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
137  (*i1)->checkAndRegisterBiDirEdge();
138  }
139  return new MSEdgeControl(myEdges);
140 }
141 
142 
143 MSEdge*
144 NLEdgeControlBuilder::buildEdge(const std::string& id, const SumoXMLEdgeFunc function,
145  const std::string& streetName, const std::string& edgeType, const int priority) {
146  return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName, edgeType, priority);
147 }
148 
149 void NLEdgeControlBuilder::addCrossingEdges(const std::vector<std::string>& crossingEdges) {
150  myActiveEdge->setCrossingEdges(crossingEdges);
151 }
152 
153 /****************************************************************************/
154 
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...
void initialize(const std::vector< MSLane * > *lanes)
Initialize the edge.
Definition: MSEdge.cpp:108
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:287
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:745
MSEdgeVector myEdges
Temporary, internal storage for built edges.
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:200
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:81
MSEdgeControl * build()
builds the MSEdgeControl-class which holds all edges
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
const MSEdgeVector & getPredecessors() const
Definition: MSEdge.h:344
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:74
virtual ~NLEdgeControlBuilder()
Destructor.
int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:313
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:76
int myCurrentNumericalEdgeID
A running number for edge numbering.
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:230
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...
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.
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:320
virtual void addCrossingEdges(const std::vector< std::string > &)
add the crossingEdges in a crossing edge if present
void markAsRoundabout()
Definition: MSEdge.h:624
int getNumPredecessors() const
Returns the number of edges this edge is connected to.
Definition: MSEdge.h:336
Representation of a lane in the micro simulation.
Definition: MSLane.h:79