Eclipse 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-2019 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 /****************************************************************************/
17 // A netgen-representation of an edge
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <algorithm>
28 #include <netbuild/NBNode.h>
29 #include <netbuild/NBNodeCont.h>
30 #include <netbuild/NBEdge.h>
31 #include <netbuild/NBOwnTLDef.h>
32 #include <netbuild/NBTypeCont.h>
34 #include <netbuild/NBNetBuilder.h>
36 #include <utils/common/ToString.h>
39 #include <utils/options/Option.h>
40 #include "NGEdge.h"
41 #include "NGNode.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 // ---------------------------------------------------------------------------
48 // NGEdge-definitions
49 // ---------------------------------------------------------------------------
50 NGEdge::NGEdge(const std::string& id, NGNode* startNode, NGNode* endNode)
51  : Named(id), myStartNode(startNode), myEndNode(endNode) {
52  myStartNode->addLink(this);
53  myEndNode->addLink(this);
54 }
55 
56 
58  myStartNode->removeLink(this);
59  myEndNode->removeLink(this);
60 }
61 
62 
63 NBEdge*
64 NGEdge::buildNBEdge(NBNetBuilder& nb, const std::string& type) const {
65  int priority = nb.getTypeCont().getPriority(type);
66  if (priority > 1 && OptionsCont::getOptions().getBool("rand.random-priority")) {
67  priority = RandHelper::rand(priority) + 1;
68  }
69  int lanenumber = nb.getTypeCont().getNumLanes(type);
70  if (lanenumber > 1 && OptionsCont::getOptions().getBool("rand.random-lanenumber")) {
71  lanenumber = RandHelper::rand(lanenumber) + 1;
72  }
73 
74  SVCPermissions permissions = nb.getTypeCont().getPermissions(type);
76  if (isRailway(permissions) && nb.getTypeCont().getIsOneWay(type)) {
77  lsf = LANESPREAD_CENTER;
78  }
79  NBEdge* result = new NBEdge(
80  myID,
81  nb.getNodeCont().retrieve(myStartNode->getID()), // from
82  nb.getNodeCont().retrieve(myEndNode->getID()), // to
83  type, nb.getTypeCont().getSpeed(type), lanenumber,
84  priority, nb.getTypeCont().getWidth(type), NBEdge::UNSPECIFIED_OFFSET,
85  "", lsf);
86  result->setPermissions(permissions);
87  return result;
88 }
89 
90 
91 /****************************************************************************/
92 
NBEdge::UNSPECIFIED_OFFSET
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:318
ToString.h
Named
Base class for objects which have an id.
Definition: Named.h:56
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
OptionsCont.h
LANESPREAD_RIGHT
@ LANESPREAD_RIGHT
Definition: SUMOXMLDefinitions.h:1098
GeoConvHelper.h
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
NBEdge::setPermissions
void setPermissions(SVCPermissions permissions, int lane=-1)
set allowed/disallowed classes for the given lane or for all lanes if -1 is given
Definition: NBEdge.cpp:3376
NGEdge::myStartNode
NGNode * myStartNode
The node the edge starts at.
Definition: NGEdge.h:106
NGNode::removeLink
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:109
LANESPREAD_CENTER
@ LANESPREAD_CENTER
Definition: SUMOXMLDefinitions.h:1099
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
NGEdge::myEndNode
NGNode * myEndNode
The node the edge ends at.
Definition: NGEdge.h:109
NGEdge::buildNBEdge
NBEdge * buildNBEdge(NBNetBuilder &nb, const std::string &type) const
Builds and returns this link's netbuild-representation.
Definition: NGEdge.cpp:64
NGNode::addLink
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:103
NBTypeCont::getIsOneWay
bool getIsOneWay(const std::string &type) const
Returns whether edges are one-way per default for the given type.
Definition: NBTypeCont.cpp:189
RandHelper::rand
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:53
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:218
NBTypeCont::getSpeed
double getSpeed(const std::string &type) const
Returns the maximal velocity for the given type [m/s].
Definition: NBTypeCont.cpp:177
NBTypeCont.h
NBNetBuilder.h
isRailway
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
Definition: SUMOVehicleClass.cpp:363
UtilExceptions.h
NGEdge::NGEdge
NGEdge(const std::string &id, NGNode *startNode, NGNode *endNode)
Constructor.
Definition: NGEdge.cpp:50
NBTypeCont::getPriority
int getPriority(const std::string &type) const
Returns the priority for the given type.
Definition: NBTypeCont.cpp:183
NBNodeCont::retrieve
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:107
NBNodeCont.h
Option.h
NBTypeCont::getPermissions
SVCPermissions getPermissions(const std::string &type) const
Returns allowed vehicle classes for the given type.
Definition: NBTypeCont.cpp:221
NBTypeCont::getWidth
double getWidth(const std::string &type) const
Returns the lane width for the given type [m].
Definition: NBTypeCont.cpp:227
NBTypeCont::getNumLanes
int getNumLanes(const std::string &type) const
Returns the number of lanes for the given type.
Definition: NBTypeCont.cpp:171
LaneSpreadFunction
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
Definition: SUMOXMLDefinitions.h:1097
config.h
RandHelper.h
NBOwnTLDef.h
NBTrafficLightLogicCont.h
NBNetBuilder::getNodeCont
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
Named::myID
std::string myID
The name of the object.
Definition: Named.h:133
NBNetBuilder::getTypeCont
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:160
NBNode.h
NGNode.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
NGNode
A netgen-representation of a node.
Definition: NGNode.h:50
NGEdge::~NGEdge
~NGEdge()
Destructor.
Definition: NGEdge.cpp:57
NBEdge.h
NGEdge.h