SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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 HAVE_INTERNAL
50 #include <mesosim/MELoop.h>
51 #endif
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
62  : myCurrentNumericalLaneID(0), myCurrentNumericalEdgeID(0), myEdges(0) {
63  myActiveEdge = (MSEdge*) 0;
64  myLaneStorage = new std::vector<MSLane*>();
65 }
66 
67 
69  delete myLaneStorage;
70 }
71 
72 
73 void
75  const std::string& id, const MSEdge::EdgeBasicFunction function,
76  const std::string& streetName,
77  const std::string& edgeType,
78  int priority) {
79  myActiveEdge = buildEdge(id, function, streetName, edgeType, priority);
80  if (MSEdge::dictionary(id) != 0) {
81  throw InvalidArgument("Another edge with the id '" + id + "' exists.");
82  }
83  myEdges.push_back(myActiveEdge);
84 }
85 
86 
87 MSLane*
88 NLEdgeControlBuilder::addLane(const std::string& id,
89  SUMOReal maxSpeed, SUMOReal length,
90  const PositionVector& shape, SUMOReal width,
91  SVCPermissions permissions) {
92  MSLane* lane = new MSLane(id, maxSpeed, length, myActiveEdge, myCurrentNumericalLaneID++, shape, width, permissions);
93  myLaneStorage->push_back(lane);
94  return lane;
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 (EdgeCont::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
112  (*i1)->closeBuilding();
113 #ifdef HAVE_INTERNAL
115  MSGlobals::gMesoNet->buildSegmentsFor(**i1, OptionsCont::getOptions());
116  }
117 #endif
118  }
119  // mark internal edges belonging to a roundabout (after all edges are build)
121  for (EdgeCont::iterator i1 = myEdges.begin(); i1 != myEdges.end(); i1++) {
122  MSEdge* edge = *i1;
123  if (edge->isInternal()) {
124  assert(edge->getNumSuccessors() == 1);
125  assert(edge->getIncomingEdges().size() == 1);
126  if (edge->getSuccessor(0)->isRoundabout() || edge->getIncomingEdges()[0]->isRoundabout()) {
127  edge->markAsRoundabout();
128  }
129  }
130  }
131  }
132  if (!deprecatedVehicleClassesSeen.empty()) {
133  WRITE_WARNING("Deprecated vehicle classes '" + toString(deprecatedVehicleClassesSeen) + "' in input network.");
135  }
136  return new MSEdgeControl(myEdges);
137 }
138 
139 
140 MSEdge*
141 NLEdgeControlBuilder::buildEdge(const std::string& id, const MSEdge::EdgeBasicFunction function,
142  const std::string& streetName, const std::string& edgeType, const int priority) {
143  return new MSEdge(id, myCurrentNumericalEdgeID++, function, streetName, edgeType, priority);
144 }
145 
146 
147 
148 /****************************************************************************/
149 
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:106
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
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:523
unsigned int myCurrentNumericalLaneID
A running number for lane numbering.
EdgeBasicFunction
Defines possible edge types.
Definition: MSEdge.h:84
const MSEdge * getSuccessor(unsigned int n) const
Returns the n-th of the following edges.
Definition: MSEdge.h:301
MSEdge * myActiveEdge
pointer to the currently chosen edge
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
unsigned int myCurrentNumericalEdgeID
A running number for edge numbering.
A road/street connecting two junctions.
Definition: MSEdge.h:75
MSEdgeControl * build()
builds the MSEdgeControl-class which holds all edges
EdgeCont myEdges
Temporary, internal storage for built 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:73
virtual ~NLEdgeControlBuilder()
Destructor.
bool isRoundabout() const
Definition: MSEdge.h:546
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:71
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:227
const std::vector< MSEdge * > & getIncomingEdges() const
Returns the list of edges from which this edge may be reached.
Definition: MSEdge.h:284
virtual MSLane * addLane(const std::string &id, SUMOReal maxSpeed, SUMOReal length, const PositionVector &shape, SUMOReal width, SVCPermissions permissions)
Adds a lane to the current edge;.
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:218
static const bool gUseMesoSim
Definition: MSGlobals.h:102
unsigned int getNumSuccessors() const
Returns the number of edges that may be reached from this edge.
Definition: MSEdge.h:292
void markAsRoundabout()
Definition: MSEdge.h:550
Representation of a lane in the micro simulation.
Definition: MSLane.h:77