SUMO - Simulation of Urban MObility
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-2017 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 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
59  : SUMOSAXHandler("sumo-stat"),
60  myCity(city), net(net) {}
61 
62 
64 
65 
66 void
68  try {
69  switch (element) {
70  case AGEN_TAG_GENERAL:
71  parseGeneralCityInfo(attrs);
72  break;
73  case AGEN_TAG_STREET:
74  parseStreets(attrs);
75  break;
76  case AGEN_TAG_WORKHOURS:
78  break;
79  case AGEN_TAG_OPENING:
80  parseOpeningHour(attrs);
81  break;
82  case AGEN_TAG_CLOSING:
83  parseClosingHour(attrs);
84  break;
85  case AGEN_TAG_SCHOOLS:
86  parseSchools();
87  break;
88  case AGEN_TAG_SCHOOL:
89  parseSchool(attrs);
90  break;
92  parseBusStation(attrs);
93  break;
94  case AGEN_TAG_BUSLINE:
95  parseBusLine(attrs);
96  break;
97  case AGEN_TAG_STATIONS:
98  parseStations();
99  break;
102  break;
103  case AGEN_TAG_STATION:
104  parseStation(attrs);
105  break;
106  case AGEN_TAG_FREQUENCY:
107  parseFrequency(attrs);
108  break;
109  case AGEN_TAG_POPULATION:
110  parsePopulation();
111  break;
112  /*case AGEN_TAG_CHILD_ACOMP:
113  parseChildrenAccompaniment();
114  break;*/
115  case AGEN_TAG_BRACKET:
116  parseBracket(attrs);
117  break;
118  case AGEN_TAG_PARAM:
119  parseParameters(attrs);
120  break;
121  case AGEN_TAG_ENTRANCE:
122  parseCityGates(attrs);
123  break;
124  default:
125  break;
126  }
127  } catch (const std::exception& e) {
128  throw ProcessError(e.what());
129  }
130 }
131 
132 
133 void
135  try {
136  bool ok;
139  myCity.statData.limitAgeChildren = attrs.getOpt<int>(AGEN_ATTR_CHILDREN, 0, ok, 18);
141  myCity.statData.carRate = attrs.getOpt<double>(AGEN_ATTR_CARS, 0, ok, 0.58);
142  myCity.statData.unemployement = attrs.getOpt<double>(AGEN_ATTR_UNEMPLOYEMENT, 0, ok, 0.06);
143  myCity.statData.maxFootDistance = attrs.getOpt<double>(AGEN_ATTR_MAX_FOOT_DIST, 0, ok, 300.0);
146  } catch (const std::exception& e) {
147  WRITE_ERROR("Error while parsing the element " +
148  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_GENERAL) + ": " +
149  e.what());
150  throw ProcessError();
151  }
152 }
153 
154 void
156  try {
157  bool ok;
158  myCity.statData.carPreference = attrs.getOpt<double>(AGEN_ATTR_CARPREF, 0, ok, 0.0);
159  myCity.statData.speedTimePerKm = attrs.getOpt<double>(AGEN_ATTR_CITYSPEED, 0, ok, 360.0);
160  myCity.statData.freeTimeActivityRate = attrs.getOpt<double>(AGEN_ATTR_FREETIMERATE, 0, ok, 0.15);
162  myCity.statData.departureVariation = attrs.getOpt<double>(AGEN_ATTR_DEP_VARIATION, 0, ok, 0.0);
163  } catch (const std::exception& e) {
164  WRITE_ERROR("Error while parsing the element " +
165  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_PARAM) + ": " +
166  e.what());
167  throw ProcessError();
168  }
169 }
170 
171 void
173  try {
174  double pop = 0;
175  double work = 0;
176 
177  if (attrs.hasAttribute(AGEN_ATTR_POPULATION)) {
178  pop = attrs.getFloat(AGEN_ATTR_POPULATION);
179  }
181  work = attrs.getFloat(AGEN_ATTR_OUT_WORKPOSITION);
182  }
183  std::string eid = attrs.getString(SUMO_ATTR_EDGE);
184  AGStreet* street = dynamic_cast<AGStreet*>(net->getEdge(eid));
185  if (street == 0) {
186  WRITE_ERROR("Edge '" + eid + "' is not known.");
187  return;
188  }
189  street->setPopulation(pop * street->getLength());
190  street->setWorkplaceNumber(work * street->getLength());
191  myCity.streets.push_back(street);
192  } catch (const std::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  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
204  double positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
205  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
208  myCity.cityGates.push_back(posi);
209 
210  } catch (const std::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 std::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 std::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  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
262  double 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 std::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  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
284  double 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 std::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 std::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.get<int>(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok);
333  if (!ok) {
334  throw ProcessError();
335  }
336  if (!isRevStation) {
338  } else {
340  }
341 
342  } catch (const std::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 std::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 std::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 
void generateBuses(int start, int stop, int rate)
Definition: AGBusLine.cpp:150
void setMaxTripTime(int time)
Definition: AGBusLine.cpp:55
std::map< int, double > outgoing
AGActivityGenHandler(AGCity &city, RONet *net)
Constructor.
std::string myCurrentObject
The name of the object that is currently processed.
ActivityGen Tags.
void parseCityGates(const SUMOSAXAttributes &attrs)
void parseGeneralCityInfo(const SUMOSAXAttributes &attrs)
void parseStation(const SUMOSAXAttributes &attrs)
void setWorkplaceNumber(const double work)
Modifies the number of work places in this street.
Definition: AGStreet.cpp:74
workingHours object
closing for workingHours object
population and children accompaniment brackets
A location in the 2D plane freely positioned on a street.
Definition: AGPosition.h:63
std::map< int, double > population
AGDataAndStatistics & statData
Definition: AGCity.h:88
weights: time range begin
A model of the street in the city.
Definition: AGStreet.h:60
void parseSchool(const SUMOSAXAttributes &attrs)
void parseBusStation(const SUMOSAXAttributes &attrs)
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:198
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:403
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.
alternative definition for Population
void locateStation(AGPosition pos)
Definition: AGBusLine.cpp:140
Definition: AGCity.h:60
station for a certain vehicle
std::map< int, double > beginWorkHours
rev stations for certain vehicles
frequency of a object
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
std::map< int, double > incoming
schools object
std::list< AGSchool > schools
Definition: AGCity.h:91
busStation and bus objects
std::map< int, double > endWorkHours
void parseBusLine(const SUMOSAXAttributes &attrs)
void parseParameters(const SUMOSAXAttributes &attrs)
std::vector< AGStreet * > streets
Definition: AGCity.h:89
streets object
void parseFrequency(const SUMOSAXAttributes &attrs)
AGCity & myCity
The city to store the information into.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
virtual double getFloat(int id) const =0
Returns the double-value of the named (by its enum-value) attribute.
void parseBracket(const SUMOSAXAttributes &attrs)
void setPopulation(const double pop)
Modifies the number of persons living in this street.
Definition: AGStreet.cpp:62
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.
The router&#39;s network representation.
Definition: RONet.h:76
void parseClosingHour(const SUMOSAXAttributes &attrs)
alternative definition for city entrances
weights: time range end
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.
static StringBijection< int > Tags
The names of SUMO-XML elements for use in netbuild.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
Definition: RONet.h:165
opening for workingHours object
std::vector< AGPosition > cityGates
Definition: AGCity.h:94
std::map< int, AGPosition > busStations
stations for certain vehicles