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
MSDevice_Tripinfo.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// A device which collects info on the vehicle trip
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
// ===========================================================================
24
// included modules
25
// ===========================================================================
26
#ifdef _MSC_VER
27
#include <
windows_config.h
>
28
#else
29
#include <
config.h
>
30
#endif
31
32
#include <
microsim/MSNet.h
>
33
#include <
microsim/MSLane.h
>
34
#include <
microsim/MSVehicle.h
>
35
#include <
utils/options/OptionsCont.h
>
36
#include <
utils/iodevices/OutputDevice.h
>
37
#include "
MSDevice_Tripinfo.h
"
38
39
#ifdef CHECK_MEMORY_LEAKS
40
#include <
foreign/nvwa/debug_new.h
>
41
#endif // CHECK_MEMORY_LEAKS
42
43
44
// ===========================================================================
45
// method definitions
46
// ===========================================================================
47
// ---------------------------------------------------------------------------
48
// static initialisation methods
49
// ---------------------------------------------------------------------------
50
void
51
MSDevice_Tripinfo::buildVehicleDevices
(
SUMOVehicle
& v, std::vector<MSDevice*>& into) {
52
if
(
OptionsCont::getOptions
().isSet(
"tripinfo-output"
)) {
53
MSDevice_Tripinfo
* device =
new
MSDevice_Tripinfo
(v,
"tripinfo_"
+ v.
getID
());
54
into.push_back(device);
55
}
56
}
57
58
59
// ---------------------------------------------------------------------------
60
// MSDevice_Tripinfo-methods
61
// ---------------------------------------------------------------------------
62
MSDevice_Tripinfo::MSDevice_Tripinfo
(
SUMOVehicle
& holder,
const
std::string&
id
)
63
:
MSDevice
(holder, id), myDepartLane(
""
), myDepartPos(-1), myDepartSpeed(-1),
64
myWaitingSteps(0), myArrivalTime(-1), myArrivalLane(
""
), myArrivalPos(-1), myArrivalSpeed(-1) {
65
}
66
67
68
MSDevice_Tripinfo::~MSDevice_Tripinfo
() {
69
}
70
71
72
bool
73
MSDevice_Tripinfo::notifyMove
(
SUMOVehicle
&
/*veh*/
,
SUMOReal
/*oldPos*/
,
74
SUMOReal
/*newPos*/
,
SUMOReal
newSpeed) {
75
if
(newSpeed <= 0.1) {
76
myWaitingSteps
++;
77
}
78
return
true
;
79
}
80
81
82
bool
83
MSDevice_Tripinfo::notifyEnter
(
SUMOVehicle
& veh,
MSMoveReminder::Notification
reason) {
84
if
(reason ==
MSMoveReminder::NOTIFICATION_DEPARTED
) {
85
if
(!
MSGlobals::gUseMesoSim
) {
86
myDepartLane
=
static_cast<
MSVehicle
&
>
(veh).
getLane
()->
getID
();
87
}
88
myDepartPos
= veh.
getPositionOnLane
();
89
myDepartSpeed
= veh.
getSpeed
();
90
}
91
return
true
;
92
}
93
94
95
bool
96
MSDevice_Tripinfo::notifyLeave
(
SUMOVehicle
& veh,
SUMOReal
/*lastPos*/
,
97
MSMoveReminder::Notification
reason) {
98
if
(reason >=
MSMoveReminder::NOTIFICATION_ARRIVED
) {
99
myArrivalTime
=
MSNet::getInstance
()->
getCurrentTimeStep
();
100
if
(!
MSGlobals::gUseMesoSim
) {
101
myArrivalLane
=
static_cast<
MSVehicle
&
>
(veh).
getLane
()->
getID
();
102
}
103
myArrivalPos
=
myHolder
.
getPositionOnLane
();
104
myArrivalSpeed
= veh.
getSpeed
();
105
}
106
return
true
;
107
}
108
109
110
void
111
MSDevice_Tripinfo::generateOutput
()
const
{
112
SUMOReal
routeLength =
myHolder
.
getRoute
().
getLength
();
113
// write
114
OutputDevice
& os =
OutputDevice::getDeviceByOption
(
"tripinfo-output"
);
115
os.
openTag
(
"tripinfo"
) <<
" id=\""
<<
myHolder
.
getID
() <<
"\" "
;
116
routeLength -=
myDepartPos
;
117
os <<
"depart=\""
<<
time2string
(
myHolder
.
getDeparture
()) <<
"\" "
118
<<
"departLane=\""
<<
myDepartLane
<<
"\" "
119
<<
"departPos=\""
<<
myDepartPos
<<
"\" "
120
<<
"departSpeed=\""
<<
myDepartSpeed
<<
"\" "
121
<<
"departDelay=\""
<<
time2string
(
myHolder
.
getDeparture
() -
myHolder
.
getParameter
().
depart
) <<
"\" "
;
122
if
(
myArrivalLane
!=
""
) {
123
routeLength -=
MSLane::dictionary
(
myArrivalLane
)->getLength() -
myArrivalPos
;
124
}
125
os <<
"arrival=\""
<<
time2string
(
myArrivalTime
) <<
"\" "
126
<<
"arrivalLane=\""
<<
myArrivalLane
<<
"\" "
127
<<
"arrivalPos=\""
<<
myArrivalPos
<<
"\" "
128
<<
"arrivalSpeed=\""
<<
myArrivalSpeed
<<
"\" "
129
<<
"duration=\""
<<
time2string
(
myArrivalTime
-
myHolder
.
getDeparture
()) <<
"\" "
130
<<
"routeLength=\""
<< routeLength <<
"\" "
131
<<
"waitSteps=\""
<<
myWaitingSteps
<<
"\" "
132
<<
"rerouteNo=\""
<<
myHolder
.
getNumberReroutes
();
133
const
std::vector<MSDevice*>& devices =
myHolder
.
getDevices
();
134
std::ostringstream str;
135
for
(std::vector<MSDevice*>::const_iterator i = devices.begin(); i != devices.end(); ++i) {
136
if
(i != devices.begin()) {
137
str <<
' '
;
138
}
139
str << (*i)->getID();
140
}
141
os <<
"\" devices=\""
<< str.str()
142
<<
"\" vType=\""
<<
myHolder
.
getVehicleType
().
getID
()
143
<<
"\" vaporized=\""
<< (
myHolder
.
getEdge
() == *(
myHolder
.
getRoute
().
end
() - 1) ?
""
:
"0"
)
144
<<
"\""
;
145
if
(devices.size() > 1) {
146
os <<
">\n"
;
147
}
148
}
149
150
151
152
/****************************************************************************/
153
build
buildd
sumo-0.16.0~dfsg
src
microsim
devices
MSDevice_Tripinfo.cpp
Generated on Tue Apr 16 2013 01:32:17 for SUMO - Simulation of Urban MObility by
1.8.3.1