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  myActiveRouteColor(0),
59  myCurrentVType(0) {
60 }
61 
62 
64 }
65 
66 
69  return myLastDepart;
70 }
71 
72 
73 bool
77  WRITE_WARNING("Route file should be sorted by departure time, ignoring '" + myVehicleParameter->id + "'!");
78  return false;
79  }
80  }
81  return true;
82 }
83 
84 
85 void
89  }
90  // else: we don't know when this vehicle will depart. keep the previous known depart time
91 }
92 
93 
94 void
96  const SUMOSAXAttributes& attrs) {
97  switch (element) {
98  case SUMO_TAG_VEHICLE:
99  delete myVehicleParameter;
101  break;
102  case SUMO_TAG_PERSON:
103  delete myVehicleParameter;
105  break;
106  case SUMO_TAG_FLOW:
107  delete myVehicleParameter;
109  break;
110  case SUMO_TAG_VTYPE:
112  break;
115  break;
116  case SUMO_TAG_ROUTE:
117  openRoute(attrs);
118  break;
120  openRouteDistribution(attrs);
121  break;
122  case SUMO_TAG_STOP:
123  addStop(attrs);
124  break;
125  case SUMO_TAG_TRIP: {
129  }
130  break;
131  default:
132  break;
133  }
134 }
135 
136 
137 void
139  switch (element) {
140  case SUMO_TAG_ROUTE:
141  closeRoute();
142  break;
143  case SUMO_TAG_PERSON:
144  closePerson();
145  delete myVehicleParameter;
146  myVehicleParameter = 0;
147  break;
148  case SUMO_TAG_VEHICLE:
150  myVehicleParameter->repetitionNumber++; // for backwards compatibility
151  // it is a flow, thus no break here
152  } else {
153  closeVehicle();
154  delete myVehicleParameter;
155  myVehicleParameter = 0;
156  break;
157  }
158  case SUMO_TAG_FLOW:
159  closeFlow();
160  break;
163  break;
166  break;
167  case SUMO_TAG_VTYPE:
169  break;
170  default:
171  break;
172  }
173 }
174 
175 
176 bool
177 SUMORouteHandler::checkStopPos(SUMOReal& startPos, SUMOReal& endPos, const SUMOReal laneLength,
178  const SUMOReal minLength, const bool friendlyPos) {
179  if (minLength > laneLength) {
180  return false;
181  }
182  if (startPos < 0) {
183  startPos += laneLength;
184  }
185  if (endPos < 0) {
186  endPos += laneLength;
187  }
188  if (endPos < minLength || endPos > laneLength) {
189  if (!friendlyPos) {
190  return false;
191  }
192  if (endPos < minLength) {
193  endPos = minLength;
194  }
195  if (endPos > laneLength) {
196  endPos = laneLength;
197  }
198  }
199  if (startPos < 0 || startPos > endPos - minLength) {
200  if (!friendlyPos) {
201  return false;
202  }
203  if (startPos < 0) {
204  startPos = 0;
205  }
206  if (startPos > endPos - minLength) {
207  startPos = endPos - minLength;
208  }
209  }
210  return true;
211 }
212 
213 /****************************************************************************/