SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AGActivityGenHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // The handler for parsing the statistics file.
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
14 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
15 // activitygen module
16 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include "AGActivityGenHandler.h"
38 #include <iostream>
39 #include <utility>
40 #include <map>
41 #include <string>
48 #include <router/RONet.h>
49 #include "city/AGCity.h"
50 #include "city/AGSchool.h"
51 #include "city/AGPosition.h"
52 #include "city/AGBusLine.h"
53 
54 #ifdef CHECK_MEMORY_LEAKS
55 #include <foreign/nvwa/debug_new.h>
56 #endif // CHECK_MEMORY_LEAKS
57 
58 using namespace std;
59 
60 // ===========================================================================
61 // method definitions
62 // ===========================================================================
64  : SUMOSAXHandler("sumo-stat"),
65  myCity(city), net(net) {}
66 
67 
69 
70 
71 void
73  try {
74  switch (element) {
75  case AGEN_TAG_GENERAL:
76  parseGeneralCityInfo(attrs);
77  break;
78  case AGEN_TAG_STREET:
79  parseStreets(attrs);
80  break;
81  case AGEN_TAG_WORKHOURS:
83  break;
84  case AGEN_TAG_OPENING:
85  parseOpeningHour(attrs);
86  break;
87  case AGEN_TAG_CLOSING:
88  parseClosingHour(attrs);
89  break;
90  case AGEN_TAG_SCHOOLS:
91  parseSchools();
92  break;
93  case AGEN_TAG_SCHOOL:
94  parseSchool(attrs);
95  break;
97  parseBusStation(attrs);
98  break;
99  case AGEN_TAG_BUSLINE:
100  parseBusLine(attrs);
101  break;
102  case AGEN_TAG_STATIONS:
103  parseStations();
104  break;
107  break;
108  case AGEN_TAG_STATION:
109  parseStation(attrs);
110  break;
111  case AGEN_TAG_FREQUENCY:
112  parseFrequency(attrs);
113  break;
114  case AGEN_TAG_POPULATION:
115  parsePopulation();
116  break;
117  /*case AGEN_TAG_CHILD_ACOMP:
118  parseChildrenAccompaniment();
119  break;*/
120  case AGEN_TAG_BRACKET:
121  parseBracket(attrs);
122  break;
123  case AGEN_TAG_PARAM:
124  parseParameters(attrs);
125  break;
126  case AGEN_TAG_ENTRANCE:
127  parseCityGates(attrs);
128  break;
129  default:
130  break;
131  }
132  } catch (const exception& e) {
133  throw ProcessError(e.what());
134  }
135 }
136 
137 
138 void
140  try {
150 
151  } catch (const exception& e) {
152  WRITE_ERROR("Error while parsing the element " +
153  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_GENERAL) + ": " +
154  e.what());
155  throw ProcessError();
156  }
157 }
158 
159 void
161  try {
167 
168  } catch (const exception& e) {
169  WRITE_ERROR("Error while parsing the element " +
170  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_PARAM) + ": " +
171  e.what());
172  throw ProcessError();
173  }
174 }
175 
176 void
178  try {
179  SUMOReal pop = 0;
180  SUMOReal work = 0;
181 
182  if (attrs.hasAttribute(AGEN_ATTR_POPULATION)) {
183  pop = attrs.getFloat(AGEN_ATTR_POPULATION);
184  }
186  work = attrs.getFloat(AGEN_ATTR_OUT_WORKPOSITION);
187  }
188 
189  AGStreet str(net->getEdge(attrs.getString(SUMO_ATTR_EDGE)), pop, work);
190  myCity.streets.push_back(str);
191 
192  } catch (const exception& e) {
193  WRITE_ERROR("Error while parsing the element " +
194  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
195  e.what());
196  throw ProcessError();
197  }
198 }
199 
200 void
202  try {
203  string edge = attrs.getString(SUMO_ATTR_EDGE);
204  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
205  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
208  myCity.cityGates.push_back(posi);
209 
210  } catch (const exception& e) {
211  WRITE_ERROR("Error while parsing the element " +
212  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " +
213  e.what());
214  throw ProcessError();
215  }
216 }
217 
218 void
220  myCurrentObject = "workHours";
221 }
222 
223 void
225  if (myCurrentObject == "workHours") {
226  try {
228 
229  } catch (const exception& e) {
230  WRITE_ERROR("Error while parsing the element " +
232  + e.what());
233  throw ProcessError();
234  }
235  }
236 }
237 
238 void
240  if (myCurrentObject == "workHours") {
241  try {
243 
244  } catch (const exception& e) {
245  WRITE_ERROR("Error while parsing the element " +
247  + e.what());
248  throw ProcessError();
249  }
250  }
251 }
252 
253 void
255  myCurrentObject = "schools";
256 }
257 
258 void
260  try {
261  string edge = attrs.getString(SUMO_ATTR_EDGE);
262  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
263  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
264  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE);
265  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE);
266  int capacity = attrs.getInt(AGEN_ATTR_CAPACITY);
267  int openingHour = attrs.getInt(AGEN_ATTR_OPENING);
268  int closingHour = attrs.getInt(AGEN_ATTR_CLOSING);
269  AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
270  myCity.schools.push_back(sch);
271 
272  } catch (const exception& e) {
273  WRITE_ERROR("Error while parsing the element " +
274  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " +
275  e.what());
276  throw ProcessError();
277  }
278 }
279 
280 void
282  try {
283  string edge = attrs.getString(SUMO_ATTR_EDGE);
284  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
285  int id = attrs.getInt(SUMO_ATTR_ID);
286  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
287  myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi));
288 
289  } catch (const exception& e) {
290  WRITE_ERROR("Error while parsing the element " +
292  e.what());
293  throw ProcessError();
294  }
295 }
296 
297 void
299  try {
300  myCurrentObject = "busLine";
301  AGBusLine busL(attrs.getString(SUMO_ATTR_ID));
303  myCity.busLines.push_front(busL);
304  currentBusLine = &*myCity.busLines.begin();
305 
306  } catch (const exception& e) {
307  WRITE_ERROR("Error while parsing the element " +
308  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " +
309  e.what());
310  throw ProcessError();
311  }
312 }
313 
314 void
316  isRevStation = false;
317 }
318 
319 void
321  isRevStation = true;
322 }
323 
324 void
326  if (myCurrentObject != "busLine") {
327  return;
328  }
329 
330  try {
331  bool ok = true;
332  int refID = attrs.getIntReporting(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok);
333  if (!ok) {
334  throw ProcessError();
335  }
336  if (!isRevStation) {
338  } else {
340  }
341 
342  } catch (const exception& e) {
343  WRITE_ERROR("Error while parsing the element " +
344  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STATION) + ": " +
345  e.what());
346  throw ProcessError();
347  }
348 }
349 
350 void
352  if (myCurrentObject != "busLine") {
353  return;
354  }
355 
356  try {
357  int beginB = attrs.getInt(SUMO_ATTR_BEGIN);
358  int endB = attrs.getInt(SUMO_ATTR_END);
359  int rateB = attrs.getInt(AGEN_ATTR_RATE);
360  currentBusLine->generateBuses(beginB, endB, rateB);
361 
362  } catch (const exception& e) {
363  WRITE_ERROR("Error while parsing the element " +
364  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_FREQUENCY) + ": " +
365  e.what());
366  throw ProcessError();
367  }
368 }
369 
370 void
372  myCurrentObject = "population";
373 }
374 
375 void
377  try {
378 //TODO beginAge needs to be evaluated
379 // int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
380  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket
381  if (myCurrentObject == "population") {
383  }
384 
385  } catch (const exception& e) {
386  WRITE_ERROR("Error while parsing the element " +
387  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " +
388  e.what());
389  throw ProcessError();
390  }
391 }
392 
393 /****************************************************************************/
394