SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SUMORouteHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Parser for routes during their loading
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 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 
34 #include <string>
35 #include <map>
36 #include <vector>
40 #include <utils/common/ToString.h>
44 #include "SUMORouteHandler.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 SUMORouteHandler::SUMORouteHandler(const std::string& file) :
55  SUMOSAXHandler(file),
56  myVehicleParameter(0),
57  myLastDepart(0),
58  myCurrentVType(0) {
59 }
60 
61 
63 }
64 
65 
68  return myLastDepart;
69 }
70 
71 
72 bool
76  WRITE_WARNING("Route file should be sorted by departure time, ignoring '" + myVehicleParameter->id + "'!");
77  return false;
78  }
79  }
80  return true;
81 }
82 
83 
84 void
88  }
89  // else: we don't know when this vehicle will depart. keep the previous known depart time
90 }
91 
92 
93 void
95  const SUMOSAXAttributes& attrs) {
96  switch (element) {
97  case SUMO_TAG_VEHICLE:
98  delete myVehicleParameter;
100  break;
101  case SUMO_TAG_PERSON:
102  delete myVehicleParameter;
104  break;
105  case SUMO_TAG_FLOW:
106  delete myVehicleParameter;
108  break;
109  case SUMO_TAG_VTYPE:
111  break;
114  break;
115  case SUMO_TAG_ROUTE:
116  openRoute(attrs);
117  break;
119  openRouteDistribution(attrs);
120  break;
121  case SUMO_TAG_STOP:
122  addStop(attrs);
123  break;
124  case SUMO_TAG_TRIP: {
128  }
129  break;
130  default:
131  break;
132  }
133 }
134 
135 
136 void
138  switch (element) {
139  case SUMO_TAG_ROUTE:
140  closeRoute();
141  break;
142  case SUMO_TAG_PERSON:
143  closePerson();
144  delete myVehicleParameter;
145  myVehicleParameter = 0;
146  break;
147  case SUMO_TAG_VEHICLE:
149  myVehicleParameter->repetitionNumber++; // for backwards compatibility
150  // it is a flow, thus no break here
151  } else {
152  closeVehicle();
153  delete myVehicleParameter;
154  myVehicleParameter = 0;
155  break;
156  }
157  case SUMO_TAG_FLOW:
158  closeFlow();
159  break;
163  break;
166  break;
168  case SUMO_TAG_VTYPE:
170  break;
171  default:
172  break;
173  }
174 }
175 
176 
177 bool
178 SUMORouteHandler::checkStopPos(SUMOReal& startPos, SUMOReal& endPos, const SUMOReal laneLength,
179  const SUMOReal minLength, const bool friendlyPos) {
180  if (minLength > laneLength) {
181  return false;
182  }
183  if (startPos < 0) {
184  startPos += laneLength;
185  }
186  if (endPos < 0) {
187  endPos += laneLength;
188  }
189  if (endPos < minLength || endPos > laneLength) {
190  if (!friendlyPos) {
191  return false;
192  }
193  if (endPos < minLength) {
194  endPos = minLength;
195  }
196  if (endPos > laneLength) {
197  endPos = laneLength;
198  }
199  }
200  if (startPos < 0 || startPos > endPos - minLength) {
201  if (!friendlyPos) {
202  return false;
203  }
204  if (startPos < 0) {
205  startPos = 0;
206  }
207  if (startPos > endPos - minLength) {
208  startPos = endPos - minLength;
209  }
210  }
211  return true;
212 }
213 
214 /****************************************************************************/