SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RORouteDef_Complete.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A complete route definition (with all passed edges being known)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2012 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 <deque>
35 #include <iterator>
36 #include "ROEdge.h"
37 #include "RORouteDef.h"
38 #include "RORoute.h"
42 #include "RORouteDef_Complete.h"
43 #include "ROHelper.h"
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56  const RGBColor* const color,
57  const std::vector<const ROEdge*> &edges,
58  bool tryRepair)
59  : RORouteDef(id, color), myEdges(edges), myTryRepair(tryRepair) {
60 }
61 
62 
64 
65 
66 void
68  SUMOTime begin, const ROVehicle& veh) const {
69  if (myTryRepair) {
70  const std::vector<const ROEdge*> &oldEdges = myEdges;
71  if (oldEdges.size() == 0) {
73  m->inform("Could not repair empty route of vehicle '" + veh.getID() + "'.");
74  myPrecomputed = new RORoute(myID, 0, 1, std::vector<const ROEdge*>(), copyColorIfGiven());
75  return;
76  }
77  std::vector<const ROEdge*> newEdges;
78  newEdges.push_back(*(oldEdges.begin()));
79  for (std::vector<const ROEdge*>::const_iterator i = oldEdges.begin() + 1; i != oldEdges.end(); ++i) {
80  if ((*(i - 1))->isConnectedTo(*i)) {
81  newEdges.push_back(*i);
82  } else {
83  std::vector<const ROEdge*> edges;
84  router.compute(*(i - 1), *i, &veh, begin, edges);
85  if (edges.size() == 0) {
86  return;
87  }
88  std::copy(edges.begin() + 1, edges.end(), back_inserter(newEdges));
89  }
90  }
91  if (myEdges != newEdges) {
92  WRITE_WARNING("Repaired route of vehicle '" + veh.getID() + "'.");
93  }
94  myEdges = newEdges;
95  }
96  SUMOReal costs = router.recomputeCosts(myEdges, &veh, begin);
97  if (costs < 0) {
98  throw ProcessError("Route '" + getID() + "' (vehicle '" + veh.getID() + "') is not valid.");
99  }
101 }
102 
103 
104 void
106  const ROVehicle* const, RORoute* current, SUMOTime begin) {
107  myStartTime = begin;
108  myEdges = current->getEdgeVector();
109  delete current;
110 }
111 
112 
113 RORouteDef*
114 RORouteDef_Complete::copy(const std::string& id) const {
116 }
117 
118 
121  OutputDevice& dev, const ROVehicle* const veh,
122  bool asAlternatives, bool withExitTimes) const {
123  // (optional) alternatives header
124  if (asAlternatives) {
126  }
127  // the route
128  dev.openTag(SUMO_TAG_ROUTE);
129  if (asAlternatives) {
131  dev.writeAttr(SUMO_ATTR_PROB, 1.);
132  }
133  if (myColor != 0) {
135  }
137  if (withExitTimes) {
138  std::string exitTimes;
139  SUMOReal time = STEPS2TIME(veh->getDepartureTime());
140  for (std::vector<const ROEdge*>::const_iterator i = myEdges.begin(); i != myEdges.end(); ++i) {
141  if (i != myEdges.begin()) {
142  exitTimes += " ";
143  }
144  time += (*i)->getTravelTime(veh, time);
145  exitTimes += toString(time);
146  }
147  dev.writeAttr("exitTimes", exitTimes);
148  }
149  dev.closeTag(true);
150  // (optional) alternatives end
151  if (asAlternatives) {
152  dev.closeTag();
153  }
154  return dev;
155 }
156 
157 
158 const ROEdge*
160  return myEdges.back();
161 }
162 
163 
164 /****************************************************************************/
165