Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RORoute.cpp
Go to the documentation of this file.
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/****************************************************************************/
20// A complete router's route
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include <iostream>
26#include <utils/common/Named.h>
29#include "ROEdge.h"
30#include "RORoute.h"
31#include "ROHelper.h"
33
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38RORoute::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
45RORoute::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
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
59 delete myColor;
60}
61
62
63void
64RORoute::setCosts(double costs) {
65 myCosts = costs;
66}
67
68
69void
71 myProbability = prob;
72}
73
74
75void
79
80bool
81RORoute::isValid(const ROVehicle& veh, bool ignoreErrors, MsgHandler* mh) const {
82 if (mh == nullptr) {
84 }
85 for (ConstROEdgeVector::const_iterator i = myRoute.begin() + 1; i != myRoute.end(); ++i) {
86 const ROEdge* prev = *(i - 1);
87 const ROEdge* cur = *i;
88 if (!prev->isConnectedTo(*cur, veh.getVClass())) {
89 mh->informf("Edge '%' not connected to edge '%' for vehicle '%'.", prev->getID(), cur->getID(), veh.getID());
90 return ignoreErrors;
91 }
92 }
93 return true;
94}
95
96
97bool
99 const bool hasRestrictions = RONet::getInstance()->hasRestrictions();
100 const bool hasPermissions = RONet::getInstance()->hasPermissions();
101 if (hasRestrictions || hasPermissions) {
102 for (const ROEdge* e: myRoute) {
103 if ((hasPermissions && e->prohibits(veh)) || (hasRestrictions && e->restricts(veh))) {
104 mh->informf("Vehicle '%' is not permitted on Edge '%'", veh->getID(), e->getID());
105 return false;
106 }
107 }
108 }
109 return true;
110}
111
112
113void
115 myProbability += prob;
116}
117
118
121 ConstROEdgeVector tempRoute;
122 for (const ROEdge* roe : myRoute) {
123 if (!roe->isInternal() && !roe->isTazConnector()) {
124 tempRoute.push_back(roe);
125 }
126 }
127 return tempRoute;
128}
129
130
133 const bool withCosts,
134 const bool asAlternatives,
135 const bool withExitTimes,
136 const bool withLength,
137 const std::string& id) const {
139 if (id != "") {
140 dev.writeAttr(SUMO_ATTR_ID, id);
141 }
142 if (withCosts) {
144 }
145 if (asAlternatives) {
146 dev.setPrecision(8);
148 dev.setPrecision();
149 }
150 if (myColor != nullptr) {
152 }
154 if (withExitTimes) {
155 std::vector<double> exitTimes;
156 double time = STEPS2TIME(veh->getDepartureTime());
157 for (const ROEdge* const roe : myRoute) {
158 time += roe->getTravelTime(veh, time);
159 if (!roe->isInternal() && !roe->isTazConnector()) {
160 exitTimes.push_back(time);
161 }
162 }
163 dev.writeAttr("exitTimes", exitTimes);
164 }
165 if (withLength) {
166 double length = 0.;
167 for (const ROEdge* const roe : myRoute) {
168 length += roe->getLength();
169 }
170 dev.writeAttr("routeLength", length);
171 }
172 dev.closeTag();
173 return dev;
174}
175
176
177/****************************************************************************/
std::vector< const ROEdge * > ConstROEdgeVector
Definition ROEdge.h:57
std::vector< const ROEdge * > ConstROEdgeVector
Definition RORoute.h:40
#define STEPS2TIME(x)
Definition SUMOTime.h:55
std::vector< SUMOVehicleParameter::Stop > StopParVector
@ SUMO_TAG_ROUTE
description of a route
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_COST
@ SUMO_ATTR_PROB
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
void informf(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
Definition MsgHandler.h:116
Base class for objects which have an id.
Definition Named.h:54
const std::string & getID() const
Returns the id.
Definition Named.h:74
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
A basic edge for routing applications.
Definition ROEdge.h:73
bool isConnectedTo(const ROEdge &e, const SUMOVehicleClass vClass, bool ignoreTransientPermissions=false) const
returns the information whether this edge is directly connected to the given
Definition ROEdge.cpp:462
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
Definition RONet.cpp:56
bool hasPermissions() const
Definition RONet.cpp:931
bool hasRestrictions() const
Definition RONet.h:97
SUMOVehicleClass getVClass() const
Definition RORoutable.h:117
const std::string & getID() const
Returns the id of the routable.
Definition RORoutable.h:95
A complete router's route.
Definition RORoute.h:52
RORoute(const std::string &id, double costs, double prob, const ConstROEdgeVector &route, const RGBColor *const color, const StopParVector &stops)
Constructor.
Definition RORoute.cpp:38
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool asAlternatives, const bool withExitTimes, const bool withLength, const std::string &id="") const
Definition RORoute.cpp:132
bool isValid(const ROVehicle &veh, bool ignoreErrors, MsgHandler *mh=nullptr) const
check whether the route is connected for the given vehicle
Definition RORoute.cpp:81
ConstROEdgeVector myRoute
The edges the route consists of.
Definition RORoute.h:215
double myCosts
The costs of the route.
Definition RORoute.h:209
void setProbability(double prob)
Sets the probability of the route.
Definition RORoute.cpp:70
double myProbability
The probability the driver will take this route with.
Definition RORoute.h:212
bool isPermitted(const ROVehicle *veh, MsgHandler *mh) const
check whether the route is permitted for the given vehicle
Definition RORoute.cpp:98
void addProbability(double prob)
add additional vehicles/probability
Definition RORoute.cpp:114
const RGBColor * myColor
The color of the route.
Definition RORoute.h:218
~RORoute()
Destructor.
Definition RORoute.cpp:58
ConstROEdgeVector getNormalEdges() const
return edges that shall be written in the route definition
Definition RORoute.cpp:120
void recheckForLoops(const ConstROEdgeVector &mandatory)
Checks whether this route contains loops and removes such.
Definition RORoute.cpp:76
void setCosts(double costs)
Sets the costs of the route.
Definition RORoute.cpp:64
A vehicle as used by router.
Definition ROVehicle.h:50
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Definition ROVehicle.h:92
Some static methods for string processing.
Definition StringUtils.h:40
void recheckForLoops(ConstROEdgeVector &edges, const ConstROEdgeVector &mandatory)
Checks whether the given edge list contains loops and removes them.
Definition ROHelper.cpp:37