SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.dlr.de/
14 // Copyright (C) 2001-2016 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  AGStreet* street = dynamic_cast<AGStreet*>(net->getEdge(eid));
189  if (street == 0) {
190  WRITE_ERROR("Edge '" + eid + "' is not known.");
191  return;
192  }
193  street->setPopulation(pop * street->getLength());
194  street->setWorkplaceNumber(work * street->getLength());
195  myCity.streets.push_back(street);
196  } catch (const std::exception& e) {
197  WRITE_ERROR("Error while parsing the element " +
198  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
199  e.what());
200  throw ProcessError();
201  }
202 }
203 
204 void
206  try {
207  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
208  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
209  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
212  myCity.cityGates.push_back(posi);
213 
214  } catch (const std::exception& e) {
215  WRITE_ERROR("Error while parsing the element " +
216  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " +
217  e.what());
218  throw ProcessError();
219  }
220 }
221 
222 void
224  myCurrentObject = "workHours";
225 }
226 
227 void
229  if (myCurrentObject == "workHours") {
230  try {
232 
233  } catch (const std::exception& e) {
234  WRITE_ERROR("Error while parsing the element " +
236  + e.what());
237  throw ProcessError();
238  }
239  }
240 }
241 
242 void
244  if (myCurrentObject == "workHours") {
245  try {
247 
248  } catch (const std::exception& e) {
249  WRITE_ERROR("Error while parsing the element " +
251  + e.what());
252  throw ProcessError();
253  }
254  }
255 }
256 
257 void
259  myCurrentObject = "schools";
260 }
261 
262 void
264  try {
265  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
266  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
267  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
268  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE);
269  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE);
270  int capacity = attrs.getInt(AGEN_ATTR_CAPACITY);
271  int openingHour = attrs.getInt(AGEN_ATTR_OPENING);
272  int closingHour = attrs.getInt(AGEN_ATTR_CLOSING);
273  AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
274  myCity.schools.push_back(sch);
275 
276  } catch (const std::exception& e) {
277  WRITE_ERROR("Error while parsing the element " +
278  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " +
279  e.what());
280  throw ProcessError();
281  }
282 }
283 
284 void
286  try {
287  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
288  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
289  int id = attrs.getInt(SUMO_ATTR_ID);
290  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
291  myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi));
292 
293  } catch (const std::exception& e) {
294  WRITE_ERROR("Error while parsing the element " +
296  e.what());
297  throw ProcessError();
298  }
299 }
300 
301 void
303  try {
304  myCurrentObject = "busLine";
305  AGBusLine busL(attrs.getString(SUMO_ATTR_ID));
307  myCity.busLines.push_front(busL);
308  currentBusLine = &*myCity.busLines.begin();
309 
310  } catch (const std::exception& e) {
311  WRITE_ERROR("Error while parsing the element " +
312  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " +
313  e.what());
314  throw ProcessError();
315  }
316 }
317 
318 void
320  isRevStation = false;
321 }
322 
323 void
325  isRevStation = true;
326 }
327 
328 void
330  if (myCurrentObject != "busLine") {
331  return;
332  }
333 
334  try {
335  bool ok = true;
336  int refID = attrs.get<int>(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok);
337  if (!ok) {
338  throw ProcessError();
339  }
340  if (!isRevStation) {
342  } else {
344  }
345 
346  } catch (const std::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 std::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 //TODO beginAge needs to be evaluated
383 // int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
384  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket
385  if (myCurrentObject == "population") {
387  }
388 
389  } catch (const std::exception& e) {
390  WRITE_ERROR("Error while parsing the element " +
391  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " +
392  e.what());
393  throw ProcessError();
394  }
395 }
396 
397 /****************************************************************************/
398 
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:165
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:63
AGDataAndStatistics & statData
Definition: AGCity.h:88
std::map< int, SUMOReal > endWorkHours
A model of the street in the city.
Definition: AGStreet.h:60
void parseSchool(const SUMOSAXAttributes &attrs)
void parseBusStation(const SUMOSAXAttributes &attrs)
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:394
void locateRevStation(AGPosition pos)
Definition: AGBusLine.cpp:145
std::list< AGBusLine > busLines
Definition: AGCity.h:92
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:60
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:91
void parseBusLine(const SUMOSAXAttributes &attrs)
void parseParameters(const SUMOSAXAttributes &attrs)
std::vector< AGStreet * > streets
Definition: AGCity.h:89
void parseFrequency(const SUMOSAXAttributes &attrs)
AGCity & myCity
The city to store the information into.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
std::map< int, SUMOReal > beginWorkHours
void parseBracket(const SUMOSAXAttributes &attrs)
The router's network representation.
Definition: RONet.h:76
void parseClosingHour(const SUMOSAXAttributes &attrs)
std::map< int, SUMOReal > population
SUMOReal getLength() const
Returns the length of the edge.
Definition: ROEdge.h:198
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.
void setWorkplaceNumber(const SUMOReal work)
Modifies the number of work places in this street.
Definition: AGStreet.cpp:74
std::map< int, SUMOReal > incoming
#define SUMOReal
Definition: config.h:214
void setPopulation(const SUMOReal pop)
Modifies the number of persons living in this street.
Definition: AGStreet.cpp:62
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:94
std::map< int, AGPosition > busStations