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-sim.org/
14 // Copyright (C) 2001-2013 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 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
63  : SUMOSAXHandler("sumo-stat"),
64  myCity(city), net(net) {}
65 
66 
68 
69 
70 void
72  try {
73  switch (element) {
74  case AGEN_TAG_GENERAL:
75  parseGeneralCityInfo(attrs);
76  break;
77  case AGEN_TAG_STREET:
78  parseStreets(attrs);
79  break;
80  case AGEN_TAG_WORKHOURS:
82  break;
83  case AGEN_TAG_OPENING:
84  parseOpeningHour(attrs);
85  break;
86  case AGEN_TAG_CLOSING:
87  parseClosingHour(attrs);
88  break;
89  case AGEN_TAG_SCHOOLS:
90  parseSchools();
91  break;
92  case AGEN_TAG_SCHOOL:
93  parseSchool(attrs);
94  break;
96  parseBusStation(attrs);
97  break;
98  case AGEN_TAG_BUSLINE:
99  parseBusLine(attrs);
100  break;
101  case AGEN_TAG_STATIONS:
102  parseStations();
103  break;
106  break;
107  case AGEN_TAG_STATION:
108  parseStation(attrs);
109  break;
110  case AGEN_TAG_FREQUENCY:
111  parseFrequency(attrs);
112  break;
113  case AGEN_TAG_POPULATION:
114  parsePopulation();
115  break;
116  /*case AGEN_TAG_CHILD_ACOMP:
117  parseChildrenAccompaniment();
118  break;*/
119  case AGEN_TAG_BRACKET:
120  parseBracket(attrs);
121  break;
122  case AGEN_TAG_PARAM:
123  parseParameters(attrs);
124  break;
125  case AGEN_TAG_ENTRANCE:
126  parseCityGates(attrs);
127  break;
128  default:
129  break;
130  }
131  } catch (const std::exception& e) {
132  throw ProcessError(e.what());
133  }
134 }
135 
136 
137 void
139  try {
140  bool ok;
143  myCity.statData.limitAgeChildren = attrs.getOpt<int>(AGEN_ATTR_CHILDREN, 0, ok, 18);
145  myCity.statData.carRate = attrs.getOpt<SUMOReal>(AGEN_ATTR_CARS, 0, ok, 0.58);
150  } catch (const std::exception& e) {
151  WRITE_ERROR("Error while parsing the element " +
152  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_GENERAL) + ": " +
153  e.what());
154  throw ProcessError();
155  }
156 }
157 
158 void
160  try {
161  bool ok;
167  } catch (const std::exception& e) {
168  WRITE_ERROR("Error while parsing the element " +
169  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_PARAM) + ": " +
170  e.what());
171  throw ProcessError();
172  }
173 }
174 
175 void
177  try {
178  SUMOReal pop = 0;
179  SUMOReal work = 0;
180 
181  if (attrs.hasAttribute(AGEN_ATTR_POPULATION)) {
182  pop = attrs.getFloat(AGEN_ATTR_POPULATION);
183  }
185  work = attrs.getFloat(AGEN_ATTR_OUT_WORKPOSITION);
186  }
187  std::string eid = attrs.getString(SUMO_ATTR_EDGE);
188  ROEdge* e = net->getEdge(eid);
189  if (e == 0) {
190  WRITE_ERROR("Edge '" + eid + "' is not known.");
191  return;
192  }
193 
194  AGStreet str(e, pop, work);
195  myCity.streets.push_back(str);
196 
197  } catch (const std::exception& e) {
198  WRITE_ERROR("Error while parsing the element " +
199  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
200  e.what());
201  throw ProcessError();
202  }
203 }
204 
205 void
207  try {
208  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
209  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
210  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
213  myCity.cityGates.push_back(posi);
214 
215  } catch (const std::exception& e) {
216  WRITE_ERROR("Error while parsing the element " +
217  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " +
218  e.what());
219  throw ProcessError();
220  }
221 }
222 
223 void
225  myCurrentObject = "workHours";
226 }
227 
228 void
230  if (myCurrentObject == "workHours") {
231  try {
233 
234  } catch (const std::exception& e) {
235  WRITE_ERROR("Error while parsing the element " +
237  + e.what());
238  throw ProcessError();
239  }
240  }
241 }
242 
243 void
245  if (myCurrentObject == "workHours") {
246  try {
248 
249  } catch (const std::exception& e) {
250  WRITE_ERROR("Error while parsing the element " +
252  + e.what());
253  throw ProcessError();
254  }
255  }
256 }
257 
258 void
260  myCurrentObject = "schools";
261 }
262 
263 void
265  try {
266  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
267  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
268  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
269  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE);
270  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE);
271  int capacity = attrs.getInt(AGEN_ATTR_CAPACITY);
272  int openingHour = attrs.getInt(AGEN_ATTR_OPENING);
273  int closingHour = attrs.getInt(AGEN_ATTR_CLOSING);
274  AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
275  myCity.schools.push_back(sch);
276 
277  } catch (const std::exception& e) {
278  WRITE_ERROR("Error while parsing the element " +
279  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " +
280  e.what());
281  throw ProcessError();
282  }
283 }
284 
285 void
287  try {
288  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
289  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
290  int id = attrs.getInt(SUMO_ATTR_ID);
291  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
292  myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi));
293 
294  } catch (const std::exception& e) {
295  WRITE_ERROR("Error while parsing the element " +
297  e.what());
298  throw ProcessError();
299  }
300 }
301 
302 void
304  try {
305  myCurrentObject = "busLine";
306  AGBusLine busL(attrs.getString(SUMO_ATTR_ID));
308  myCity.busLines.push_front(busL);
309  currentBusLine = &*myCity.busLines.begin();
310 
311  } catch (const std::exception& e) {
312  WRITE_ERROR("Error while parsing the element " +
313  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " +
314  e.what());
315  throw ProcessError();
316  }
317 }
318 
319 void
321  isRevStation = false;
322 }
323 
324 void
326  isRevStation = true;
327 }
328 
329 void
331  if (myCurrentObject != "busLine") {
332  return;
333  }
334 
335  try {
336  bool ok = true;
337  int refID = attrs.get<int>(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok);
338  if (!ok) {
339  throw ProcessError();
340  }
341  if (!isRevStation) {
343  } else {
345  }
346 
347  } catch (const std::exception& e) {
348  WRITE_ERROR("Error while parsing the element " +
349  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STATION) + ": " +
350  e.what());
351  throw ProcessError();
352  }
353 }
354 
355 void
357  if (myCurrentObject != "busLine") {
358  return;
359  }
360 
361  try {
362  int beginB = attrs.getInt(SUMO_ATTR_BEGIN);
363  int endB = attrs.getInt(SUMO_ATTR_END);
364  int rateB = attrs.getInt(AGEN_ATTR_RATE);
365  currentBusLine->generateBuses(beginB, endB, rateB);
366 
367  } catch (const std::exception& e) {
368  WRITE_ERROR("Error while parsing the element " +
369  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_FREQUENCY) + ": " +
370  e.what());
371  throw ProcessError();
372  }
373 }
374 
375 void
377  myCurrentObject = "population";
378 }
379 
380 void
382  try {
383 //TODO beginAge needs to be evaluated
384 // int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
385  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket
386  if (myCurrentObject == "population") {
388  }
389 
390  } catch (const std::exception& e) {
391  WRITE_ERROR("Error while parsing the element " +
392  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " +
393  e.what());
394  throw ProcessError();
395  }
396 }
397 
398 /****************************************************************************/
399 
void generateBuses(int start, int stop, int rate)
Definition: AGBusLine.cpp:150
void setMaxTripTime(int time)
Definition: AGBusLine.cpp:55
AGActivityGenHandler(AGCity &city, RONet *net)
Constructor.
std::string myCurrentObject
The name of the object that is currently processed.
void parseCityGates(const SUMOSAXAttributes &attrs)
void parseGeneralCityInfo(const SUMOSAXAttributes &attrs)
void parseStation(const SUMOSAXAttributes &attrs)
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:100
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:63
AGDataAndStatistics & statData
Definition: AGCity.h:87
std::map< int, SUMOReal > endWorkHours
A model of the street in the city.
Definition: AGStreet.h:57
void parseSchool(const SUMOSAXAttributes &attrs)
void parseBusStation(const SUMOSAXAttributes &attrs)
std::vector< AGStreet > streets
Definition: AGCity.h:88
SAX-handler base for SUMO-files.
RONet * net
The loaded network.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
bool isRevStation
indicator whether the current station (in bus line context) is a reverse station or not...
const AGStreet & getStreet(const std::string &edge)
Definition: AGCity.cpp:388
void locateRevStation(AGPosition pos)
Definition: AGBusLine.cpp:145
std::list< AGBusLine > busLines
Definition: AGCity.h:91
virtual std::string getString(int id) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual ~AGActivityGenHandler()
Destructor.
void locateStation(AGPosition pos)
Definition: AGBusLine.cpp:140
Definition: AGCity.h:59
Encapsulated SAX-Attributes.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
virtual SUMOReal getFloat(int id) const =0
Returns the SUMOReal-value of the named (by its enum-value) attribute.
std::list< AGSchool > schools
Definition: AGCity.h:90
void parseBusLine(const SUMOSAXAttributes &attrs)
void parseParameters(const SUMOSAXAttributes &attrs)
A basic edge for routing applications.
Definition: ROEdge.h:67
void parseFrequency(const SUMOSAXAttributes &attrs)
AGCity & myCity
The city to store the information into.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
std::map< int, SUMOReal > beginWorkHours
void parseBracket(const SUMOSAXAttributes &attrs)
The router&#39;s network representation.
Definition: RONet.h:65
void parseClosingHour(const SUMOSAXAttributes &attrs)
std::map< int, SUMOReal > population
void parseOpeningHour(const SUMOSAXAttributes &attrs)
void parseStreets(const SUMOSAXAttributes &attrs)
virtual int getInt(int id) const =0
Returns the int-value of the named (by its enum-value) attribute.
std::map< int, SUMOReal > incoming
#define SUMOReal
Definition: config.h:215
static StringBijection< int > Tags
The names of SUMO-XML elements for use in netbuild.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
std::map< int, SUMOReal > outgoing
std::vector< AGPosition > cityGates
Definition: AGCity.h:93
std::map< int, AGPosition > busStations