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-2013 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(-1),
58  myActiveRouteColor(0),
59  myCurrentVType(0),
60  myBeginDefault(string2time(OptionsCont::getOptions().getString("begin"))),
61  myEndDefault(string2time(OptionsCont::getOptions().getString("end"))) {
62 }
63 
64 
66 }
67 
68 
71  return myLastDepart;
72 }
73 
74 
75 bool
79  WRITE_WARNING("Route file should be sorted by departure time, ignoring '" + myVehicleParameter->id + "'!");
80  return false;
81  }
82  }
83  return true;
84 }
85 
86 
87 void
91  }
92  // else: we don't know when this vehicle will depart. keep the previous known depart time
93 }
94 
95 
96 void
98  const SUMOSAXAttributes& attrs) {
99  switch (element) {
100  case SUMO_TAG_VEHICLE:
101  delete myVehicleParameter;
103  break;
104  case SUMO_TAG_PERSON:
105  delete myVehicleParameter;
107  break;
108  case SUMO_TAG_FLOW:
109  delete myVehicleParameter;
111  break;
112  case SUMO_TAG_VTYPE:
114  break;
117  break;
118  case SUMO_TAG_ROUTE:
119  openRoute(attrs);
120  break;
122  openRouteDistribution(attrs);
123  break;
124  case SUMO_TAG_STOP:
125  addStop(attrs);
126  break;
127  case SUMO_TAG_TRIP: {
129  if (myVehicleParameter->id == "") {
130  //@todo warn about deprecation of missing trip ids
132  }
135  break;
136  }
137  case SUMO_TAG_INTERVAL: {
138  bool ok;
141  break;
142  }
143  default:
144  break;
145  }
146 }
147 
148 
149 void
151  switch (element) {
152  case SUMO_TAG_ROUTE:
153  closeRoute();
154  break;
155  case SUMO_TAG_PERSON:
156  closePerson();
157  delete myVehicleParameter;
158  myVehicleParameter = 0;
159  break;
160  case SUMO_TAG_VEHICLE:
162  myVehicleParameter->repetitionNumber++; // for backwards compatibility
163  // it is a flow, thus no break here
164  } else {
165  closeVehicle();
166  delete myVehicleParameter;
167  myVehicleParameter = 0;
168  break;
169  }
170  case SUMO_TAG_FLOW:
171  closeFlow();
172  break;
175  break;
178  break;
179  case SUMO_TAG_VTYPE:
181  break;
182  case SUMO_TAG_INTERVAL:
183  myBeginDefault = string2time(OptionsCont::getOptions().getString("begin"));
184  myEndDefault = string2time(OptionsCont::getOptions().getString("end"));
185  break;
186  default:
187  break;
188  }
189 }
190 
191 
192 bool
193 SUMORouteHandler::checkStopPos(SUMOReal& startPos, SUMOReal& endPos, const SUMOReal laneLength,
194  const SUMOReal minLength, const bool friendlyPos) {
195  if (minLength > laneLength) {
196  return false;
197  }
198  if (startPos < 0) {
199  startPos += laneLength;
200  }
201  if (endPos < 0) {
202  endPos += laneLength;
203  }
204  if (endPos < minLength || endPos > laneLength) {
205  if (!friendlyPos) {
206  return false;
207  }
208  if (endPos < minLength) {
209  endPos = minLength;
210  }
211  if (endPos > laneLength) {
212  endPos = laneLength;
213  }
214  }
215  if (startPos < 0 || startPos > endPos - minLength) {
216  if (!friendlyPos) {
217  return false;
218  }
219  if (startPos < 0) {
220  startPos = 0;
221  }
222  if (startPos > endPos - minLength) {
223  startPos = endPos - minLength;
224  }
225  }
226  return true;
227 }
228 
229 /****************************************************************************/