Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/router/RORoute.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2002-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 RORoute.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Michael Behrisch
17
/// @author Yun-Pang Floetteroed
18
/// @date Sept 2002
19
///
20
// A complete router's route
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <string>
25
#include <iostream>
26
#include <utils/common/Named.h>
27
#include <utils/common/StringUtils.h>
28
#include <utils/common/StdDefs.h>
29
#include "ROEdge.h"
30
#include "RORoute.h"
31
#include "ROHelper.h"
32
#include <utils/iodevices/OutputDevice.h>
33
34
35
// ===========================================================================
36
// method definitions
37
// ===========================================================================
38
RORoute::RORoute(const std::string& id, double costs, double prop,
39
const ConstROEdgeVector& route,
40
const RGBColor* const color,
41
const StopParVector& stops)
42
: Named(StringUtils::convertUmlaute(id)), myCosts(costs),
43
myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
44
45
RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
46
: Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
47
myProbability(0.0), myRoute(route), myColor(nullptr), myStops() {}
48
49
RORoute::RORoute(const RORoute& src)
50
: Named(src.myID), myCosts(src.myCosts),
51
myProbability(src.myProbability), myRoute(src.myRoute), myColor(nullptr) {
52
if (src.myColor != nullptr) {
53
myColor = new RGBColor(*src.myColor);
54
}
55
}
56
57
58
RORoute::~RORoute() {
59
delete myColor;
60
}
61
62
63
void
64
RORoute::setCosts(double costs) {
65
myCosts = costs;
66
}
67
68
69
void
70
RORoute::setProbability(double prob) {
71
myProbability = prob;
72
}
73
74
75
void
76
RORoute::recheckForLoops(const ConstROEdgeVector& mandatory) {
77
ROHelper::recheckForLoops(myRoute, mandatory);
78
}
79
80
bool
81
RORoute::isValid(const ROVehicle& veh, bool ignoreErrors) const {
82
MsgHandler* mh = ignoreErrors ? MsgHandler::getWarningInstance() : MsgHandler::getErrorInstance();
83
for (ConstROEdgeVector::const_iterator i = myRoute.begin() + 1; i != myRoute.end(); ++i) {
84
const ROEdge* prev = *(i - 1);
85
const ROEdge* cur = *i;
86
if (!prev->isConnectedTo(*cur, veh.getVClass())) {
87
mh->informf("Edge '%' not connected to edge '%' for vehicle '%'.", prev->getID(), cur->getID(), veh.getID());
88
return ignoreErrors;
89
}
90
}
91
return true;
92
}
93
94
95
void
96
RORoute::addProbability(double prob) {
97
myProbability += prob;
98
}
99
100
101
ConstROEdgeVector
102
RORoute::getNormalEdges() const {
103
ConstROEdgeVector tempRoute;
104
for (const ROEdge* roe : myRoute) {
105
if (!roe->isInternal() && !roe->isTazConnector()) {
106
tempRoute.push_back(roe);
107
}
108
}
109
return tempRoute;
110
}
111
112
113
OutputDevice&
114
RORoute::writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
115
const bool withCosts,
116
const bool asAlternatives,
117
const bool withExitTimes,
118
const bool withLength,
119
const std::string& id) const {
120
dev.openTag(SUMO_TAG_ROUTE);
121
if (id != "") {
122
dev.writeAttr(SUMO_ATTR_ID, id);
123
}
124
if (withCosts) {
125
dev.writeAttr(SUMO_ATTR_COST, myCosts);
126
}
127
if (asAlternatives) {
128
dev.setPrecision(8);
129
dev.writeAttr(SUMO_ATTR_PROB, myProbability);
130
dev.setPrecision();
131
}
132
if (myColor != nullptr) {
133
dev.writeAttr(SUMO_ATTR_COLOR, *myColor);
134
}
135
dev.writeAttr(SUMO_ATTR_EDGES, getNormalEdges());
136
if (withExitTimes) {
137
std::vector<double> exitTimes;
138
double time = STEPS2TIME(veh->getDepartureTime());
139
for (const ROEdge* const roe : myRoute) {
140
time += roe->getTravelTime(veh, time);
141
if (!roe->isInternal() && !roe->isTazConnector()) {
142
exitTimes.push_back(time);
143
}
144
}
145
dev.writeAttr("exitTimes", exitTimes);
146
}
147
if (withLength) {
148
double length = 0.;
149
for (const ROEdge* const roe : myRoute) {
150
length += roe->getLength();
151
}
152
dev.writeAttr("routeLength", length);
153
}
154
dev.closeTag();
155
return dev;
156
}
157
158
159
/****************************************************************************/
160
161