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-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>
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
using namespace
std;
59
60
// ===========================================================================
61
// method definitions
62
// ===========================================================================
63
AGActivityGenHandler::AGActivityGenHandler
(
AGCity
& city,
RONet
* net)
64
:
SUMOSAXHandler
(
"sumo-stat"
),
65
myCity(city), net(net) {}
66
67
68
AGActivityGenHandler::~AGActivityGenHandler
() {}
69
70
71
void
72
AGActivityGenHandler::myStartElement
(
int
element,
const
SUMOSAXAttributes
& attrs) {
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
:
82
parseWorkHours
();
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
;
96
case
AGEN_TAG_BUSSTATION
:
97
parseBusStation
(attrs);
98
break
;
99
case
AGEN_TAG_BUSLINE
:
100
parseBusLine
(attrs);
101
break
;
102
case
AGEN_TAG_STATIONS
:
103
parseStations
();
104
break
;
105
case
AGEN_TAG_REV_STATIONS
:
106
parseRevStations
();
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
139
AGActivityGenHandler::parseGeneralCityInfo
(
const
SUMOSAXAttributes
& attrs) {
140
try
{
141
bool
ok;
142
myCity
.
statData
.
inhabitants
= attrs.
getInt
(
AGEN_ATTR_INHABITANTS
);
143
myCity
.
statData
.
households
= attrs.
getInt
(
AGEN_ATTR_HOUSEHOLDS
);
144
myCity
.
statData
.
limitAgeChildren
= attrs.
getOpt
<
int
>(
AGEN_ATTR_CHILDREN
, 0, ok, 18);
145
myCity
.
statData
.
limitAgeRetirement
= attrs.
getOpt
<
int
>(
AGEN_ATTR_RETIREMENT
, 0, ok, 63);
146
myCity
.
statData
.
carRate
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_CARS
, 0, ok, 0.58);
147
myCity
.
statData
.
unemployement
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_UNEMPLOYEMENT
, 0, ok, 0.06);
148
myCity
.
statData
.
maxFootDistance
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_MAX_FOOT_DIST
, 0, ok, 300.0);
149
myCity
.
statData
.
incomingTraffic
= attrs.
getOpt
<
int
>(
AGEN_ATTR_IN_TRAFFIC
, 0, ok, 0);
150
myCity
.
statData
.
outgoingTraffic
= attrs.
getOpt
<
int
>(
AGEN_ATTR_OUT_TRAFFIC
, 0, ok, 0);
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
160
AGActivityGenHandler::parseParameters
(
const
SUMOSAXAttributes
& attrs) {
161
try
{
162
bool
ok;
163
myCity
.
statData
.
carPreference
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_CARPREF
, 0, ok, 0.0);
164
myCity
.
statData
.
speedTimePerKm
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_CITYSPEED
, 0, ok, 360.0);
165
myCity
.
statData
.
freeTimeActivityRate
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_FREETIMERATE
, 0, ok, 0.15);
166
myCity
.
statData
.
uniformRandomTrafficRate
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_UNI_RAND_TRAFFIC
, 0, ok, 0.0);
167
myCity
.
statData
.
departureVariation
= attrs.
getOpt
<
SUMOReal
>(
AGEN_ATTR_DEP_VARIATION
, 0, ok, 0.0);
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
177
AGActivityGenHandler::parseStreets
(
const
SUMOSAXAttributes
& attrs) {
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
}
185
if
(attrs.
hasAttribute
(
AGEN_ATTR_OUT_WORKPOSITION
)) {
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
207
AGActivityGenHandler::parseCityGates
(
const
SUMOSAXAttributes
& attrs) {
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);
212
myCity
.
statData
.
incoming
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_INCOMING
);
213
myCity
.
statData
.
outgoing
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_OUTGOING
);
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
225
AGActivityGenHandler::parseWorkHours
() {
226
myCurrentObject
=
"workHours"
;
227
}
228
229
void
230
AGActivityGenHandler::parseOpeningHour
(
const
SUMOSAXAttributes
& attrs) {
231
if
(
myCurrentObject
==
"workHours"
) {
232
try
{
233
myCity
.
statData
.
beginWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
234
235
}
catch
(
const
exception& e) {
236
WRITE_ERROR
(
"Error while parsing the element "
+
237
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_OPENING
) +
": "
238
+ e.what());
239
throw
ProcessError
();
240
}
241
}
242
}
243
244
void
245
AGActivityGenHandler::parseClosingHour
(
const
SUMOSAXAttributes
& attrs) {
246
if
(
myCurrentObject
==
"workHours"
) {
247
try
{
248
myCity
.
statData
.
endWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
249
250
}
catch
(
const
exception& e) {
251
WRITE_ERROR
(
"Error while parsing the element "
+
252
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_CLOSING
) +
": "
253
+ e.what());
254
throw
ProcessError
();
255
}
256
}
257
}
258
259
void
260
AGActivityGenHandler::parseSchools
() {
261
myCurrentObject
=
"schools"
;
262
}
263
264
void
265
AGActivityGenHandler::parseSchool
(
const
SUMOSAXAttributes
& attrs) {
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
287
AGActivityGenHandler::parseBusStation
(
const
SUMOSAXAttributes
& attrs) {
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 "
+
297
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BUSSTATION
) +
": "
+
298
e.what());
299
throw
ProcessError
();
300
}
301
}
302
303
void
304
AGActivityGenHandler::parseBusLine
(
const
SUMOSAXAttributes
& attrs) {
305
try
{
306
myCurrentObject
=
"busLine"
;
307
AGBusLine
busL(attrs.
getString
(
SUMO_ATTR_ID
));
308
busL.
setMaxTripTime
(attrs.
getInt
(
AGEN_ATTR_MAX_TRIP_DURATION
));
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
321
AGActivityGenHandler::parseStations
() {
322
isRevStation
=
false
;
323
}
324
325
void
326
AGActivityGenHandler::parseRevStations
() {
327
isRevStation
=
true
;
328
}
329
330
void
331
AGActivityGenHandler::parseStation
(
const
SUMOSAXAttributes
& attrs) {
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
) {
343
currentBusLine
->
locateStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
344
}
else
{
345
currentBusLine
->
locateRevStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
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
357
AGActivityGenHandler::parseFrequency
(
const
SUMOSAXAttributes
& attrs) {
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
377
AGActivityGenHandler::parsePopulation
() {
378
myCurrentObject
=
"population"
;
379
}
380
381
void
382
AGActivityGenHandler::parseBracket
(
const
SUMOSAXAttributes
& attrs) {
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"
) {
388
myCity
.
statData
.
population
[endAge] = attrs.
getInt
(
AGEN_ATTR_PEOPLENBR
);
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
build
buildd
sumo-0.18~dfsg
src
activitygen
AGActivityGenHandler.cpp
Generated on Wed Oct 23 2013 01:15:07 for SUMO - Simulation of Urban MObility by
1.8.4