Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NGEdge.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2003-2024 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>
39#include "NGEdge.h"
40#include "NGNode.h"
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46// ---------------------------------------------------------------------------
47// NGEdge-definitions
48// ---------------------------------------------------------------------------
49NGEdge::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
60
61
62NBEdge*
63NGEdge::buildNBEdge(NBNetBuilder& nb, std::string type, const bool reversed) const {
65 if (oc.getBool("random-type") && nb.getTypeCont().size() > 1) {
66 auto it = nb.getTypeCont().begin();
67 std::advance(it, RandHelper::rand((int)nb.getTypeCont().size()));
68 type = it->first;
69 }
70 int priority = nb.getTypeCont().getEdgeTypePriority(type);
71 if (priority > 1 && oc.getBool("rand.random-priority")) {
72 priority = RandHelper::rand(priority) + 1;
73 }
74 int lanenumber = nb.getTypeCont().getEdgeTypeNumLanes(type);
75 if (lanenumber > 1 && oc.getBool("rand.random-lanenumber")) {
76 lanenumber = RandHelper::rand(lanenumber) + 1;
77 }
78
79 SVCPermissions permissions = nb.getTypeCont().getEdgeTypePermissions(type);
81 if (isRailway(permissions) && nb.getTypeCont().getEdgeTypeIsOneWay(type)) {
83 }
84 const double maxSegmentLength = oc.getFloat("geometry.max-segment-length");
85 NBNode* from = nb.getNodeCont().retrieve(reversed ? myEndNode->getID() : myStartNode->getID());
86 NBNode* to = nb.getNodeCont().retrieve(reversed ? myStartNode->getID() : myEndNode->getID());
87 PositionVector shape;
88 if (maxSegmentLength > 0) {
89 shape.push_back(from->getPosition());
90 shape.push_back(to->getPosition());
91 // shape is already cartesian but we must use a copy because the original will be modified
92 NBNetBuilder::addGeometrySegments(shape, PositionVector(shape), maxSegmentLength);
93 }
94 NBEdge* result = new NBEdge(
95 reversed ? myReverseID : myID,
96 from, to,
97 type, nb.getTypeCont().getEdgeTypeSpeed(type), NBEdge::UNSPECIFIED_FRICTION, lanenumber,
98 priority, nb.getTypeCont().getEdgeTypeWidth(type), NBEdge::UNSPECIFIED_OFFSET, shape, lsf);
99 result->setPermissions(permissions);
100 return result;
101}
102
103
104/****************************************************************************/
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permissions is a railway edge.
long long 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:92
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:4342
static const double UNSPECIFIED_FRICTION
unspecified lane friction
Definition NBEdge.h:355
static const double UNSPECIFIED_OFFSET
unspecified lane offset
Definition NBEdge.h:349
Instance responsible for building networks.
static int addGeometrySegments(PositionVector &from, const PositionVector &cartesian, const double maxLength)
insertion geometry points to ensure maximum segment length between points
NBNodeCont & getNodeCont()
Returns a reference to the node container.
NBTypeCont & getTypeCont()
Returns a reference to the type container.
NBNode * retrieve(const std::string &id) const
Returns the node with the given name.
Represents a single node (junction) during network building.
Definition NBNode.h:66
const Position & getPosition() const
Definition NBNode.h:260
int size() const
Returns the number of known edgeTypes.
double getEdgeTypeSpeed(const std::string &edgeType) const
Returns the maximal velocity for the given edgeType [m/s].
int getEdgeTypePriority(const std::string &edgeType) const
Returns the priority for the given edgeType.
TypesCont::const_iterator begin() const
return begin iterator
int getEdgeTypeNumLanes(const std::string &edgeType) const
Returns the number of lanes for the given edgeType.
double getEdgeTypeWidth(const std::string &edgeType) const
Returns the lane width for the given edgeType [m].
SVCPermissions getEdgeTypePermissions(const std::string &edgeType) const
Returns allowed vehicle classes for the given edgeType.
LaneSpreadFunction getEdgeTypeSpreadType(const std::string &edgeType) const
Returns spreadType for the given edgeType.
bool getEdgeTypeIsOneWay(const std::string &edgeType) const
Returns whether edges are one-way per default for the given edgeType.
const std::string myReverseID
The id when building the reverse edge.
Definition NGEdge.h:110
NBEdge * buildNBEdge(NBNetBuilder &nb, 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
A storage for options typed value containers)
Definition OptionsCont.h:89
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
A list of positions.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)