Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netgen/NGEdge.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2003-2025 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
/****************************************************************************/
14
/// @file NGEdge.cpp
15
/// @author Markus Hartinger
16
/// @author Daniel Krajzewicz
17
/// @author Michael Behrisch
18
/// @author Jakob Erdmann
19
/// @date Mar, 2003
20
///
21
// A netgen-representation of an edge
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <algorithm>
26
#include <utils/common/RandHelper.h>
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>
32
#include <netbuild/NBTrafficLightLogicCont.h>
33
#include <netbuild/NBNetBuilder.h>
34
#include <utils/common/UtilExceptions.h>
35
#include <utils/common/ToString.h>
36
#include <utils/geom/GeoConvHelper.h>
37
#include <utils/options/OptionsCont.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
56
NGEdge::~NGEdge() {
57
myStartNode->removeLink(this);
58
myEndNode->removeLink(this);
59
}
60
61
62
NBEdge*
63
NGEdge::buildNBEdge(NBNetBuilder& nb, std::string type, const bool reversed) const {
64
const OptionsCont& oc = OptionsCont::getOptions();
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);
80
LaneSpreadFunction lsf = nb.getTypeCont().getEdgeTypeSpreadType(type);
81
if (isRailway(permissions) && nb.getTypeCont().getEdgeTypeIsOneWay(type)) {
82
lsf = LaneSpreadFunction::CENTER;
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
/****************************************************************************/
105
106