SUMO - Simulation of Urban MObility
NGEdge.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2003-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 // A netgen-representation of an edge
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <algorithm>
29 #include <netbuild/NBNode.h>
30 #include <netbuild/NBNodeCont.h>
31 #include <netbuild/NBEdge.h>
32 #include <netbuild/NBOwnTLDef.h>
33 #include <netbuild/NBTypeCont.h>
35 #include <netbuild/NBNetBuilder.h>
37 #include <utils/common/ToString.h>
40 #include <utils/options/Option.h>
41 #include "NGEdge.h"
42 #include "NGNode.h"
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // NGEdge-definitions
50 // ---------------------------------------------------------------------------
51 NGEdge::NGEdge(const std::string& id, NGNode* startNode, NGNode* endNode)
52  : Named(id), myStartNode(startNode), myEndNode(endNode) {
53  myStartNode->addLink(this);
54  myEndNode->addLink(this);
55 }
56 
57 
59  myStartNode->removeLink(this);
60  myEndNode->removeLink(this);
61 }
62 
63 
64 NBEdge*
66  int priority = nb.getTypeCont().getPriority("");
67  if (priority > 1 && OptionsCont::getOptions().getBool("rand.random-priority")) {
68  priority = RandHelper::rand(priority) + 1;
69  }
70  int lanenumber = nb.getTypeCont().getNumLanes("");
71  if (lanenumber > 1 && OptionsCont::getOptions().getBool("rand.random-lanenumber")) {
72  lanenumber = RandHelper::rand(lanenumber) + 1;
73  }
74  return new NBEdge(
75  myID,
76  nb.getNodeCont().retrieve(myStartNode->getID()), // from
77  nb.getNodeCont().retrieve(myEndNode->getID()), // to
78  "", nb.getTypeCont().getSpeed(""), lanenumber,
80  );
81 }
82 
83 
84 /****************************************************************************/
85 
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:108
~NGEdge()
Destructor.
Definition: NGEdge.cpp:58
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:174
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:160
NBEdge * buildNBEdge(NBNetBuilder &nb) const
Builds and returns this link&#39;s netbuild-representation.
Definition: NGEdge.cpp:65
The representation of a single edge during network building.
Definition: NBEdge.h:65
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:61
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:180
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:261
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:110
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:168
const std::string & getID() const
Returns the id.
Definition: Named.h:78
NGEdge(const std::string &id, NGNode *startNode, NGNode *endNode)
Constructor.
Definition: NGEdge.cpp:51
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:210
Base class for objects which have an id.
Definition: Named.h:58
std::string myID
The name of the object.
Definition: Named.h:130
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
NGNode * myEndNode
The node the edge ends at.
Definition: NGEdge.h:110
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
A netgen-representation of a node.
Definition: NGNode.h:51
NGNode * myStartNode
The node the edge starts at.
Definition: NGEdge.h:107
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:104