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.sourceforge.net/
14
// Copyright (C) 2001-2012 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"
), net(net),
65
myCity(city) {}
66
67
68
AGActivityGenHandler::~AGActivityGenHandler
() {}
69
70
71
void
72
AGActivityGenHandler::myStartElement
(
int
element,
const
SUMOSAXAttributes
& attrs)
73
{
74
try
{
75
switch
(element) {
76
case
AGEN_TAG_GENERAL
:
77
parseGeneralCityInfo
(attrs);
78
break
;
79
case
AGEN_TAG_STREET
:
80
parseStreets
(attrs);
81
break
;
82
case
AGEN_TAG_WORKHOURS
:
83
parseWorkHours
();
84
break
;
85
case
AGEN_TAG_OPENING
:
86
parseOpeningHour
(attrs);
87
break
;
88
case
AGEN_TAG_CLOSING
:
89
parseClosingHour
(attrs);
90
break
;
91
case
AGEN_TAG_SCHOOLS
:
92
parseSchools
();
93
break
;
94
case
AGEN_TAG_SCHOOL
:
95
parseSchool
(attrs);
96
break
;
97
case
AGEN_TAG_BUSSTATION
:
98
parseBusStation
(attrs);
99
break
;
100
case
AGEN_TAG_BUSLINE
:
101
parseBusLine
(attrs);
102
break
;
103
case
AGEN_TAG_STATIONS
:
104
parseStations
();
105
break
;
106
case
AGEN_TAG_REV_STATIONS
:
107
parseRevStations
();
108
break
;
109
case
AGEN_TAG_STATION
:
110
parseStation
(attrs);
111
break
;
112
case
AGEN_TAG_FREQUENCY
:
113
parseFrequency
(attrs);
114
break
;
115
case
AGEN_TAG_POPULATION
:
116
parsePopulation
();
117
break
;
118
/*case AGEN_TAG_CHILD_ACOMP:
119
parseChildrenAccompaniment();
120
break;*/
121
case
AGEN_TAG_BRACKET
:
122
parseBracket
(attrs);
123
break
;
124
case
AGEN_TAG_PARAM
:
125
parseParameters
(attrs);
126
break
;
127
case
AGEN_TAG_ENTRANCE
:
128
parseCityGates
(attrs);
129
break
;
130
default
:
131
break
;
132
}
133
}
catch
(
const
exception
& e) {
134
throw
ProcessError
(e.what());
135
}
136
}
137
138
139
void
140
AGActivityGenHandler::parseGeneralCityInfo
(
const
SUMOSAXAttributes
& attrs) {
141
try
{
142
myCity
.
statData
.
inhabitants
= attrs.
getInt
(
AGEN_ATTR_INHABITANTS
);
143
myCity
.
statData
.
households
= attrs.
getInt
(
AGEN_ATTR_HOUSEHOLDS
);
144
myCity
.
statData
.
limitAgeChildren
= attrs.
getIntSecure
(
AGEN_ATTR_CHILDREN
, 18);
145
myCity
.
statData
.
limitAgeRetirement
= attrs.
getIntSecure
(
AGEN_ATTR_RETIREMENT
, 63);
146
myCity
.
statData
.
carRate
= attrs.
getFloatSecure
(
AGEN_ATTR_CARS
, 0.58);
147
myCity
.
statData
.
unemployement
= attrs.
getFloatSecure
(
AGEN_ATTR_UNEMPLOYEMENT
, 0.06);
148
myCity
.
statData
.
maxFootDistance
= attrs.
getFloatSecure
(
AGEN_ATTR_MAX_FOOT_DIST
, 300.0);
149
myCity
.
statData
.
incomingTraffic
= attrs.
getIntSecure
(
AGEN_ATTR_IN_TRAFFIC
, 0);
150
myCity
.
statData
.
outgoingTraffic
= attrs.
getIntSecure
(
AGEN_ATTR_OUT_TRAFFIC
, 0);
151
152
}
catch
(
const
exception
& e) {
153
WRITE_ERROR
(
"Error while parsing the element "
+
154
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_GENERAL
) +
": "
+
155
e.what());
156
throw
ProcessError
();
157
}
158
}
159
160
void
161
AGActivityGenHandler::parseParameters
(
const
SUMOSAXAttributes
& attrs) {
162
try
{
163
myCity
.
statData
.
carPreference
= attrs.
getFloatSecure
(
AGEN_ATTR_CARPREF
, 0.0);
164
myCity
.
statData
.
speedTimePerKm
= attrs.
getFloatSecure
(
AGEN_ATTR_CITYSPEED
, 360.0);
165
myCity
.
statData
.
freeTimeActivityRate
= attrs.
getFloatSecure
(
AGEN_ATTR_FREETIMERATE
, 0.15);
166
myCity
.
statData
.
uniformRandomTrafficRate
= attrs.
getFloatSecure
(
AGEN_ATTR_UNI_RAND_TRAFFIC
, 0.0);
167
myCity
.
statData
.
departureVariation
= attrs.
getFloatSecure
(
AGEN_ATTR_DEP_VARIATION
, 0.0);
168
169
}
catch
(
const
exception
& e) {
170
WRITE_ERROR
(
"Error while parsing the element "
+
171
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_PARAM
) +
": "
+
172
e.what());
173
throw
ProcessError
();
174
}
175
}
176
177
void
178
AGActivityGenHandler::parseStreets
(
const
SUMOSAXAttributes
& attrs) {
179
try
{
180
SUMOReal
pop = 0;
181
SUMOReal
work = 0;
182
183
if
(attrs.
hasAttribute
(
AGEN_ATTR_POPULATION
)) {
184
pop = attrs.
getFloat
(
AGEN_ATTR_POPULATION
);
185
}
186
if
(attrs.
hasAttribute
(
AGEN_ATTR_OUT_WORKPOSITION
)) {
187
work = attrs.
getFloat
(
AGEN_ATTR_OUT_WORKPOSITION
);
188
}
189
190
AGStreet
str(
net
->
getEdge
(attrs.
getString
(
SUMO_ATTR_EDGE
)), pop, work);
191
myCity
.
streets
.push_back(str);
192
193
}
catch
(
const
exception
& e) {
194
WRITE_ERROR
(
"Error while parsing the element "
+
195
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_STREET
) +
": "
+
196
e.what());
197
throw
ProcessError
();
198
}
199
}
200
201
void
202
AGActivityGenHandler::parseCityGates
(
const
SUMOSAXAttributes
& attrs) {
203
try
{
204
string
edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
205
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
206
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
207
myCity
.
statData
.
incoming
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_INCOMING
);
208
myCity
.
statData
.
outgoing
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_OUTGOING
);
209
myCity
.
cityGates
.push_back(posi);
210
211
}
catch
(
const
exception
& e) {
212
WRITE_ERROR
(
"Error while parsing the element "
+
213
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_CITYGATES
) +
": "
+
214
e.what());
215
throw
ProcessError
();
216
}
217
}
218
219
void
220
AGActivityGenHandler::parseWorkHours
() {
221
myCurrentObject
=
"workHours"
;
222
}
223
224
void
225
AGActivityGenHandler::parseOpeningHour
(
const
SUMOSAXAttributes
& attrs) {
226
if
(
myCurrentObject
==
"workHours"
) {
227
try
{
228
myCity
.
statData
.
beginWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
229
230
}
catch
(
const
exception
& e) {
231
WRITE_ERROR
(
"Error while parsing the element "
+
232
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_OPENING
) +
": "
233
+ e.what());
234
throw
ProcessError
();
235
}
236
}
237
}
238
239
void
240
AGActivityGenHandler::parseClosingHour
(
const
SUMOSAXAttributes
& attrs) {
241
if
(
myCurrentObject
==
"workHours"
) {
242
try
{
243
myCity
.
statData
.
endWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
244
245
}
catch
(
const
exception
& e) {
246
WRITE_ERROR
(
"Error while parsing the element "
+
247
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_CLOSING
) +
": "
248
+ e.what());
249
throw
ProcessError
();
250
}
251
}
252
}
253
254
void
255
AGActivityGenHandler::parseSchools
() {
256
myCurrentObject
=
"schools"
;
257
}
258
259
void
260
AGActivityGenHandler::parseSchool
(
const
SUMOSAXAttributes
& attrs) {
261
try
{
262
string
edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
263
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
264
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
265
int
beginAge = attrs.
getInt
(
AGEN_ATTR_BEGINAGE
);
266
int
endAge = attrs.
getInt
(
AGEN_ATTR_ENDAGE
);
267
int
capacity = attrs.
getInt
(
AGEN_ATTR_CAPACITY
);
268
int
openingHour = attrs.
getInt
(
AGEN_ATTR_OPENING
);
269
int
closingHour = attrs.
getInt
(
AGEN_ATTR_CLOSING
);
270
AGSchool
sch(capacity, posi, beginAge, endAge, openingHour, closingHour);
271
myCity
.
schools
.push_back(sch);
272
273
}
catch
(
const
exception
& e) {
274
WRITE_ERROR
(
"Error while parsing the element "
+
275
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_SCHOOL
) +
": "
+
276
e.what());
277
throw
ProcessError
();
278
}
279
}
280
281
void
282
AGActivityGenHandler::parseBusStation
(
const
SUMOSAXAttributes
& attrs) {
283
try
{
284
string
edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
285
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
286
int
id
= attrs.
getInt
(
SUMO_ATTR_ID
);
287
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
288
myCity
.
statData
.
busStations
.insert(std::pair<int, AGPosition>(
id
, posi));
289
290
}
catch
(
const
exception
& e) {
291
WRITE_ERROR
(
"Error while parsing the element "
+
292
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BUSSTATION
) +
": "
+
293
e.what());
294
throw
ProcessError
();
295
}
296
}
297
298
void
299
AGActivityGenHandler::parseBusLine
(
const
SUMOSAXAttributes
& attrs) {
300
try
{
301
myCurrentObject
=
"busLine"
;
302
AGBusLine
busL(attrs.
getString
(
SUMO_ATTR_ID
));
303
busL.
setMaxTripTime
(attrs.
getInt
(
AGEN_ATTR_MAX_TRIP_DURATION
));
304
myCity
.
busLines
.push_front(busL);
305
currentBusLine
= &*
myCity
.
busLines
.begin();
306
307
}
catch
(
const
exception
& e) {
308
WRITE_ERROR
(
"Error while parsing the element "
+
309
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BUSLINE
) +
": "
+
310
e.what());
311
throw
ProcessError
();
312
}
313
}
314
315
void
316
AGActivityGenHandler::parseStations
() {
317
isRevStation
=
false
;
318
}
319
320
void
321
AGActivityGenHandler::parseRevStations
() {
322
isRevStation
=
true
;
323
}
324
325
void
326
AGActivityGenHandler::parseStation
(
const
SUMOSAXAttributes
& attrs) {
327
if
(
myCurrentObject
!=
"busLine"
) {
328
return
;
329
}
330
331
try
{
332
bool
ok =
true
;
333
int
refID = attrs.
hasAttribute
(
SUMO_ATTR_REFID
)
334
? attrs.
getIntReporting
(
SUMO_ATTR_REFID
,
myCurrentObject
.c_str(), ok)
335
: attrs.
getIntReporting
(
SUMO_ATTR_REFID__DEPRECATED
,
myCurrentObject
.c_str(), ok);
336
if
(!ok) {
337
throw
ProcessError
();
338
}
339
340
if
(!
isRevStation
) {
341
currentBusLine
->
locateStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
342
}
else
{
343
currentBusLine
->
locateRevStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
344
}
345
346
}
catch
(
const
exception
& e) {
347
WRITE_ERROR
(
"Error while parsing the element "
+
348
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_STATION
) +
": "
+
349
e.what());
350
throw
ProcessError
();
351
}
352
}
353
354
void
355
AGActivityGenHandler::parseFrequency
(
const
SUMOSAXAttributes
& attrs) {
356
if
(
myCurrentObject
!=
"busLine"
) {
357
return
;
358
}
359
360
try
{
361
int
beginB = attrs.
getInt
(
SUMO_ATTR_BEGIN
);
362
int
endB = attrs.
getInt
(
SUMO_ATTR_END
);
363
int
rateB = attrs.
getInt
(
AGEN_ATTR_RATE
);
364
currentBusLine
->
generateBuses
(beginB, endB, rateB);
365
366
}
catch
(
const
exception
& e) {
367
WRITE_ERROR
(
"Error while parsing the element "
+
368
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_FREQUENCY
) +
": "
+
369
e.what());
370
throw
ProcessError
();
371
}
372
}
373
374
void
375
AGActivityGenHandler::parsePopulation
() {
376
myCurrentObject
=
"population"
;
377
}
378
379
void
380
AGActivityGenHandler::parseBracket
(
const
SUMOSAXAttributes
& attrs) {
381
try
{
382
int
beginAge = attrs.
getInt
(
AGEN_ATTR_BEGINAGE
);
//included in the bracket
383
int
endAge = attrs.
getInt
(
AGEN_ATTR_ENDAGE
);
//NOT included in the bracket
384
if
(
myCurrentObject
==
"population"
) {
385
myCity
.
statData
.
population
[endAge] = attrs.
getInt
(
AGEN_ATTR_PEOPLENBR
);
386
}
387
388
}
catch
(
const
exception
& e) {
389
WRITE_ERROR
(
"Error while parsing the element "
+
390
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BRACKET
) +
": "
+
391
e.what());
392
throw
ProcessError
();
393
}
394
}
395
396
/****************************************************************************/
397
tmp
buildd
sumo-0.15.0~dfsg
src
activitygen
AGActivityGenHandler.cpp
Generated on Sun May 27 2012 14:52:03 for SUMO - Simulation of Urban MObility by
1.8.1