Eclipse SUMO - Simulation of Urban MObility
RORoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2020 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>
28 #include <utils/common/StdDefs.h>
29 #include "ROEdge.h"
30 #include "RORoute.h"
31 #include "ROHelper.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 std::vector<SUMOVehicleParameter::Stop>& 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 
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 
63 void
64 RORoute::setCosts(double costs) {
65  myCosts = costs;
66 }
67 
68 
69 void
71  myProbability = prob;
72 }
73 
74 
75 void
78 }
79 
80 void
82  myProbability += prob;
83 }
84 
85 
88  const bool withCosts,
89  const bool withExitTimes) const {
91  if (withCosts) {
93  dev.setPrecision(8);
95  dev.setPrecision();
96  }
97  if (myColor != nullptr) {
99  }
100  ConstROEdgeVector tempRoute;
101  for (const ROEdge* roe : myRoute) {
102  if (!roe->isInternal() && !roe->isTazConnector()) {
103  tempRoute.push_back(roe);
104  }
105  }
106  dev.writeAttr(SUMO_ATTR_EDGES, tempRoute);
107  if (withExitTimes) {
108  std::vector<double> exitTimes;
109  double time = STEPS2TIME(veh->getDepartureTime());
110  for (const ROEdge* roe : myRoute) {
111  time += roe->getTravelTime(veh, time);
112  if (!roe->isInternal() && !roe->isTazConnector()) {
113  exitTimes.push_back(time);
114  }
115  }
116  dev.writeAttr("exitTimes", exitTimes);
117  }
118  dev.closeTag();
119  return dev;
120 }
121 
122 
123 /****************************************************************************/
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:54
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_COST
@ SUMO_ATTR_PROB
@ SUMO_ATTR_COLOR
A color information.
Base class for objects which have an id.
Definition: Named.h:53
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
A basic edge for routing applications.
Definition: ROEdge.h:70
A complete router's route.
Definition: RORoute.h:52
ConstROEdgeVector myRoute
The edges the route consists of.
Definition: RORoute.h:203
double myCosts
The costs of the route.
Definition: RORoute.h:197
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:200
RORoute(const std::string &id, double costs, double prob, const ConstROEdgeVector &route, const RGBColor *const color, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
Definition: RORoute.cpp:38
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:81
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:206
~RORoute()
Destructor.
Definition: RORoute.cpp:58
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
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:87
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:36
void recheckForLoops(ConstROEdgeVector &edges, const ConstROEdgeVector &mandatory)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:37