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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // A netgen-representation of an edge
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <algorithm>
27 #include <netbuild/NBNode.h>
28 #include <netbuild/NBNodeCont.h>
29 #include <netbuild/NBEdge.h>
30 #include <netbuild/NBOwnTLDef.h>
31 #include <netbuild/NBTypeCont.h>
33 #include <netbuild/NBNetBuilder.h>
35 #include <utils/common/ToString.h>
38 #include <utils/options/Option.h>
39 #include "NGEdge.h"
40 #include "NGNode.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // NGEdge-definitions
48 // ---------------------------------------------------------------------------
49 NGEdge::NGEdge(const std::string& id, NGNode* startNode, NGNode* endNode, const std::string& reverseID) :
50  Named(id), myStartNode(startNode), myEndNode(endNode), myReverseID(reverseID == "" ? "-" + id : reverseID) {
51  myStartNode->addLink(this);
52  myEndNode->addLink(this);
53 }
54 
55 
57  myStartNode->removeLink(this);
58  myEndNode->removeLink(this);
59 }
60 
61 
62 NBEdge*
63 NGEdge::buildNBEdge(NBNetBuilder& nb, const std::string& type, const bool reversed) const {
64  int priority = nb.getTypeCont().getEdgeTypePriority(type);
65  if (priority > 1 && OptionsCont::getOptions().getBool("rand.random-priority")) {
66  priority = RandHelper::rand(priority) + 1;
67  }
68  int lanenumber = nb.getTypeCont().getEdgeTypeNumLanes(type);
69  if (lanenumber > 1 && OptionsCont::getOptions().getBool("rand.random-lanenumber")) {
70  lanenumber = RandHelper::rand(lanenumber) + 1;
71  }
72 
73  SVCPermissions permissions = nb.getTypeCont().getEdgeTypePermissions(type);
75  if (isRailway(permissions) && nb.getTypeCont().getEdgeTypeIsOneWay(type)) {
77  }
78  NBEdge* result = new NBEdge(
79  reversed ? myReverseID : myID,
80  nb.getNodeCont().retrieve(reversed ? myEndNode->getID() : myStartNode->getID()), // from
81  nb.getNodeCont().retrieve(reversed ? myStartNode->getID() : myEndNode->getID()), // to
82  type, nb.getTypeCont().getEdgeTypeSpeed(type), lanenumber,
83  priority, nb.getTypeCont().getEdgeTypeWidth(type), NBEdge::UNSPECIFIED_OFFSET, lsf);
84  result->setPermissions(permissions);
85  return result;
86 }
87 
88 
89 /****************************************************************************/
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
LaneSpreadFunction
Numbers representing special SUMO-XML-attribute values Information how the edge's lateral offset shal...
The representation of a single edge during network building.
Definition: NBEdge.h:91
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:3985
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition: NBEdge.h:352
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
NBTypeCont & getTypeCont()
Returns a reference to the type container.
Definition: NBNetBuilder.h:158
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:153
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Definition: NBNodeCont.cpp:119
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
Definition: NBTypeCont.cpp:476
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
Definition: NBTypeCont.cpp:482
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
Definition: NBTypeCont.cpp:470
double getEdgeTypeWidth(const std::string &edgeType) const
Returns the lane width for the given edgeType [m].
Definition: NBTypeCont.cpp:532
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
Definition: NBTypeCont.cpp:520
LaneSpreadFunction getEdgeTypeSpreadType(const std::string &edgeType) const
Returns spreadType for the given edgeType.
Definition: NBTypeCont.cpp:526
bool getEdgeTypeIsOneWay(const std::string &edgeType) const
Returns whether edges are one-way per default for the given edgeType.
Definition: NBTypeCont.cpp:488
const std::string myReverseID
The id when building the reverse edge.
Definition: NGEdge.h:110
NBEdge * buildNBEdge(NBNetBuilder &nb, const std::string &type, const bool reversed=false) const
Builds and returns this link's netbuild-representation.
Definition: NGEdge.cpp:63
~NGEdge()
Destructor.
Definition: NGEdge.cpp:56
NGNode * myStartNode
The node the edge starts at.
Definition: NGEdge.h:104
NGNode * myEndNode
The node the edge ends at.
Definition: NGEdge.h:107
NGEdge(const std::string &id, NGNode *startNode, NGNode *endNode, const std::string &reverseID="")
Constructor.
Definition: NGEdge.cpp:49
A netgen-representation of a node.
Definition: NGNode.h:48
void addLink(NGEdge *link)
Adds the given link to the internal list.
Definition: NGNode.cpp:105
void removeLink(NGEdge *link)
Removes the given link.
Definition: NGNode.cpp:111
Base class for objects which have an id.
Definition: Named.h:54
std::string myID
The name of the object.
Definition: Named.h:125
const std::string & getID() const
Returns the id.
Definition: Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:119