SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RORoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A complete router's route
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
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 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 RORoute::RORoute(const std::string& id, SUMOReal costs, SUMOReal prop,
51  const std::vector<const ROEdge*>& route,
52  const RGBColor* const color)
53  : Named(StringUtils::convertUmlaute(id)), myCosts(costs),
54  myProbability(prop), myRoute(route), myColor(color) {}
55 
56 
58  : Named(src.myID), myCosts(src.myCosts),
59  myProbability(src.myProbability), myRoute(src.myRoute), myColor(0) {
60  if (src.myColor != 0) {
61  myColor = new RGBColor(*src.myColor);
62  }
63 }
64 
65 
67  delete myColor;
68 }
69 
70 
71 void
73  myRoute.push_back(edge);
74 }
75 
76 
77 void
79  myCosts = costs;
80 }
81 
82 
83 void
85  myProbability = prob;
86 }
87 
88 
89 void
92 }
93 
94 void
96  myProbability += prob;
97 }
98 
99 
102  const bool withCosts,
103  const bool withExitTimes) const {
104  dev.openTag(SUMO_TAG_ROUTE);
105  if (withCosts) {
107  dev.setPrecision(8);
109  dev.setPrecision();
110  }
111  if (myColor != 0) {
113  }
114  if (!myRoute.empty() && myRoute.front()->getType() == ROEdge::ET_DISTRICT) {
115  std::vector<const ROEdge*> temp(myRoute.begin() + 1, myRoute.end() - 1);
116  dev.writeAttr(SUMO_ATTR_EDGES, temp);
117  } else {
119  }
120  if (withExitTimes) {
121  std::string exitTimes;
122  SUMOReal time = STEPS2TIME(veh->getDepartureTime());
123  for (std::vector<const ROEdge*>::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 /****************************************************************************/
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at.
Definition: ROVehicle.h:108
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:101
void add(ROEdge *edge)
Adds an edge to the end of the route.
Definition: RORoute.cpp:72
Some static methods for string processing.
Definition: StringUtils.h:45
void setProbability(SUMOReal prob)
Sets the probability of the route.
Definition: RORoute.cpp:84
void recheckForLoops()
Checks whether this route contains loops and removes such.
Definition: RORoute.cpp:90
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
void addProbability(SUMOReal prob)
add additional vehicles/probability
Definition: RORoute.cpp:95
A vehicle as used by router.
Definition: ROVehicle.h:57
the edges of a route
SUMOReal myCosts
The costs of the route.
Definition: RORoute.h:185
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:194
std::vector< const ROEdge * > myRoute
The edges the route consists of.
Definition: RORoute.h:191
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void setCosts(SUMOReal costs)
Sets the costs of the route.
Definition: RORoute.cpp:78
SUMOReal myProbability
The probability the driver will take this route with.
Definition: RORoute.h:188
An edge representing a whole district.
Definition: ROEdge.h:77
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
A basic edge for routing applications.
Definition: ROEdge.h:67
Base class for objects which have an id.
Definition: Named.h:45
RORoute(const std::string &id, SUMOReal costs, SUMOReal prob, const std::vector< const ROEdge * > &route, const RGBColor *const color)
Constructor.
Definition: RORoute.cpp:50
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:221
A color information.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router&#39;s route.
Definition: RORoute.h:58
~RORoute()
Destructor.
Definition: RORoute.cpp:66
void recheckForLoops(std::vector< const ROEdge * > &edges)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:44