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-2018 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 // SPDX-License-Identifier: EPL-2.0
11 /****************************************************************************/
21 // The handler for parsing the statistics file.
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include "AGActivityGenHandler.h"
31 #include <iostream>
32 #include <utility>
33 #include <map>
34 #include <string>
41 #include <router/RONet.h>
42 #include "city/AGCity.h"
43 #include "city/AGSchool.h"
44 #include "city/AGPosition.h"
45 #include "city/AGBusLine.h"
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
52  : SUMOSAXHandler("sumo-stat"),
53  myCity(city), net(net) {}
54 
55 
57 
58 
59 void
61  try {
62  switch (element) {
63  case AGEN_TAG_GENERAL:
64  parseGeneralCityInfo(attrs);
65  break;
66  case AGEN_TAG_STREET:
67  parseStreets(attrs);
68  break;
69  case AGEN_TAG_WORKHOURS:
71  break;
72  case AGEN_TAG_OPENING:
73  parseOpeningHour(attrs);
74  break;
75  case AGEN_TAG_CLOSING:
76  parseClosingHour(attrs);
77  break;
78  case AGEN_TAG_SCHOOLS:
79  parseSchools();
80  break;
81  case AGEN_TAG_SCHOOL:
82  parseSchool(attrs);
83  break;
85  parseBusStation(attrs);
86  break;
87  case AGEN_TAG_BUSLINE:
88  parseBusLine(attrs);
89  break;
90  case AGEN_TAG_STATIONS:
91  parseStations();
92  break;
95  break;
96  case AGEN_TAG_STATION:
97  parseStation(attrs);
98  break;
99  case AGEN_TAG_FREQUENCY:
100  parseFrequency(attrs);
101  break;
102  case AGEN_TAG_POPULATION:
103  parsePopulation();
104  break;
105  /*case AGEN_TAG_CHILD_ACOMP:
106  parseChildrenAccompaniment();
107  break;*/
108  case AGEN_TAG_BRACKET:
109  parseBracket(attrs);
110  break;
111  case AGEN_TAG_PARAM:
112  parseParameters(attrs);
113  break;
114  case AGEN_TAG_ENTRANCE:
115  parseCityGates(attrs);
116  break;
117  default:
118  break;
119  }
120  } catch (const std::exception& e) {
121  throw ProcessError(e.what());
122  }
123 }
124 
125 
126 void
128  try {
129  bool ok;
132  myCity.statData.limitAgeChildren = attrs.getOpt<int>(AGEN_ATTR_CHILDREN, nullptr, ok, 18);
133  myCity.statData.limitAgeRetirement = attrs.getOpt<int>(AGEN_ATTR_RETIREMENT, nullptr, ok, 63);
134  myCity.statData.carRate = attrs.getOpt<double>(AGEN_ATTR_CARS, nullptr, ok, 0.58);
135  myCity.statData.unemployement = attrs.getOpt<double>(AGEN_ATTR_UNEMPLOYEMENT, nullptr, ok, 0.06);
136  myCity.statData.laborDemand = attrs.getOpt<double>(AGEN_ATTR_LABORDEMAND, nullptr, ok, 1.05);
137  myCity.statData.maxFootDistance = attrs.getOpt<double>(AGEN_ATTR_MAX_FOOT_DIST, nullptr, ok, 300.0);
138  myCity.statData.incomingTraffic = attrs.getOpt<int>(AGEN_ATTR_IN_TRAFFIC, nullptr, ok, 0);
139  myCity.statData.outgoingTraffic = attrs.getOpt<int>(AGEN_ATTR_OUT_TRAFFIC, nullptr, ok, 0);
140  } catch (const std::exception& e) {
141  WRITE_ERROR("Error while parsing the element " +
142  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_GENERAL) + ": " +
143  e.what());
144  throw ProcessError();
145  }
146 }
147 
148 void
150  try {
151  bool ok;
152  myCity.statData.carPreference = attrs.getOpt<double>(AGEN_ATTR_CARPREF, nullptr, ok, 0.0);
153  myCity.statData.speedTimePerKm = attrs.getOpt<double>(AGEN_ATTR_CITYSPEED, nullptr, ok, 360.0);
154  myCity.statData.freeTimeActivityRate = attrs.getOpt<double>(AGEN_ATTR_FREETIMERATE, nullptr, ok, 0.15);
155  myCity.statData.uniformRandomTrafficRate = attrs.getOpt<double>(AGEN_ATTR_UNI_RAND_TRAFFIC, nullptr, ok, 0.0);
156  myCity.statData.departureVariation = attrs.getOpt<double>(AGEN_ATTR_DEP_VARIATION, nullptr, ok, 0.0);
157  } catch (const std::exception& e) {
158  WRITE_ERROR("Error while parsing the element " +
159  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_PARAM) + ": " +
160  e.what());
161  throw ProcessError();
162  }
163 }
164 
165 void
167  try {
168  double pop = 0;
169  double work = 0;
170 
171  if (attrs.hasAttribute(AGEN_ATTR_POPULATION)) {
172  pop = attrs.getFloat(AGEN_ATTR_POPULATION);
173  }
175  work = attrs.getFloat(AGEN_ATTR_OUT_WORKPOSITION);
176  }
177  std::string eid = attrs.getString(SUMO_ATTR_EDGE);
178  AGStreet* street = dynamic_cast<AGStreet*>(net->getEdge(eid));
179  if (street == nullptr) {
180  WRITE_ERROR("Edge '" + eid + "' is not known.");
181  return;
182  }
183  street->setPopulation(pop * street->getLength());
184  street->setWorkplaceNumber(work * street->getLength());
185  myCity.streets.push_back(street);
186  } catch (const std::exception& e) {
187  WRITE_ERROR("Error while parsing the element " +
188  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STREET) + ": " +
189  e.what());
190  throw ProcessError();
191  }
192 }
193 
194 void
196  try {
197  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
198  double positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
199  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
202  myCity.cityGates.push_back(posi);
203 
204  } catch (const std::exception& e) {
205  WRITE_ERROR("Error while parsing the element " +
206  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_CITYGATES) + ": " +
207  e.what());
208  throw ProcessError();
209  }
210 }
211 
212 void
214  myCurrentObject = "workHours";
215 }
216 
217 void
219  if (myCurrentObject == "workHours") {
220  try {
222 
223  } catch (const std::exception& e) {
224  WRITE_ERROR("Error while parsing the element " +
226  + e.what());
227  throw ProcessError();
228  }
229  }
230 }
231 
232 void
234  if (myCurrentObject == "workHours") {
235  try {
237 
238  } catch (const std::exception& e) {
239  WRITE_ERROR("Error while parsing the element " +
241  + e.what());
242  throw ProcessError();
243  }
244  }
245 }
246 
247 void
249  myCurrentObject = "schools";
250 }
251 
252 void
254  try {
255  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
256  double positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
257  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
258  int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE);
259  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE);
260  int capacity = attrs.getInt(AGEN_ATTR_CAPACITY);
261  int openingHour = attrs.getInt(AGEN_ATTR_OPENING);
262  int closingHour = attrs.getInt(AGEN_ATTR_CLOSING);
263  AGSchool sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
264  myCity.schools.push_back(sch);
265 
266  } catch (const std::exception& e) {
267  WRITE_ERROR("Error while parsing the element " +
268  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_SCHOOL) + ": " +
269  e.what());
270  throw ProcessError();
271  }
272 }
273 
274 void
276  try {
277  std::string edge = attrs.getString(SUMO_ATTR_EDGE);
278  double positionOnEdge = attrs.getFloat(SUMO_ATTR_POSITION);
279  int id = attrs.getInt(SUMO_ATTR_ID);
280  AGPosition posi(myCity.getStreet(edge), positionOnEdge);
281  myCity.statData.busStations.insert(std::pair<int, AGPosition>(id, posi));
282 
283  } catch (const std::exception& e) {
284  WRITE_ERROR("Error while parsing the element " +
286  e.what());
287  throw ProcessError();
288  }
289 }
290 
291 void
293  try {
294  myCurrentObject = "busLine";
295  AGBusLine busL(attrs.getString(SUMO_ATTR_ID));
297  myCity.busLines.push_front(busL);
298  currentBusLine = &*myCity.busLines.begin();
299 
300  } catch (const std::exception& e) {
301  WRITE_ERROR("Error while parsing the element " +
302  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BUSLINE) + ": " +
303  e.what());
304  throw ProcessError();
305  }
306 }
307 
308 void
310  isRevStation = false;
311 }
312 
313 void
315  isRevStation = true;
316 }
317 
318 void
320  if (myCurrentObject != "busLine") {
321  return;
322  }
323 
324  try {
325  bool ok = true;
326  int refID = attrs.get<int>(SUMO_ATTR_REFID, myCurrentObject.c_str(), ok);
327  if (!ok) {
328  throw ProcessError();
329  }
330  if (myCity.statData.busStations.count(refID) == 0) {
331  throw ProcessError("Unknown bus station " + toString(refID));
332  }
333  if (!isRevStation) {
335  } else {
337  }
338 
339  } catch (const std::exception& e) {
340  WRITE_ERROR("Error while parsing the element " +
341  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_STATION) + ": " +
342  e.what());
343  throw ProcessError();
344  }
345 }
346 
347 void
349  if (myCurrentObject != "busLine") {
350  return;
351  }
352 
353  try {
354  int beginB = attrs.getInt(SUMO_ATTR_BEGIN);
355  int endB = attrs.getInt(SUMO_ATTR_END);
356  int rateB = attrs.getInt(AGEN_ATTR_RATE);
357  currentBusLine->generateBuses(beginB, endB, rateB);
358 
359  } catch (const std::exception& e) {
360  WRITE_ERROR("Error while parsing the element " +
361  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_FREQUENCY) + ": " +
362  e.what());
363  throw ProcessError();
364  }
365 }
366 
367 void
369  myCurrentObject = "population";
370 }
371 
372 void
374  try {
375 //TODO beginAge needs to be evaluated
376 // int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
377  int endAge = attrs.getInt(AGEN_ATTR_ENDAGE); //NOT included in the bracket
378  if (myCurrentObject == "population") {
380  }
381 
382  } catch (const std::exception& e) {
383  WRITE_ERROR("Error while parsing the element " +
384  SUMOXMLDefinitions::Tags.getString(AGEN_TAG_BRACKET) + ": " +
385  e.what());
386  throw ProcessError();
387  }
388 }
389 
390 /****************************************************************************/
391 
void generateBuses(int start, int stop, int rate)
Definition: AGBusLine.cpp:143
void setMaxTripTime(int time)
Definition: AGBusLine.cpp:48
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:67
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:56
std::map< int, double > population
AGDataAndStatistics & statData
Definition: AGCity.h:81
weights: time range begin
A model of the street in the city.
Definition: AGStreet.h:53
void parseSchool(const SUMOSAXAttributes &attrs)
void parseBusStation(const SUMOSAXAttributes &attrs)
double getLength() const
Returns the length of the edge.
Definition: ROEdge.h:199
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:138
std::list< AGBusLine > busLines
Definition: AGCity.h:85
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:133
Definition: AGCity.h:53
station for a certain vehicle
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
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:84
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:82
streets object
void parseFrequency(const SUMOSAXAttributes &attrs)
AGCity & myCity
The city to store the information into.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
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:55
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:68
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:157
opening for workingHours object
std::vector< AGPosition > cityGates
Definition: AGCity.h:87
std::map< int, AGPosition > busStations
stations for certain vehicles