SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ROVehicle.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A vehicle as used by router
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 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 
34 #include <utils/common/ToString.h>
39 #include <string>
40 #include <iostream>
41 #include "RORouteDef.h"
42 #include "ROVehicle.h"
43 #include "RORoute.h"
44 #include "ROHelper.h"
45 #include "RONet.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  RORouteDef* route, const SUMOVTypeParameter* type, const RONet* net)
57  : myParameter(pars), myType(type), myRoute(route) {
58  myParameter.stops.clear();
59  if (route != 0) {
60  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = route->getFirstRoute()->getStops().begin(); s != route->getFirstRoute()->getStops().end(); ++s) {
61  addStop(*s, net);
62  }
63  }
64  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = pars.stops.begin(); s != pars.stops.end(); ++s) {
65  addStop(*s, net);
66  }
67 }
68 
69 
70 void
72  const ROEdge* stopEdge = net->getEdge(stopPar.lane.substr(0, stopPar.lane.rfind("_")));
73  if (stopEdge == 0) {
74  // warn here?
75  return;
76  }
77  // where to insert the stop
78  std::vector<SUMOVehicleParameter::Stop>::iterator iter = myParameter.stops.begin();
79  std::vector<const ROEdge*>::iterator edgeIter = myStopEdges.begin();
80  if (stopPar.index == STOP_INDEX_END || stopPar.index >= static_cast<int>(myParameter.stops.size())) {
81  if (myParameter.stops.size() > 0) {
82  iter = myParameter.stops.end();
83  edgeIter = myStopEdges.end();
84  }
85  } else {
86  if (stopPar.index == STOP_INDEX_FIT) {
87  const std::vector<const ROEdge*> edges = myRoute->getFirstRoute()->getEdgeVector();
88  std::vector<const ROEdge*>::const_iterator stopEdgeIt = std::find(edges.begin(), edges.end(), stopEdge);
89  if (stopEdgeIt == edges.end()) {
90  iter = myParameter.stops.end();
91  edgeIter = myStopEdges.end();
92  } else {
93  while (iter != myParameter.stops.end()) {
94  if (edgeIter > stopEdgeIt || (edgeIter == stopEdgeIt && iter->endPos >= stopPar.endPos)) {
95  break;
96  }
97  ++iter;
98  ++edgeIter;
99  }
100  }
101  } else {
102  iter += stopPar.index;
103  edgeIter += stopPar.index;
104  }
105  }
106  myParameter.stops.insert(iter, stopPar);
107  myStopEdges.insert(edgeIter, stopEdge);
108 }
109 
110 
112 
113 
114 void
116  OutputDevice* const typeos, bool withExitTimes) const {
117  // check whether the vehicle's type was saved before
118  if (myType != 0 && !myType->saved) {
119  // ... save if not
120  if (typeos != 0) {
121  myType->write(*typeos);
122  } else {
123  myType->write(os);
124  if (altos != 0) {
125  myType->write(*altos);
126  }
127  }
128  myType->saved = true;
129  }
130 
131  // write the vehicle (new style, with included routes)
133  if (altos != 0) {
135  }
136 
137  // check whether the route shall be saved
138  if (!myRoute->isSaved()) {
139  myRoute->writeXMLDefinition(os, this, false, withExitTimes);
140  if (altos != 0) {
141  myRoute->writeXMLDefinition(*altos, this, true, withExitTimes);
142  }
143  }
145  if (altos != 0) {
146  myParameter.writeStops(*altos);
147  }
148  os.closeTag();
149  if (altos != 0) {
150  altos->closeTag();
151  }
152 }
153 
154 
155 SUMOReal
157  return myType->maxSpeed;
158 }
159 
160 
161 /****************************************************************************/
162