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 /****************************************************************************/
17 // A complete router's route
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <iostream>
28 #include <utils/common/Named.h>
30 #include <utils/common/StdDefs.h>
31 #include "ROEdge.h"
32 #include "RORoute.h"
33 #include "ROHelper.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 RORoute::RORoute(const std::string& id, double costs, double prop,
41  const ConstROEdgeVector& route,
42  const RGBColor* const color,
43  const std::vector<SUMOVehicleParameter::Stop>& stops)
44  : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
45  myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
46 
47 RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
48  : Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
49  myProbability(0.0), myRoute(route), myColor(nullptr), myStops() {}
50 
52  : Named(src.myID), myCosts(src.myCosts),
53  myProbability(src.myProbability), myRoute(src.myRoute), myColor(nullptr) {
54  if (src.myColor != nullptr) {
55  myColor = new RGBColor(*src.myColor);
56  }
57 }
58 
59 
61  delete myColor;
62 }
63 
64 
65 void
66 RORoute::setCosts(double costs) {
67  myCosts = costs;
68 }
69 
70 
71 void
73  myProbability = prob;
74 }
75 
76 
77 void
80 }
81 
82 void
84  myProbability += prob;
85 }
86 
87 
90  const bool withCosts,
91  const bool withExitTimes) const {
93  if (withCosts) {
95  dev.setPrecision(8);
97  dev.setPrecision();
98  }
99  if (myColor != nullptr) {
101  }
102  ConstROEdgeVector tempRoute;
103  for (const ROEdge* roe : myRoute) {
104  if (!roe->isInternal() && !roe->isTazConnector()) {
105  tempRoute.push_back(roe);
106  }
107  }
108  dev.writeAttr(SUMO_ATTR_EDGES, tempRoute);
109  if (withExitTimes) {
110  std::vector<double> exitTimes;
111  double time = STEPS2TIME(veh->getDepartureTime());
112  for (const ROEdge* roe : myRoute) {
113  time += roe->getTravelTime(veh, time);
114  if (!roe->isInternal() && !roe->isTazConnector()) {
115  exitTimes.push_back(time);
116  }
117  }
118  dev.writeAttr("exitTimes", exitTimes);
119  }
120  dev.closeTag();
121  return dev;
122 }
123 
124 
125 /****************************************************************************/
void setProbability(double prob)
Sets the probability of the route.
Definition: RORoute.cpp:72
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
void recheckForLoops(ConstROEdgeVector &edges, const ConstROEdgeVector &mandatory)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:38
Some static methods for string processing.
Definition: StringUtils.h:39
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:57
begin/end of the description of a route
A vehicle as used by router.
Definition: ROVehicle.h:53
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: RORoute.h:212
the edges of a route
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:209
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
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:40
double myProbability
The probability the driver will take this route with.
Definition: RORoute.h:203
double myCosts
The costs of the route.
Definition: RORoute.h:200
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Definition: ROVehicle.h:95
A basic edge for routing applications.
Definition: ROEdge.h:73
Base class for objects which have an id.
Definition: Named.h:57
std::string myID
The name of the object.
Definition: Named.h:134
void setCosts(double costs)
Sets the costs of the route.
Definition: RORoute.cpp:66
void recheckForLoops(const ConstROEdgeVector &mandatory)
Checks whether this route contains loops and removes such.
Definition: RORoute.cpp:78
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:83
A color information.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:89
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router&#39;s route.
Definition: RORoute.h:55
~RORoute()
Destructor.
Definition: RORoute.cpp:60
ConstROEdgeVector myRoute
The edges the route consists of.
Definition: RORoute.h:206