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-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
189
AGStreet
str(
net
->
getEdge
(attrs.
getString
(
SUMO_ATTR_EDGE
)), pop, work);
190
myCity
.
streets
.push_back(str);
191
192
}
catch
(
const
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
201
AGActivityGenHandler::parseCityGates
(
const
SUMOSAXAttributes
& attrs) {
202
try
{
203
string
edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
204
SUMOReal
positionOnEdge = attrs.
getFloat
(
SUMO_ATTR_POSITION
);
205
AGPosition
posi(
myCity
.
getStreet
(edge), positionOnEdge);
206
myCity
.
statData
.
incoming
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_INCOMING
);
207
myCity
.
statData
.
outgoing
[(
int
)
myCity
.
cityGates
.size()] = attrs.
getFloat
(
AGEN_ATTR_OUTGOING
);
208
myCity
.
cityGates
.push_back(posi);
209
210
}
catch
(
const
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
219
AGActivityGenHandler::parseWorkHours
() {
220
myCurrentObject
=
"workHours"
;
221
}
222
223
void
224
AGActivityGenHandler::parseOpeningHour
(
const
SUMOSAXAttributes
& attrs) {
225
if
(
myCurrentObject
==
"workHours"
) {
226
try
{
227
myCity
.
statData
.
beginWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
228
229
}
catch
(
const
exception
& e) {
230
WRITE_ERROR
(
"Error while parsing the element "
+
231
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_OPENING
) +
": "
232
+ e.what());
233
throw
ProcessError
();
234
}
235
}
236
}
237
238
void
239
AGActivityGenHandler::parseClosingHour
(
const
SUMOSAXAttributes
& attrs) {
240
if
(
myCurrentObject
==
"workHours"
) {
241
try
{
242
myCity
.
statData
.
endWorkHours
[attrs.
getInt
(
AGEN_ATTR_HOUR
)] = attrs.
getFloat
(
AGEN_ATTR_PROP
);
243
244
}
catch
(
const
exception
& e) {
245
WRITE_ERROR
(
"Error while parsing the element "
+
246
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_CLOSING
) +
": "
247
+ e.what());
248
throw
ProcessError
();
249
}
250
}
251
}
252
253
void
254
AGActivityGenHandler::parseSchools
() {
255
myCurrentObject
=
"schools"
;
256
}
257
258
void
259
AGActivityGenHandler::parseSchool
(
const
SUMOSAXAttributes
& attrs) {
260
try
{
261
string
edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
262
SUMOReal
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
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
281
AGActivityGenHandler::parseBusStation
(
const
SUMOSAXAttributes
& attrs) {
282
try
{
283
string
edge = attrs.
getString
(
SUMO_ATTR_EDGE
);
284
SUMOReal
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
exception
& e) {
290
WRITE_ERROR
(
"Error while parsing the element "
+
291
SUMOXMLDefinitions::Tags
.getString(
AGEN_TAG_BUSSTATION
) +
": "
+
292
e.what());
293
throw
ProcessError
();
294
}
295
}
296
297
void
298
AGActivityGenHandler::parseBusLine
(
const
SUMOSAXAttributes
& attrs) {
299
try
{
300
myCurrentObject
=
"busLine"
;
301
AGBusLine
busL(attrs.
getString
(
SUMO_ATTR_ID
));
302
busL.
setMaxTripTime
(attrs.
getInt
(
AGEN_ATTR_MAX_TRIP_DURATION
));
303
myCity
.
busLines
.push_front(busL);
304
currentBusLine
= &*
myCity
.
busLines
.begin();
305
306
}
catch
(
const
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
315
AGActivityGenHandler::parseStations
() {
316
isRevStation
=
false
;
317
}
318
319
void
320
AGActivityGenHandler::parseRevStations
() {
321
isRevStation
=
true
;
322
}
323
324
void
325
AGActivityGenHandler::parseStation
(
const
SUMOSAXAttributes
& attrs) {
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
) {
337
currentBusLine
->
locateStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
338
}
else
{
339
currentBusLine
->
locateRevStation
(
myCity
.
statData
.
busStations
.find(refID)->second);
340
}
341
342
}
catch
(
const
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
351
AGActivityGenHandler::parseFrequency
(
const
SUMOSAXAttributes
& attrs) {
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
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
371
AGActivityGenHandler::parsePopulation
() {
372
myCurrentObject
=
"population"
;
373
}
374
375
void
376
AGActivityGenHandler::parseBracket
(
const
SUMOSAXAttributes
& attrs) {
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"
) {
382
myCity
.
statData
.
population
[endAge] = attrs.
getInt
(
AGEN_ATTR_PEOPLENBR
);
383
}
384
385
}
catch
(
const
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
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
activitygen
AGActivityGenHandler.cpp
Generated on Sun Jun 16 2013 07:06:57 for SUMO - Simulation of Urban MObility by
1.8.1.2