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
MSVTypeProbe.cpp
Go to the documentation of this file.
1
/****************************************************************************/
10
// Writes positions of vehicles that have a certain (named) type
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13
// Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
14
/****************************************************************************/
15
//
16
// This file is part of SUMO.
17
// SUMO is free software: you can redistribute it and/or modify
18
// it under the terms of the GNU General Public License as published by
19
// the Free Software Foundation, either version 3 of the License, or
20
// (at your option) any later version.
21
//
22
/****************************************************************************/
23
24
25
// ===========================================================================
26
// included modules
27
// ===========================================================================
28
#ifdef _MSC_VER
29
#include <
windows_config.h
>
30
#else
31
#include <
config.h
>
32
#endif
33
34
#include <string>
35
#include <
utils/common/WrappingCommand.h
>
36
#include <
microsim/MSNet.h
>
37
#include <
microsim/MSVehicle.h
>
38
#include <
microsim/MSLane.h
>
39
#include <
utils/iodevices/OutputDevice.h
>
40
#include <
utils/geom/GeoConvHelper.h
>
41
42
#include "
MSVTypeProbe.h
"
43
44
#ifdef CHECK_MEMORY_LEAKS
45
#include <
foreign/nvwa/debug_new.h
>
46
#endif // CHECK_MEMORY_LEAKS
47
48
49
// ===========================================================================
50
// method definitions
51
// ===========================================================================
52
MSVTypeProbe::MSVTypeProbe
(
const
std::string&
id
,
53
const
std::string& vType,
54
OutputDevice
& od,
SUMOTime
frequency)
55
:
Named
(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) {
56
MSNet::getInstance
()->
getEndOfTimestepEvents
().
addEvent
(
this
, 0,
MSEventControl::ADAPT_AFTER_EXECUTION
);
57
myOutputDevice
.
writeXMLHeader
(
"vehicle-type-probes"
);
58
}
59
60
61
MSVTypeProbe::~MSVTypeProbe
() {
62
}
63
64
65
SUMOTime
66
MSVTypeProbe::execute
(
SUMOTime
currentTime) {
67
myOutputDevice
.
openTag
(
"timestep"
) <<
" time=\""
<<
time2string
(currentTime) <<
"\" id=\""
<<
getID
() <<
"\" vType=\""
<<
myVType
<<
"\""
;
68
MSVehicleControl
& vc =
MSNet::getInstance
()->
getVehicleControl
();
69
MSVehicleControl::constVehIt
it = vc.
loadedVehBegin
();
70
MSVehicleControl::constVehIt
end = vc.
loadedVehEnd
();
71
for
(; it != end; ++it) {
72
const
MSVehicle
* veh =
static_cast<
const
MSVehicle
*
>
((*it).second);
73
if
(
myVType
==
""
||
myVType
== veh->
getVehicleType
().
getID
()) {
74
if
(!veh->
isOnRoad
()) {
75
continue
;
76
}
77
Position
pos = veh->
getLane
()->
getShape
().
positionAtOffset
(veh->
getPositionOnLane
());
78
myOutputDevice
.
openTag
(
"vehicle"
) <<
" id=\""
<< veh->
getID
()
79
<<
"\" lane=\""
<< veh->
getLane
()->
getID
()
80
<<
"\" pos=\""
<< veh->
getPositionOnLane
()
81
<<
"\" x=\""
<< pos.
x
()
82
<<
"\" y=\""
<< pos.
y
();
83
if
(
GeoConvHelper::getFinal
().usingGeoProjection()) {
84
GeoConvHelper::getFinal
().
cartesian2geo
(pos);
85
myOutputDevice
.
setPrecision
(
GEO_OUTPUT_ACCURACY
);
86
myOutputDevice
<<
"\" lat=\""
<< pos.
y
() <<
"\" lon=\""
<< pos.
x
();
87
myOutputDevice
.
setPrecision
();
88
}
89
myOutputDevice
<<
"\" speed=\""
<< veh->
getSpeed
() <<
"\""
;
90
myOutputDevice
.
closeTag
();
91
}
92
93
}
94
myOutputDevice
.
closeTag
();
95
return
myFrequency
;
96
}
97
98
99
/****************************************************************************/
tmp
buildd
sumo-0.21.0+dfsg
src
microsim
output
MSVTypeProbe.cpp
Generated on Thu Nov 20 2014 19:49:56 for SUMO - Simulation of Urban MObility by
1.8.1.2