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 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 {
141  bool ok;
144  myCity.statData.limitAgeChildren = attrs.getOpt<int>(AGEN_ATTR_CHILDREN, 0, ok, 18);
146  myCity.statData.carRate = attrs.getOpt<SUMOReal>(AGEN_ATTR_CARS, 0, ok, 0.58);
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 {
162  bool ok;
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  std::string eid = attrs.getString(SUMO_ATTR_EDGE);
189  ROEdge* e = net->getEdge(eid);
190  if (e == 0) {
191  WRITE_ERROR("Edge '" + eid + "' is not known.");
192  return;
193  }
194 
195  AGStreet str(e, pop, work);
196  myCity.streets.push_back(str);
197 
198  } catch (const exception& e) {
199  WRITE_ERROR("Error while parsing the element " +
200  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
201  e.what());
202  throw ProcessError();
203  }
204 }
205 
206 void
208  try {
209  string edge = attrs.getString(SUMO_ATTR_EDGE);
210  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
211  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
214  myCity.cityGates.push_back(posi);
215 
216  } catch (const exception& e) {
217  WRITE_ERROR("Error while parsing the element " +
218  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " +
219  e.what());
220  throw ProcessError();
221  }
222 }
223 
224 void
226  myCurrentObject = "workHours";
227 }
228 
229 void
231  if (myCurrentObject == "workHours") {
232  try {
234 
235  } catch (const exception& e) {
236  WRITE_ERROR("Error while parsing the element " +
238  + e.what());
239  throw ProcessError();
240  }
241  }
242 }
243 
244 void
246  if (myCurrentObject == "workHours") {
247  try {
249 
250  } catch (const exception& e) {
251  WRITE_ERROR("Error while parsing the element " +
253  + e.what());
254  throw ProcessError();
255  }
256  }
257 }
258 
259 void
261  myCurrentObject = "schools";
262 }
263 
264 void
266  try {
267  string edge = attrs.getString(SUMO_ATTR_EDGE);
268  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
269  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
270  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE);
271  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE);
272  int capacity = attrs.getInt(AGEN_ATTR_CAPACITY);
273  int openingHour = attrs.getInt(AGEN_ATTR_OPENING);
274  int closingHour = attrs.getInt(AGEN_ATTR_CLOSING);
275  AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
276  myCity.schools.push_back(sch);
277 
278  } catch (const exception& e) {
279  WRITE_ERROR("Error while parsing the element " +
280  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " +
281  e.what());
282  throw ProcessError();
283  }
284 }
285 
286 void
288  try {
289  string edge = attrs.getString(SUMO_ATTR_EDGE);
290  SUMOReal positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
291  int id = attrs.getInt(SUMO_ATTR_ID);
292  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
293  myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi));
294 
295  } catch (const exception& e) {
296  WRITE_ERROR("Error while parsing the element " +
298  e.what());
299  throw ProcessError();
300  }
301 }
302 
303 void
305  try {
306  myCurrentObject = "busLine";
307  AGBusLine busL(attrs.getString(SUMO_ATTR_ID));
309  myCity.busLines.push_front(busL);
310  currentBusLine = &*myCity.busLines.begin();
311 
312  } catch (const exception& e) {
313  WRITE_ERROR("Error while parsing the element " +
314  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " +
315  e.what());
316  throw ProcessError();
317  }
318 }
319 
320 void
322  isRevStation = false;
323 }
324 
325 void
327  isRevStation = true;
328 }
329 
330 void
332  if (myCurrentObject != "busLine") {
333  return;
334  }
335 
336  try {
337  bool ok = true;
338  int refID = attrs.get<int>(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok);
339  if (!ok) {
340  throw ProcessError();
341  }
342  if (!isRevStation) {
344  } else {
346  }
347 
348  } catch (const exception& e) {
349  WRITE_ERROR("Error while parsing the element " +
350  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STATION) + ": " +
351  e.what());
352  throw ProcessError();
353  }
354 }
355 
356 void
358  if (myCurrentObject != "busLine") {
359  return;
360  }
361 
362  try {
363  int beginB = attrs.getInt(SUMO_ATTR_BEGIN);
364  int endB = attrs.getInt(SUMO_ATTR_END);
365  int rateB = attrs.getInt(AGEN_ATTR_RATE);
366  currentBusLine->generateBuses(beginB, endB, rateB);
367 
368  } catch (const exception& e) {
369  WRITE_ERROR("Error while parsing the element " +
370  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_FREQUENCY) + ": " +
371  e.what());
372  throw ProcessError();
373  }
374 }
375 
376 void
378  myCurrentObject = "population";
379 }
380 
381 void
383  try {
384 //TODO beginAge needs to be evaluated
385 // int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
386  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket
387  if (myCurrentObject == "population") {
389  }
390 
391  } catch (const exception& e) {
392  WRITE_ERROR("Error while parsing the element " +
393  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " +
394  e.what());
395  throw ProcessError();
396  }
397 }
398 
399 /****************************************************************************/
400 
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:101
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:221
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