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-2014 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 
ROVehicle(const SUMOVehicleParameter &pars, RORouteDef *route, const SUMOVTypeParameter *type, const RONet *net)
Constructor.
Definition: ROVehicle.cpp:55
SUMOVehicleParameter myParameter
The vehicle's parameter.
Definition: ROVehicle.h:154
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:100
bool isSaved() const
Returns the information whether this item was already saved.
SUMOReal getMaxSpeed() const
Returns the vehicle's maximum speed.
Definition: ROVehicle.cpp:156
const int STOP_INDEX_FIT
RORouteDef *const myRoute
The route the vehicle takes.
Definition: ROVehicle.h:160
void saveAllAsXML(OutputDevice &os, OutputDevice *const altos, OutputDevice *const typeos, bool withExitTimes) const
Saves the complete vehicle description.
Definition: ROVehicle.cpp:115
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:71
OutputDevice & writeXMLDefinition(OutputDevice &dev, const ROVehicle *const veh, bool asAlternatives, bool withExitTimes) const
Saves the built route / route alternatives.
Definition: RORouteDef.cpp:323
SUMOReal endPos
The stopping position end.
const int STOP_INDEX_END
const SUMOVTypeParameter *const myType
The type of the vehicle.
Definition: ROVehicle.h:157
A basic edge for routing applications.
Definition: ROEdge.h:67
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:152
The router's network representation.
Definition: RONet.h:65
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:63
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:163
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:215
const RORoute * getFirstRoute() const
Definition: RORouteDef.h:108
virtual ~ROVehicle()
Destructor.
Definition: ROVehicle.cpp:111
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the list of stops this route contains.
Definition: RORoute.h:181