SUMO - Simulation of Urban MObility
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.dlr.de/
13 // Copyright (C) 2002-2015 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), myRoutingSuccess(false) {
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  ConstROEdgeVector::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) {
89  ConstROEdgeVector::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) 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 
133 
134 void
135 ROVehicle::saveAllAsXML(OutputDevice& os, bool asAlternatives, bool withExitTimes) const {
136  // write the vehicle (new style, with included routes)
138 
139  // save the route
140  myRoute->writeXMLDefinition(os, this, asAlternatives, withExitTimes);
142  for (std::map<std::string, std::string>::const_iterator j = myParameter.getMap().begin(); j != myParameter.getMap().end(); ++j) {
144  os.writeAttr(SUMO_ATTR_KEY, (*j).first);
145  os.writeAttr(SUMO_ATTR_VALUE, (*j).second);
146  os.closeTag();
147  }
148  os.closeTag();
149 }
150 
151 
152 SUMOReal
154  return myType->maxSpeed;
155 }
156 
157 
158 /****************************************************************************/
159 
ROVehicle(const SUMOVehicleParameter &pars, RORouteDef *route, const SUMOVTypeParameter *type, const RONet *net)
Constructor.
Definition: ROVehicle.cpp:56
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
SUMOVehicleParameter myParameter
The vehicle&#39;s parameter.
Definition: ROVehicle.h:184
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:158
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
Definition: RORoute.h:155
SUMOReal getMaxSpeed() const
Returns the vehicle&#39;s maximum speed.
Definition: ROVehicle.cpp:153
const int STOP_INDEX_FIT
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
std::vector< const ROEdge * > ConstROEdgeVector
Definition: ROEdge.h:59
RORouteDef *const myRoute
The route the vehicle takes.
Definition: ROVehicle.h:190
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
std::vector< Stop > stops
List of the stops the vehicle will make.
void saveTypeAsXML(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos) const
Saves the vehicle type if it was not saved before.
Definition: ROVehicle.cpp:116
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:377
SUMOReal endPos
The stopping position end.
const int STOP_INDEX_END
const SUMOVTypeParameter *const myType
The type of the vehicle.
Definition: ROVehicle.h:187
A basic edge for routing applications.
Definition: ROEdge.h:73
void saveAllAsXML(OutputDevice &os, bool asAlternatives, bool withExitTimes) const
Saves the complete vehicle description.
Definition: ROVehicle.cpp:135
std::string lane
The lane to stop at.
void write(OutputDevice &dev) const
Writes the vtype.
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
The router&#39;s network representation.
Definition: RONet.h:72
Structure representing possible vehicle parameter.
ConstROEdgeVector myStopEdges
The edges where the vehicle stops.
Definition: ROVehicle.h:193
Definition of vehicle stop (position and duration)
int index
at which position in the stops list
Base class for a vehicle&#39;s route definition.
Definition: RORouteDef.h:63
void write(OutputDevice &dev, const OptionsCont &oc) const
Writes the parameters as a beginning element.
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:214
const RORoute * getFirstRoute() const
Definition: RORouteDef.h:108
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:184
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.