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-2016 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 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
59  myActiveEdge = (MSEdge*) 0;
60  myLaneStorage = new std::vector<MSLane*>();
61 }
62 
63 
65  delete myLaneStorage;
66 }
67 
68 
69 void
71  const std::string& id, const MSEdge::EdgeBasicFunction function,
72  const std::string& streetName,
73  const std::string& edgeType,
74  int priority) {
75  myActiveEdge = buildEdge(id, function, streetName, edgeType, priority);
76  if (MSEdge::dictionary(id) != 0) {
77  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
78  }
79  myEdges.push_back(myActiveEdge);
80 }
81 
82 
83 MSLane*
84 NLEdgeControlBuilder::addLane(const std::string& id,
85  SUMOReal maxSpeed, SUMOReal length,
86  const PositionVector& shape, SUMOReal width,
87  SVCPermissions permissions, int index) {
88  MSLane* lane = new MSLane(id, maxSpeed, length, myActiveEdge, myCurrentNumericalLaneID++, shape, width, permissions, index);
89  myLaneStorage->push_back(lane);
90  return lane;
91 }
92 
93 
94 void
95 NLEdgeControlBuilder::addNeigh(const std::string id) {
96  myLaneStorage->back()->addNeigh(id);
97 }
98 
99 
100 MSEdge*
102  std::vector<MSLane*>* lanes = new std::vector<MSLane*>();
103  lanes->reserve(myLaneStorage->size());
104  copy(myLaneStorage->begin(), myLaneStorage->end(), back_inserter(*lanes));
105  myLaneStorage->clear();
106  myActiveEdge->initialize(lanes);
107  return myActiveEdge;
108 }
109 
110 
113  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
114  (*i1)->closeBuilding();
115  }
116  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
117  (*i1)->buildLaneChanger();
118  }
119  // mark internal edges belonging to a roundabout (after all edges are build)
121  for (MSEdgeVector::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
122  MSEdge* edge = *i1;
123  if (edge->isInternal()) {
124  if (edge->getNumSuccessors() != 1 || edge->getIncomingEdges().size() != 1) {
125  throw ProcessError("Internal edge '" + edge->getID() + "' is not properly connected (probably a manually modified net.xml).");
126  }
127  if (edge->getSuccessors()[0]->isRoundabout() || edge->getIncomingEdges()[0]->isRoundabout()) {
128  edge->markAsRoundabout();
129  }
130  }
131  }
132  }
133  if (!deprecatedVehicleClassesSeen.empty()) {
134  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
136  }
137  return new MSEdgeControl(myEdges);
138 }
139 
140 
141 MSEdge*
142 NLEdgeControlBuilder::buildEdge(const std::string& id, const MSEdge::EdgeBasicFunction function,
143  const std::string& streetName, const std::string& edgeType, const int priority) {
144  return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName, edgeType, priority);
145 }
146 
147 void NLEdgeControlBuilder::addCrossingEdges(const std::vector<std::string>& crossingEdges) {
148  myActiveEdge->setCrossingEdges(crossingEdges);
149 }
150 
151 /****************************************************************************/
152 
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:110
virtual MSEdge * buildEdge(const std::string &id, const MSEdge::EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, const int priority)
Builds an edge instance (MSEdge in this case)
int SVCPermissions
void setCrossingEdges(const std::vector< std::string > &crossingEdges)
Sets the crossed edge ids for a crossing edge.
Definition: MSEdge.h:298
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:666
MSEdgeVector myEdges
Temporary, internal storage for built edges.
const MSEdgeVector & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:328
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:89
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:80
MSEdgeControl * build()
builds the MSEdgeControl-class which holds all edges
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:342
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:69
int myCurrentNumericalEdgeID
A running number for edge numbering.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:254
virtual void addNeigh(const std::string id)
Adds a neighbor to the current lane.
virtual MSLane * addLane(const std::string &id, SUMOReal maxSpeed, SUMOReal length, const PositionVector &shape, SUMOReal width, SVCPermissions permissions, int index)
Adds a lane to the current edge.
int myCurrentNumericalLaneID
A running number for lane numbering.
void beginEdgeParsing(const std::string &id, const MSEdge::EdgeBasicFunction function, const std::string &streetName, const std::string &edgeType, int priority)
Begins building of an MSEdge.
#define SUMOReal
Definition: config.h:213
const MSEdgeVector & getSuccessors() const
Returns the following edges.
Definition: MSEdge.h:349
virtual void addCrossingEdges(const std::vector< std::string > &)
add the crossingEdges in a crossing edge if present
void markAsRoundabout()
Definition: MSEdge.h:636
Representation of a lane in the micro simulation.
Definition: MSLane.h:79