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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A complete router's route
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <iostream>
27 #include <utils/common/Named.h>
29 #include <utils/common/StdDefs.h>
30 #include "ROEdge.h"
31 #include "RORoute.h"
32 #include "ROHelper.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 RORoute::RORoute(const std::string& id, double costs, double prop,
40  const ConstROEdgeVector& route,
41  const RGBColor* const color,
42  const std::vector<SUMOVehicleParameter::Stop>& stops)
43  : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
44  myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
45 
46 RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
47  : Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
48  myProbability(0.0), myRoute(route), myColor(nullptr), myStops() {}
49 
51  : Named(src.myID), myCosts(src.myCosts),
52  myProbability(src.myProbability), myRoute(src.myRoute), myColor(nullptr) {
53  if (src.myColor != nullptr) {
54  myColor = new RGBColor(*src.myColor);
55  }
56 }
57 
58 
60  delete myColor;
61 }
62 
63 
64 void
65 RORoute::setCosts(double costs) {
66  myCosts = costs;
67 }
68 
69 
70 void
72  myProbability = prob;
73 }
74 
75 
76 void
79 }
80 
81 void
83  myProbability += prob;
84 }
85 
86 
89  const bool withCosts,
90  const bool withExitTimes) const {
92  if (withCosts) {
94  dev.setPrecision(8);
96  dev.setPrecision();
97  }
98  if (myColor != nullptr) {
100  }
101  ConstROEdgeVector tempRoute;
102  for (const ROEdge* roe : myRoute) {
103  if (!roe->isInternal() && !roe->isTazConnector()) {
104  tempRoute.push_back(roe);
105  }
106  }
107  dev.writeAttr(SUMO_ATTR_EDGES, tempRoute);
108  if (withExitTimes) {
109  std::vector<double> exitTimes;
110  double time = STEPS2TIME(veh->getDepartureTime());
111  for (const ROEdge* roe : myRoute) {
112  time += roe->getTravelTime(veh, time);
113  if (!roe->isInternal() && !roe->isTazConnector()) {
114  exitTimes.push_back(time);
115  }
116  }
117  dev.writeAttr("exitTimes", exitTimes);
118  }
119  dev.closeTag();
120  return dev;
121 }
122 
123 
124 /****************************************************************************/
RORoute::myColor
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:208
Named
Base class for objects which have an id.
Definition: Named.h:56
ROVehicle::getDepartureTime
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Definition: ROVehicle.h:94
ROHelper.h
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
RORoute::RORoute
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:39
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
RORoute::myCosts
double myCosts
The costs of the route.
Definition: RORoute.h:199
SUMO_ATTR_COLOR
@ SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:704
RORoute::addProbability
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:82
RORoute::setCosts
void setCosts(double costs)
Sets the costs of the route.
Definition: RORoute.cpp:65
ROVehicle
A vehicle as used by router.
Definition: ROVehicle.h:52
SUMO_ATTR_COST
@ SUMO_ATTR_COST
Definition: SUMOXMLDefinitions.h:627
RORoute.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
RORoute::recheckForLoops
void recheckForLoops(const ConstROEdgeVector &mandatory)
Checks whether this route contains loops and removes such.
Definition: RORoute.cpp:77
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
RGBColor
Definition: RGBColor.h:39
SUMO_ATTR_PROB
@ SUMO_ATTR_PROB
Definition: SUMOXMLDefinitions.h:629
RORoute::~RORoute
~RORoute()
Destructor.
Definition: RORoute.cpp:59
RORoute::myRoute
ConstROEdgeVector myRoute
The edges the route consists of.
Definition: RORoute.h:205
Named.h
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
SUMO_ATTR_EDGES
@ SUMO_ATTR_EDGES
the edges of a route
Definition: SUMOXMLDefinitions.h:427
OutputDevice.h
RORoute
A complete router's route.
Definition: RORoute.h:54
RORoute::writeXMLDefinition
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:88
RORoute::setProbability
void setProbability(double prob)
Sets the probability of the route.
Definition: RORoute.cpp:71
StringUtils
Some static methods for string processing.
Definition: StringUtils.h:39
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
StringUtils.h
ROEdge
A basic edge for routing applications.
Definition: ROEdge.h:72
SUMO_TAG_ROUTE
@ SUMO_TAG_ROUTE
begin/end of the description of a route
Definition: SUMOXMLDefinitions.h:125
config.h
StdDefs.h
ROEdge.h
RORoute::myProbability
double myProbability
The probability the driver will take this route with.
Definition: RORoute.h:202
ConstROEdgeVector
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:56
ROHelper::recheckForLoops
void recheckForLoops(ConstROEdgeVector &edges, const ConstROEdgeVector &mandatory)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:37