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-2016 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 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 RORoute::RORoute(const std::string& id, SUMOReal costs, SUMOReal prop,
52  const ConstROEdgeVector& route,
53  const RGBColor* const color,
54  const std::vector<SUMOVehicleParameter::Stop>& stops)
55  : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
56  myProbability(prop), myRoute(route), myColor(color), myStops(stops) {}
57 
58 RORoute::RORoute(const std::string& id, const ConstROEdgeVector& route)
59  : Named(StringUtils::convertUmlaute(id)), myCosts(0.0),
60  myProbability(0.0), myRoute(route), myColor(0), myStops() {}
61 
63  : Named(src.myID), myCosts(src.myCosts),
65  if (src.myColor != 0) {
66  myColor = new RGBColor(*src.myColor);
67  }
68 }
69 
70 
72  delete myColor;
73 }
74 
75 
76 void
78  myCosts = costs;
79 }
80 
81 
82 void
84  myProbability = prob;
85 }
86 
87 
88 void
91 }
92 
93 void
95  myProbability += prob;
96 }
97 
98 
101  const bool withCosts,
102  const bool withExitTimes) const {
103  dev.openTag(SUMO_TAG_ROUTE);
104  if (withCosts) {
106  dev.setPrecision(8);
108  dev.setPrecision();
109  }
110  if (myColor != 0) {
112  }
113  if (!myRoute.empty()) {
114  const int frontOffset = myRoute.front()->getFunc() == ROEdge::ET_DISTRICT ? 1 : 0;
115  const int backOffset = myRoute.back()->getFunc() == ROEdge::ET_DISTRICT ? 1 : 0;
116  if (frontOffset + backOffset > 0) {
117  ConstROEdgeVector temp(myRoute.begin() + frontOffset, myRoute.end() - backOffset);
118  dev.writeAttr(SUMO_ATTR_EDGES, temp);
119  } else {
121  }
122  } else {
124  }
125  if (withExitTimes) {
126  std::string exitTimes;
127  SUMOReal time = STEPS2TIME(veh->getDepartureTime());
128  for (ConstROEdgeVector::const_iterator i = myRoute.begin(); i != myRoute.end(); ++i) {
129  if (i != myRoute.begin()) {
130  exitTimes += " ";
131  }
132  time += (*i)->getTravelTime(veh, time);
133  exitTimes += toString(time);
134  }
135  dev.writeAttr("exitTimes", exitTimes);
136  }
137  dev.closeTag();
138  return dev;
139 }
140 
141 
142 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
Some static methods for string processing.
Definition: StringUtils.h:45
void setPrecision(int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
void setProbability(SUMOReal prob)
Sets the probability of the route.
Definition: RORoute.cpp:83
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:89
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:62
void addProbability(SUMOReal prob)
add additional vehicles/probability
Definition: RORoute.cpp:94
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
SUMOReal myCosts
The costs of the route.
Definition: RORoute.h:207
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:216
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void setCosts(SUMOReal costs)
Sets the costs of the route.
Definition: RORoute.cpp:77
SUMOReal myProbability
The probability the driver will take this route with.
Definition: RORoute.h:210
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
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
RORoute(const std::string &id, SUMOReal costs, SUMOReal prob, const ConstROEdgeVector &route, const RGBColor *const color, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
Definition: RORoute.cpp:51
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:213
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:100
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:71
ConstROEdgeVector myRoute
The edges the route consists of.
Definition: RORoute.h:213