SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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-2014 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>
42
#include <
utils/options/OptionsCont.h
>
43
#include <
utils/common/MsgHandler.h
>
44
#include <
utils/common/StringTokenizer.h
>
45
#include <
utils/common/UtilExceptions.h
>
46
#include <
utils/xml/SUMOSAXHandler.h
>
47
#include <
utils/xml/SUMOXMLDefinitions.h
>
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
// ===========================================================================
62
AGActivityGenHandler::AGActivityGenHandler
(
AGCity
& city,
RONet
* net)
63
:
SUMOSAXHandler
(
"sumo-stat"
),
64
myCity(city), net(net) {}
65
66
67
AGActivityGenHandler::~AGActivityGenHandler
() {}
68
69
70
void
71
AGActivityGenHandler::myStartElement
(
int
element,
const
SUMOSAXAttributes
& attrs) {
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
:
81
parseWorkHours
();
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
;
95
case
AGEN_TAG_BUSSTATION
:
96
parseBusStation
(attrs);
97
break
;
98
case
AGEN_TAG_BUSLINE
:
99
parseBusLine
(attrs);
100
break
;
101
case
AGEN_TAG_STATIONS
:
102
parseStations
();
103
break
;
104
case
AGEN_TAG_REV_STATIONS
:
105
parseRevStations
();
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
138
AGActivityGenHandler::parseGeneralCityInfo
(
const
SUMOSAXAttributes
& attrs) {
139
try
{
140
bool
ok;
141
myCity
.
statData
.
inhabitants
= attrs.
getInt
(
AGEN_ATTR_INHABITANTS
);
142
myCity
.
statData
.
households
= attrs.
getInt
(
AGEN_ATTR_HOUSEHOLDS
);
143
myCity
.
statData
.
limitAgeChildren
= attrs.
getOpt
<
int
>(
AGEN_ATTR_CHILDREN
, 0, ok, 18);
144
myCity
.
statData
.
limitAgeRetirement
= attrs.
getOpt
<
int
>(
AGEN_ATTR_RETIREMENT
, 0, ok, 63);
145
myCity
.
statData
.
carRate
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_CARS
, 0, ok, 0.58);
146
myCity
.
statData
.
unemployement
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_UNEMPLOYEMENT
, 0, ok, 0.06);
147
myCity
.
statData
.
maxFootDistance
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_MAX_FOOT_DIST
, 0, ok, 300.0);
148
myCity
.
statData
.
incomingTraffic
= attrs.
getOpt
<
int
>(
AGEN_ATTR_IN_TRAFFIC
, 0, ok, 0);
149
myCity
.
statData
.
outgoingTraffic
= attrs.
getOpt
<
int
>(
AGEN_ATTR_OUT_TRAFFIC
, 0, ok, 0);
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
159
AGActivityGenHandler::parseParameters
(
const
SUMOSAXAttributes
& attrs) {
160
try
{
161
bool
ok;
162
myCity
.
statData
.
carPreference
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_CARPREF
, 0, ok, 0.0);
163
myCity
.
statData
.
speedTimePerKm
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_CITYSPEED
, 0, ok, 360.0);
164
myCity
.
statData
.
freeTimeActivityRate
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_FREETIMERATE
, 0, ok, 0.15);
165
myCity
.
statData
.
uniformRandomTrafficRate
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_UNI_RAND_TRAFFIC
, 0, ok, 0.0);
166
myCity
.
statData
.
departureVariation
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_DEP_VARIATION
, 0, ok, 0.0);
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
176
AGActivityGenHandler::parseStreets
(
const
SUMOSAXAttributes
& attrs) {
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
}
184
if
(attrs.
hasAttribute
(
AGEN_ATTR_OUT_WORKPOSITION
)) {
185
work = attrs.
getFloat
(
AGEN_ATTR_OUT_WORKPOSITION
);
186
}
187
std::string eid = attrs.
getString
(
SUMO_ATTR_EDGE
);
188
ROEdge
* e =
net
->
getEdge
(eid);
189
if
(e == 0) {
190
WRITE_ERROR
(
"Edge '"
+ eid +
"' is not known."
);
191
return
;
192
}
193
194
AGStreet
str(e, pop, work);
195
myCity
.
streets
.push_back(str);
196
197
}
catch
(
const
std::exception& e) {
198
WRITE_ERROR
(
"Error while parsing the element "
+
199
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_STREET
) +
": "
+
200
e.what());
201
throw
ProcessError
();
202
}
203
}
204
205
void
206
AGActivityGenHandler::parseCityGates
(
const
SUMOSAXAttributes
& attrs) {
207
try
{
208
std::string edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
209
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
210
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
211
myCity
.
statData
.
incoming
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_INCOMING
);
212
myCity
.
statData
.
outgoing
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_OUTGOING
);
213
myCity
.
cityGates
.push_back(posi);
214
215
}
catch
(
const
std::exception& e) {
216
WRITE_ERROR
(
"Error while parsing the element "
+
217
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_CITYGATES
) +
": "
+
218
e.what());
219
throw
ProcessError
();
220
}
221
}
222
223
void
224
AGActivityGenHandler::parseWorkHours
() {
225
myCurrentObject
=
"workHours"
;
226
}
227
228
void
229
AGActivityGenHandler::parseOpeningHour
(
const
SUMOSAXAttributes
& attrs) {
230
if
(
myCurrentObject
==
"workHours"
) {
231
try
{
232
myCity
.
statData
.
beginWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
233
234
}
catch
(
const
std::exception& e) {
235
WRITE_ERROR
(
"Error while parsing the element "
+
236
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_OPENING
) +
": "
237
+ e.what());
238
throw
ProcessError
();
239
}
240
}
241
}
242
243
void
244
AGActivityGenHandler::parseClosingHour
(
const
SUMOSAXAttributes
& attrs) {
245
if
(
myCurrentObject
==
"workHours"
) {
246
try
{
247
myCity
.
statData
.
endWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
248
249
}
catch
(
const
std::exception& e) {
250
WRITE_ERROR
(
"Error while parsing the element "
+
251
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_CLOSING
) +
": "
252
+ e.what());
253
throw
ProcessError
();
254
}
255
}
256
}
257
258
void
259
AGActivityGenHandler::parseSchools
() {
260
myCurrentObject
=
"schools"
;
261
}
262
263
void
264
AGActivityGenHandler::parseSchool
(
const
SUMOSAXAttributes
& attrs) {
265
try
{
266
std::string edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
267
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
268
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
269
int
beginAge = attrs.
getInt
(
AGEN_ATTR_BEGINAGE
);
270
int
endAge = attrs.
getInt
(
AGEN_ATTR_ENDAGE
);
271
int
capacity = attrs.
getInt
(
AGEN_ATTR_CAPACITY
);
272
int
openingHour = attrs.
getInt
(
AGEN_ATTR_OPENING
);
273
int
closingHour = attrs.
getInt
(
AGEN_ATTR_CLOSING
);
274
AGSchool
sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
275
myCity
.
schools
.push_back(sch);
276
277
}
catch
(
const
std::exception& e) {
278
WRITE_ERROR
(
"Error while parsing the element "
+
279
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_SCHOOL
) +
": "
+
280
e.what());
281
throw
ProcessError
();
282
}
283
}
284
285
void
286
AGActivityGenHandler::parseBusStation
(
const
SUMOSAXAttributes
& attrs) {
287
try
{
288
std::string edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
289
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
290
int
id
= attrs.
getInt
(
SUMO_ATTR_ID
);
291
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
292
myCity
.
statData
.
busStations
.insert(std::pair<int, AGPosition>(
id
, posi));
293
294
}
catch
(
const
std::exception& e) {
295
WRITE_ERROR
(
"Error while parsing the element "
+
296
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BUSSTATION
) +
": "
+
297
e.what());
298
throw
ProcessError
();
299
}
300
}
301
302
void
303
AGActivityGenHandler::parseBusLine
(
const
SUMOSAXAttributes
& attrs) {
304
try
{
305
myCurrentObject
=
"busLine"
;
306
AGBusLine
busL(attrs.
getString
(
SUMO_ATTR_ID
));
307
busL.
setMaxTripTime
(attrs.
getInt
(
AGEN_ATTR_MAX_TRIP_DURATION
));
308
myCity
.
busLines
.push_front(busL);
309
currentBusLine
= &*
myCity
.
busLines
.begin();
310
311
}
catch
(
const
std::exception& e) {
312
WRITE_ERROR
(
"Error while parsing the element "
+
313
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BUSLINE
) +
": "
+
314
e.what());
315
throw
ProcessError
();
316
}
317
}
318
319
void
320
AGActivityGenHandler::parseStations
() {
321
isRevStation
=
false
;
322
}
323
324
void
325
AGActivityGenHandler::parseRevStations
() {
326
isRevStation
=
true
;
327
}
328
329
void
330
AGActivityGenHandler::parseStation
(
const
SUMOSAXAttributes
& attrs) {
331
if
(
myCurrentObject
!=
"busLine"
) {
332
return
;
333
}
334
335
try
{
336
bool
ok =
true
;
337
int
refID = attrs.
get
<
int
>(
SUMO_ATTR_REFID
,
myCurrentObject
.c_str(), ok);
338
if
(!ok) {
339
throw
ProcessError
();
340
}
341
if
(!
isRevStation
) {
342
currentBusLine
->
locateStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
343
}
else
{
344
currentBusLine
->
locateRevStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
345
}
346
347
}
catch
(
const
std::exception& e) {
348
WRITE_ERROR
(
"Error while parsing the element "
+
349
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_STATION
) +
": "
+
350
e.what());
351
throw
ProcessError
();
352
}
353
}
354
355
void
356
AGActivityGenHandler::parseFrequency
(
const
SUMOSAXAttributes
& attrs) {
357
if
(
myCurrentObject
!=
"busLine"
) {
358
return
;
359
}
360
361
try
{
362
int
beginB = attrs.
getInt
(
SUMO_ATTR_BEGIN
);
363
int
endB = attrs.
getInt
(
SUMO_ATTR_END
);
364
int
rateB = attrs.
getInt
(
AGEN_ATTR_RATE
);
365
currentBusLine
->
generateBuses
(beginB, endB, rateB);
366
367
}
catch
(
const
std::exception& e) {
368
WRITE_ERROR
(
"Error while parsing the element "
+
369
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_FREQUENCY
) +
": "
+
370
e.what());
371
throw
ProcessError
();
372
}
373
}
374
375
void
376
AGActivityGenHandler::parsePopulation
() {
377
myCurrentObject
=
"population"
;
378
}
379
380
void
381
AGActivityGenHandler::parseBracket
(
const
SUMOSAXAttributes
& attrs) {
382
try
{
383
//TODO beginAge needs to be evaluated
384
// int beginAge = attrs.getInt(AGEN_ATTR_BEGINAGE); //included in the bracket
385
int
endAge = attrs.
getInt
(
AGEN_ATTR_ENDAGE
);
//NOT included in the bracket
386
if
(
myCurrentObject
==
"population"
) {
387
myCity
.
statData
.
population
[endAge] = attrs.
getInt
(
AGEN_ATTR_PEOPLENBR
);
388
}
389
390
}
catch
(
const
std::exception& e) {
391
WRITE_ERROR
(
"Error while parsing the element "
+
392
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BRACKET
) +
": "
+
393
e.what());
394
throw
ProcessError
();
395
}
396
}
397
398
/****************************************************************************/
399
tmp
buildd
sumo-0.21.0+dfsg
src
activitygen
AGActivityGenHandler.cpp
Generated on Thu Nov 20 2014 19:49:52 for SUMO - Simulation of Urban MObility by
1.8.1.2