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 
ROVehicle(const SUMOVehicleParameter &pars, RORouteDef *route, const SUMOVTypeParameter *type, const RONet *net)
Constructor.
Definition: ROVehicle.cpp:56
SUMOVehicleParameter myParameter
The vehicle's parameter.
Definition: ROVehicle.h:155
void writeStops(OutputDevice &dev) const
Writes the enclosed stops.
Structure representing possible vehicle parameter.
bool saved
Information whether this type was already saved (needed by routers)
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:102
bool isSaved() const
Returns the information whether this item was already saved.
SUMOReal getMaxSpeed() const
Returns the vehicle's maximum speed.
Definition: ROVehicle.cpp:157
const int STOP_INDEX_FIT
RORouteDef *const myRoute
The route the vehicle takes.
Definition: ROVehicle.h:161
void saveAllAsXML(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos, bool withExitTimes) const
Saves the complete vehicle description.
Definition: ROVehicle.cpp:116
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
std::vector< Stop > stops
List of the stops the vehicle will make.
void addStop(const SUMOVehicleParameter::Stop &stopPar, const RONet *net)
Adds a stop to this vehicle.
Definition: ROVehicle.cpp:72
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
Definition: RORouteDef.cpp:324
SUMOReal endPos
The stopping position end.
const int STOP_INDEX_END
const SUMOVTypeParameter *const myType
The type of the vehicle.
Definition: ROVehicle.h:158
A basic edge for routing applications.
Definition: ROEdge.h:69
std::string lane
The lane to stop at.
void write(OutputDevice &dev) const
Writes the vtype.
SUMOReal maxSpeed
The vehicle type's maximum speed [m/s].
const std::vector< const ROEdge * > & getEdgeVector() const
Returns the list of edges this route consists of.
Definition: RORoute.h:154
The router's network representation.
Definition: RONet.h:67
Structure representing possible vehicle parameter.
Definition of vehicle stop (position and duration)
int index
at which position in the stops list
Base class for a vehicle's route definition.
Definition: RORouteDef.h:64
void write(OutputDevice &dev, const OptionsCont &oc) const
Writes the parameters as a beginning element.
std::vector< const ROEdge * > myStopEdges
The edges where the vehicle stops.
Definition: ROVehicle.h:164
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
const RORoute * getFirstRoute() const
Definition: RORouteDef.h:109
virtual ~ROVehicle()
Destructor.
Definition: ROVehicle.cpp:112
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
Definition: RORoute.h:183