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 /****************************************************************************/
10 // A vehicle as used by router
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2002-2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
35 #include <utils/common/ToString.h>
40 #include <string>
41 #include <iostream>
42 #include "RORouteDef.h"
43 #include "ROVehicle.h"
44 #include "RORoute.h"
45 #include "ROHelper.h"
46 #include "RONet.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57  RORouteDef* route, const SUMOVTypeParameter* type, const RONet* net)
58  : myParameter(pars), myType(type), myRoute(route) {
59  myParameter.stops.clear();
60  if (route != 0) {
61  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = route->getFirstRoute()->getStops().begin(); s != route->getFirstRoute()->getStops().end(); ++s) {
62  addStop(*s, net);
63  }
64  }
65  for (std::vector<SUMOVehicleParameter::Stop>::const_iterator s = pars.stops.begin(); s != pars.stops.end(); ++s) {
66  addStop(*s, net);
67  }
68 }
69 
70 
71 void
73  const ROEdge* stopEdge = net->getEdge(stopPar.lane.substr(0, stopPar.lane.rfind("_")));
74  if (stopEdge == 0) {
75  // warn here?
76  return;
77  }
78  // where to insert the stop
79  std::vector<SUMOVehicleParameter::Stop>::iterator iter = myParameter.stops.begin();
80  std::vector<const ROEdge*>::iterator edgeIter = myStopEdges.begin();
81  if (stopPar.index == STOP_INDEX_END || stopPar.index >= static_cast<int>(myParameter.stops.size())) {
82  if (myParameter.stops.size() > 0) {
83  iter = myParameter.stops.end();
84  edgeIter = myStopEdges.end();
85  }
86  } else {
87  if (stopPar.index == STOP_INDEX_FIT) {
88  const std::vector<const ROEdge*> edges = myRoute->getFirstRoute()->getEdgeVector();
89  std::vector<const ROEdge*>::const_iterator stopEdgeIt = std::find(edges.begin(), edges.end(), stopEdge);
90  if (stopEdgeIt == edges.end()) {
91  iter = myParameter.stops.end();
92  edgeIter = myStopEdges.end();
93  } else {
94  while (iter != myParameter.stops.end()) {
95  if (edgeIter > stopEdgeIt || (edgeIter == stopEdgeIt && iter->endPos >= stopPar.endPos)) {
96  break;
97  }
98  ++iter;
99  ++edgeIter;
100  }
101  }
102  } else {
103  iter += stopPar.index;
104  edgeIter += stopPar.index;
105  }
106  }
107  myParameter.stops.insert(iter, stopPar);
108  myStopEdges.insert(edgeIter, stopEdge);
109 }
110 
111 
113 
114 
115 void
117  OutputDevice* const typeos, bool withExitTimes) const {
118  // check whether the vehicle's type was saved before
119  if (myType != 0 && !myType->saved) {
120  // ... save if not
121  if (typeos != 0) {
122  myType->write(*typeos);
123  } else {
124  myType->write(os);
125  if (altos != 0) {
126  myType->write(*altos);
127  }
128  }
129  myType->saved = true;
130  }
131 
132  // write the vehicle (new style, with included routes)
134  if (altos != 0) {
136  }
137 
138  // check whether the route shall be saved
139  if (!myRoute->isSaved()) {
140  myRoute->writeXMLDefinition(os, this, false, withExitTimes);
141  if (altos != 0) {
142  myRoute->writeXMLDefinition(*altos, this, true, withExitTimes);
143  }
144  }
146  if (altos != 0) {
147  myParameter.writeStops(*altos);
148  }
149  os.closeTag();
150  if (altos != 0) {
151  altos->closeTag();
152  }
153 }
154 
155 
156 SUMOReal
158  return myType->maxSpeed;
159 }
160 
161 
162 /****************************************************************************/
163