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-sim.org/
12 // Copyright (C) 2002-2014 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 std::vector<const ROEdge*>& 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 
60  : Named(src.myID), myCosts(src.myCosts),
61  myProbability(src.myProbability), myRoute(src.myRoute), myColor(0) {
62  if (src.myColor != 0) {
63  myColor = new RGBColor(*src.myColor);
64  }
65 }
66 
67 
69  delete myColor;
70 }
71 
72 
73 void
75  myCosts = costs;
76 }
77 
78 
79 void
81  myProbability = prob;
82 }
83 
84 
85 void
88 }
89 
90 void
92  myProbability += prob;
93 }
94 
95 
98  const bool withCosts,
99  const bool withExitTimes) const {
100  dev.openTag(SUMO_TAG_ROUTE);
101  if (withCosts) {
103  dev.setPrecision(8);
105  dev.setPrecision();
106  }
107  if (myColor != 0) {
109  }
110  if (!myRoute.empty() && myRoute.front()->getType() == ROEdge::ET_DISTRICT) {
111  std::vector<const ROEdge*> temp(myRoute.begin() + 1, myRoute.end() - 1);
112  dev.writeAttr(SUMO_ATTR_EDGES, temp);
113  } else {
115  }
116  if (withExitTimes) {
117  std::string exitTimes;
118  SUMOReal time = STEPS2TIME(veh->getDepartureTime());
119  for (std::vector<const ROEdge*>::const_iterator i = myRoute.begin(); i != myRoute.end(); ++i) {
120  if (i != myRoute.begin()) {
121  exitTimes += " ";
122  }
123  time += (*i)->getTravelTime(veh, time);
124  exitTimes += toString(time);
125  }
126  dev.writeAttr("exitTimes", exitTimes);
127  }
128  dev.closeTag();
129  return dev;
130 }
131 
132 
133 /****************************************************************************/
SUMOTime getDepartureTime() const
Returns the time the vehicle starts at.
Definition: ROVehicle.h:111
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, const bool withCosts, const bool withExitTimes) const
Definition: RORoute.cpp:97
Some static methods for string processing.
Definition: StringUtils.h:45
void setProbability(SUMOReal prob)
Sets the probability of the route.
Definition: RORoute.cpp:80
void recheckForLoops()
Checks whether this route contains loops and removes such.
Definition: RORoute.cpp:86
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:91
RORoute(const std::string &id, SUMOReal costs, SUMOReal prob, const std::vector< const ROEdge * > &route, const RGBColor *const color, const std::vector< SUMOVehicleParameter::Stop > &stops)
Constructor.
Definition: RORoute.cpp:51
A vehicle as used by router.
Definition: ROVehicle.h:59
the edges of a route
SUMOReal myCosts
The costs of the route.
Definition: RORoute.h:189
const RGBColor * myColor
The color of the route.
Definition: RORoute.h:198
std::vector< const ROEdge * > myRoute
The edges the route consists of.
Definition: RORoute.h:195
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void setCosts(SUMOReal costs)
Sets the costs of the route.
Definition: RORoute.cpp:74
SUMOReal myProbability
The probability the driver will take this route with.
Definition: RORoute.h:192
An edge representing a whole district.
Definition: ROEdge.h:79
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
Base class for objects which have an id.
Definition: Named.h:45
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:215
A color information.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
A complete router's route.
Definition: RORoute.h:61
~RORoute()
Destructor.
Definition: RORoute.cpp:68
void recheckForLoops(std::vector< const ROEdge * > &edges)
Checks whether the given edge list contains loops and removes them.
Definition: ROHelper.cpp:44