SUMO - Simulation of Urban MObility
RORoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A complete router's route
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2002-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <iostream>
35 #include <utils/common/Named.h>
37 #include <utils/common/StdDefs.h>
38 #include "ROEdge.h"
39 #include "RORoute.h"
40 #include "ROHelper.h"
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 RORoute::RORoute(const std::string& id, double costs, double prop,
48  const ConstROEdgeVector& route,
49  const RGBColor* const color,
50  const std::vector<SUMOVehicleParameter::Stop>& stops)
51  : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
52  myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
53 
54 RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
55  : Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
56  myProbability(0.0), myRoute(route), myColor(0), myStops() {}
57 
59  : Named(src.myID), myCosts(src.myCosts),
61  if (src.myColor != 0) {
62  myColor = new RGBColor(*src.myColor);
63  }
64 }
65 
66 
68  delete myColor;
69 }
70 
71 
72 void
73 RORoute::setCosts(double costs) {
74  myCosts = costs;
75 }
76 
77 
78 void
80  myProbability = prob;
81 }
82 
83 
84 void
87 }
88 
89 void
91  myProbability += prob;
92 }
93 
94 
97  const bool withCosts,
98  const bool withExitTimes) const {
100  if (withCosts) {
102  dev.setPrecision(8);
104  dev.setPrecision();
105  }
106  if (myColor != 0) {
108  }
109  if (!myRoute.empty()) {
110  const int frontOffset = myRoute.front()->getFunc() == ROEdge::ET_DISTRICT ? 1 : 0;
111  const int backOffset = myRoute.back()->getFunc() == ROEdge::ET_DISTRICT ? 1 : 0;
112  if (frontOffset + backOffset > 0) {
113  ConstROEdgeVector temp(myRoute.begin() + frontOffset, myRoute.end() - backOffset);
114  dev.writeAttr(SUMO_ATTR_EDGES, temp);
115  } else {
117  }
118  } else {
120  }
121  if (withExitTimes) {
122  std::string exitTimes;
123  double time = STEPS2TIME(veh->getDepartureTime());
124  for (ConstROEdgeVector::const_iterator i = myRoute.begin(); i != myRoute.end(); ++i) {
125  if (i != myRoute.begin()) {
126  exitTimes += " ";
127  }
128  time += (*i)->getTravelTime(veh, time);
129  exitTimes += toString(time);
130  }
131  dev.writeAttr("exitTimes", exitTimes);
132  }
133  dev.closeTag();
134  return dev;
135 }
136 
137 
138 /****************************************************************************/
void setProbability(double prob)
Sets the probability of the route.
Definition: RORoute.cpp:79
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
Some static methods for string processing.
Definition: StringUtils.h:45
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:44
void recheckForLoops()
Checks whether this route contains loops and removes such.
Definition: RORoute.cpp:85
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:60
std::vector< SUMOVehicleParameter::Stop > myStops
List of the stops on the parsed route.
Definition: RORoute.h:219
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:216
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
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:47
double myProbability
The probability the driver will take this route with.
Definition: RORoute.h:210
double myCosts
The costs of the route.
Definition: RORoute.h:207
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at, 0 for triggered vehicles.
Definition: ROVehicle.h:111
Base class for objects which have an id.
Definition: Named.h:46
std::string myID
The name of the object.
Definition: Named.h:136
void setCosts(double costs)
Sets the costs of the route.
Definition: RORoute.cpp:73
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
void addProbability(double prob)
add additional vehicles/probability
Definition: RORoute.cpp:90
An edge representing a whole district.
Definition: ROEdge.h:87
A color information.
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:96
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router&#39;s route.
Definition: RORoute.h:62
~RORoute()
Destructor.
Definition: RORoute.cpp:67
ConstROEdgeVector myRoute
The edges the route consists of.
Definition: RORoute.h:213