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"), net(net),
65  myCity(city) {}
66 
67 
69 
70 
71 void
73 {
74  try {
75  switch (element) {
76  case AGEN_TAG_GENERAL:
77  parseGeneralCityInfo(attrs);
78  break;
79  case AGEN_TAG_STREET:
80  parseStreets(attrs);
81  break;
82  case AGEN_TAG_WORKHOURS:
84  break;
85  case AGEN_TAG_OPENING:
86  parseOpeningHour(attrs);
87  break;
88  case AGEN_TAG_CLOSING:
89  parseClosingHour(attrs);
90  break;
91  case AGEN_TAG_SCHOOLS:
92  parseSchools();
93  break;
94  case AGEN_TAG_SCHOOL:
95  parseSchool(attrs);
96  break;
98  parseBusStation(attrs);
99  break;
100  case AGEN_TAG_BUSLINE:
101  parseBusLine(attrs);
102  break;
103  case AGEN_TAG_STATIONS:
104  parseStations();
105  break;
108  break;
109  case AGEN_TAG_STATION:
110  parseStation(attrs);
111  break;
112  case AGEN_TAG_FREQUENCY:
113  parseFrequency(attrs);
114  break;
115  case AGEN_TAG_POPULATION:
116  parsePopulation();
117  break;
118  /*case AGEN_TAG_CHILD_ACOMP:
119  parseChildrenAccompaniment();
120  break;*/
121  case AGEN_TAG_BRACKET:
122  parseBracket(attrs);
123  break;
124  case AGEN_TAG_PARAM:
125  parseParameters(attrs);
126  break;
127  case AGEN_TAG_ENTRANCE:
128  parseCityGates(attrs);
129  break;
130  default:
131  break;
132  }
133  } catch (const exception& e) {
134  throw ProcessError(e.what());
135  }
136 }
137 
138 
139 void
141  try {
151 
152  } catch (const exception& e) {
153  WRITE_ERROR("Error while parsing the element " +
154  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_GENERAL) + ": " +
155  e.what());
156  throw ProcessError();
157  }
158 }
159 
160 void
162  try {
168 
169  } catch (const exception& e) {
170  WRITE_ERROR("Error while parsing the element " +
171  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_PARAM) + ": " +
172  e.what());
173  throw ProcessError();
174  }
175 }
176 
177 void
179  try {
180  SUMOReal pop = 0;
181  SUMOReal work = 0;
182 
183  if (attrs.hasAttribute(AGEN_ATTR_POPULATION)) {
184  pop = attrs.getFloat(AGEN_ATTR_POPULATION);
185  }
187  work = attrs.getFloat(AGEN_ATTR_OUT_WORKPOSITION);
188  }
189 
190  AGStreet str(net->getEdge(attrs.getString(SUMO_ATTR_EDGE)), pop, work);
191  myCity.streets.push_back(str);
192 
193  } catch (const exception& e) {
194  WRITE_ERROR("Error while parsing the element " +
195  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
196  e.what());
197  throw ProcessError();
198  }
199 }
200 
201 void
203  try {
204  string edge = attrs.getString(SUMO_ATTR_EDGE);
205  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
206  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
209  myCity.cityGates.push_back(posi);
210 
211  } catch (const exception& e) {
212  WRITE_ERROR("Error while parsing the element " +
213  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " +
214  e.what());
215  throw ProcessError();
216  }
217 }
218 
219 void
221  myCurrentObject = "workHours";
222 }
223 
224 void
226  if (myCurrentObject == "workHours") {
227  try {
229 
230  } catch (const exception& e) {
231  WRITE_ERROR("Error while parsing the element " +
233  + e.what());
234  throw ProcessError();
235  }
236  }
237 }
238 
239 void
241  if (myCurrentObject == "workHours") {
242  try {
244 
245  } catch (const exception& e) {
246  WRITE_ERROR("Error while parsing the element " +
248  + e.what());
249  throw ProcessError();
250  }
251  }
252 }
253 
254 void
256  myCurrentObject = "schools";
257 }
258 
259 void
261  try {
262  string edge = attrs.getString(SUMO_ATTR_EDGE);
263  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
264  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
265  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE);
266  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE);
267  int capacity = attrs.getInt(AGEN_ATTR_CAPACITY);
268  int openingHour = attrs.getInt(AGEN_ATTR_OPENING);
269  int closingHour = attrs.getInt(AGEN_ATTR_CLOSING);
270  AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
271  myCity.schools.push_back(sch);
272 
273  } catch (const exception& e) {
274  WRITE_ERROR("Error while parsing the element " +
275  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " +
276  e.what());
277  throw ProcessError();
278  }
279 }
280 
281 void
283  try {
284  string edge = attrs.getString(SUMO_ATTR_EDGE);
285  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
286  int id = attrs.getInt(SUMO_ATTR_ID);
287  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
288  myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi));
289 
290  } catch (const exception& e) {
291  WRITE_ERROR("Error while parsing the element " +
293  e.what());
294  throw ProcessError();
295  }
296 }
297 
298 void
300  try {
301  myCurrentObject = "busLine";
302  AGBusLine busL(attrs.getString(SUMO_ATTR_ID));
304  myCity.busLines.push_front(busL);
305  currentBusLine = &*myCity.busLines.begin();
306 
307  } catch (const exception& e) {
308  WRITE_ERROR("Error while parsing the element " +
309  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " +
310  e.what());
311  throw ProcessError();
312  }
313 }
314 
315 void
317  isRevStation = false;
318 }
319 
320 void
322  isRevStation = true;
323 }
324 
325 void
327  if (myCurrentObject != "busLine") {
328  return;
329  }
330 
331  try {
332  bool ok = true;
333  int refID = attrs.hasAttribute(SUMO_ATTR_REFID)
334  ? attrs.getIntReporting(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok)
336  if (!ok) {
337  throw ProcessError();
338  }
339 
340  if (!isRevStation) {
342  } else {
344  }
345 
346  } catch (const exception& e) {
347  WRITE_ERROR("Error while parsing the element " +
348  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STATION) + ": " +
349  e.what());
350  throw ProcessError();
351  }
352 }
353 
354 void
356  if (myCurrentObject != "busLine") {
357  return;
358  }
359 
360  try {
361  int beginB = attrs.getInt(SUMO_ATTR_BEGIN);
362  int endB = attrs.getInt(SUMO_ATTR_END);
363  int rateB = attrs.getInt(AGEN_ATTR_RATE);
364  currentBusLine->generateBuses(beginB, endB, rateB);
365 
366  } catch (const exception& e) {
367  WRITE_ERROR("Error while parsing the element " +
368  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_FREQUENCY) + ": " +
369  e.what());
370  throw ProcessError();
371  }
372 }
373 
374 void
376  myCurrentObject = "population";
377 }
378 
379 void
381  try {
382  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
383  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket
384  if (myCurrentObject == "population") {
386  }
387 
388  } catch (const exception& e) {
389  WRITE_ERROR("Error while parsing the element " +
390  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " +
391  e.what());
392  throw ProcessError();
393  }
394 }
395 
396 /****************************************************************************/
397