SUMO - Simulation of Urban MObility
AGActivityGenHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 /****************************************************************************/
7 //
8 // This program and the accompanying materials
9 // are made available under the terms of the Eclipse Public License v2.0
10 // which accompanies this distribution, and is available at
11 // http://www.eclipse.org/legal/epl-v20.html
12 //
13 /****************************************************************************/
23 // The handler for parsing the statistics file.
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include "AGActivityGenHandler.h"
37 #include <iostream>
38 #include <utility>
39 #include <map>
40 #include <string>
47 #include <router/RONet.h>
48 #include "city/AGCity.h"
49 #include "city/AGSchool.h"
50 #include "city/AGPosition.h"
51 #include "city/AGBusLine.h"
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  : SUMOSAXHandler("sumo-stat"),
59  myCity(city), net(net) {}
60 
61 
63 
64 
65 void
67  try {
68  switch (element) {
69  case AGEN_TAG_GENERAL:
70  parseGeneralCityInfo(attrs);
71  break;
72  case AGEN_TAG_STREET:
73  parseStreets(attrs);
74  break;
75  case AGEN_TAG_WORKHOURS:
77  break;
78  case AGEN_TAG_OPENING:
79  parseOpeningHour(attrs);
80  break;
81  case AGEN_TAG_CLOSING:
82  parseClosingHour(attrs);
83  break;
84  case AGEN_TAG_SCHOOLS:
85  parseSchools();
86  break;
87  case AGEN_TAG_SCHOOL:
88  parseSchool(attrs);
89  break;
91  parseBusStation(attrs);
92  break;
93  case AGEN_TAG_BUSLINE:
94  parseBusLine(attrs);
95  break;
96  case AGEN_TAG_STATIONS:
97  parseStations();
98  break;
101  break;
102  case AGEN_TAG_STATION:
103  parseStation(attrs);
104  break;
105  case AGEN_TAG_FREQUENCY:
106  parseFrequency(attrs);
107  break;
108  case AGEN_TAG_POPULATION:
109  parsePopulation();
110  break;
111  /*case AGEN_TAG_CHILD_ACOMP:
112  parseChildrenAccompaniment();
113  break;*/
114  case AGEN_TAG_BRACKET:
115  parseBracket(attrs);
116  break;
117  case AGEN_TAG_PARAM:
118  parseParameters(attrs);
119  break;
120  case AGEN_TAG_ENTRANCE:
121  parseCityGates(attrs);
122  break;
123  default:
124  break;
125  }
126  } catch (const std::exception& e) {
127  throw ProcessError(e.what());
128  }
129 }
130 
131 
132 void
134  try {
135  bool ok;
138  myCity.statData.limitAgeChildren = attrs.getOpt<int>(AGEN_ATTR_CHILDREN, 0, ok, 18);
140  myCity.statData.carRate = attrs.getOpt<double>(AGEN_ATTR_CARS, 0, ok, 0.58);
141  myCity.statData.unemployement = attrs.getOpt<double>(AGEN_ATTR_UNEMPLOYEMENT, 0, ok, 0.06);
142  myCity.statData.laborDemand = attrs.getOpt<double>(AGEN_ATTR_LABORDEMAND, 0, ok, 1.05);
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:149
void setMaxTripTime(int time)
Definition: AGBusLine.cpp:54
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:73
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:62
std::map< int, double > population
AGDataAndStatistics & statData
Definition: AGCity.h:87
weights: time range begin
A model of the street in the city.
Definition: AGStreet.h:59
void parseSchool(const SUMOSAXAttributes &attrs)
void parseBusStation(const SUMOSAXAttributes &attrs)
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:204
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:400
void locateRevStation(AGPosition pos)
Definition: AGBusLine.cpp:144
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.
alternative definition for Population
void locateStation(AGPosition pos)
Definition: AGBusLine.cpp:139
Definition: AGCity.h:59
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:90
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:88
streets object
void parseFrequency(const SUMOSAXAttributes &attrs)
AGCity & myCity
The city to store the information into.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
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:61
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:74
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:163
opening for workingHours object
std::vector< AGPosition > cityGates
Definition: AGCity.h:93
std::map< int, AGPosition > busStations
stations for certain vehicles