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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A complete router's route
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <iostream>
34 #include <utils/common/Named.h>
36 #include <utils/common/StdDefs.h>
37 #include "ROEdge.h"
38 #include "RORoute.h"
39 #include "ROHelper.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 RORoute::RORoute(const std::string& id, double costs, double prop,
47  const ConstROEdgeVector& route,
48  const RGBColor* const color,
49  const std::vector<SUMOVehicleParameter::Stop>& stops)
50  : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
51  myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
52 
53 RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
54  : Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
55  myProbability(0.0), myRoute(route), myColor(0), myStops() {}
56 
58  : Named(src.myID), myCosts(src.myCosts),
60  if (src.myColor != 0) {
61  myColor = new RGBColor(*src.myColor);
62  }
63 }
64 
65 
67  delete myColor;
68 }
69 
70 
71 void
72 RORoute::setCosts(double costs) {
73  myCosts = costs;
74 }
75 
76 
77 void
79  myProbability = prob;
80 }
81 
82 
83 void
86 }
87 
88 void
90  myProbability += prob;
91 }
92 
93 
96  const bool withCosts,
97  const bool withExitTimes) const {
99  if (withCosts) {
101  dev.setPrecision(8);
103  dev.setPrecision();
104  }
105  if (myColor != 0) {
107  }
108  if (!myRoute.empty()) {
109  const int frontOffset = myRoute.front()->isTazConnector() ? 1 : 0;
110  const int backOffset = myRoute.back()->isTazConnector() ? 1 : 0;
111  if (frontOffset + backOffset > 0) {
112  ConstROEdgeVector temp(myRoute.begin() + frontOffset, myRoute.end() - backOffset);
113  dev.writeAttr(SUMO_ATTR_EDGES, temp);
114  } else {
116  }
117  } else {
119  }
120  if (withExitTimes) {
121  std::string exitTimes;
122  double time = STEPS2TIME(veh->getDepartureTime());
123  for (ConstROEdgeVector::const_iterator i = myRoute.begin(); i != myRoute.end(); ++i) {
124  if (i != myRoute.begin()) {
125  exitTimes += " ";
126  }
127  time += (*i)->getTravelTime(veh, time);
128  exitTimes += toString(time);
129  }
130  dev.writeAttr("exitTimes", exitTimes);
131  }
132  dev.closeTag();
133  return dev;
134 }
135 
136 
137 /****************************************************************************/
void setProbability(double prob)
Sets the probability of the route.
Definition: RORoute.cpp:78
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:260
Some static methods for string processing.
Definition: StringUtils.h:44
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
void recheckForLoops(ConstROEdgeVector &edges)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:43
void recheckForLoops()
Checks whether this route contains loops and removes such.
Definition: RORoute.cpp:84
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
begin/end of the description of a route
A vehicle as used by router.
Definition: ROVehicle.h:59
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: RORoute.h:218
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:215
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
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:46
double myProbability
The probability the driver will take this route with.
Definition: RORoute.h:209
double myCosts
The costs of the route.
Definition: RORoute.h:206
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Definition: ROVehicle.h:101
Base class for objects which have an id.
Definition: Named.h:54
std::string myID
The name of the object.
Definition: Named.h:126
void setCosts(double costs)
Sets the costs of the route.
Definition: RORoute.cpp:72
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:89
A color information.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:95
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router&#39;s route.
Definition: RORoute.h:61
~RORoute()
Destructor.
Definition: RORoute.cpp:66
ConstROEdgeVector myRoute
The edges the route consists of.
Definition: RORoute.h:212