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
/****************************************************************************/
10
// A device which collects info on the vehicle trip
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13
// Copyright (C) 2009-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
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#include <
microsim/MSNet.h
>
34
#include <
microsim/MSLane.h
>
35
#include <
microsim/MSVehicle.h
>
36
#include <
utils/options/OptionsCont.h
>
37
#include <
utils/iodevices/OutputDevice.h
>
38
#include "
MSDevice_Tripinfo.h
"
39
40
#ifdef CHECK_MEMORY_LEAKS
41
#include <
foreign/nvwa/debug_new.h
>
42
#endif // CHECK_MEMORY_LEAKS
43
44
45
// ===========================================================================
46
// method definitions
47
// ===========================================================================
48
// ---------------------------------------------------------------------------
49
// static initialisation methods
50
// ---------------------------------------------------------------------------
51
void
52
MSDevice_Tripinfo::buildVehicleDevices
(
SUMOVehicle
& v, std::vector<MSDevice*>& into) {
53
if
(
OptionsCont::getOptions
().isSet(
"tripinfo-output"
)) {
54
MSDevice_Tripinfo
* device =
new
MSDevice_Tripinfo
(v,
"tripinfo_"
+ v.
getID
());
55
into.push_back(device);
56
}
57
}
58
59
60
// ---------------------------------------------------------------------------
61
// MSDevice_Tripinfo-methods
62
// ---------------------------------------------------------------------------
63
MSDevice_Tripinfo::MSDevice_Tripinfo
(
SUMOVehicle
& holder,
const
std::string&
id
)
64
:
MSDevice
(holder, id), myDepartLane(
""
), myDepartPos(-1), myDepartSpeed(-1),
65
myWaitingSteps(0), myArrivalTime(-1), myArrivalLane(
""
), myArrivalPos(-1), myArrivalSpeed(-1) {
66
}
67
68
69
MSDevice_Tripinfo::~MSDevice_Tripinfo
() {
70
}
71
72
73
bool
74
MSDevice_Tripinfo::notifyMove
(
SUMOVehicle
&
/*veh*/
,
SUMOReal
/*oldPos*/
,
75
SUMOReal
/*newPos*/
,
SUMOReal
newSpeed) {
76
if
(newSpeed <=
SUMO_const_haltingSpeed
) {
77
myWaitingSteps
++;
78
}
79
return
true
;
80
}
81
82
83
bool
84
MSDevice_Tripinfo::notifyEnter
(
SUMOVehicle
& veh,
MSMoveReminder::Notification
reason) {
85
if
(reason ==
MSMoveReminder::NOTIFICATION_DEPARTED
) {
86
if
(!
MSGlobals::gUseMesoSim
) {
87
myDepartLane
=
static_cast<
MSVehicle
&
>
(veh).
getLane
()->
getID
();
88
}
89
myDepartPos
= veh.
getPositionOnLane
();
90
myDepartSpeed
= veh.
getSpeed
();
91
}
92
return
true
;
93
}
94
95
96
bool
97
MSDevice_Tripinfo::notifyLeave
(
SUMOVehicle
& veh,
SUMOReal
/*lastPos*/
,
98
MSMoveReminder::Notification
reason) {
99
if
(reason >=
MSMoveReminder::NOTIFICATION_ARRIVED
) {
100
myArrivalTime
=
MSNet::getInstance
()->
getCurrentTimeStep
();
101
if
(!
MSGlobals::gUseMesoSim
) {
102
myArrivalLane
=
static_cast<
MSVehicle
&
>
(veh).
getLane
()->
getID
();
103
}
104
// @note vehicle may have moved past its arrivalPos during the last step
105
// due to non-zero arrivalspeed but we consider it as arrived at the desired position
106
myArrivalPos
=
myHolder
.
getArrivalPos
();
107
myArrivalSpeed
= veh.
getSpeed
();
108
}
109
return
true
;
110
}
111
112
113
void
114
MSDevice_Tripinfo::generateOutput
()
const
{
115
SUMOReal
routeLength =
myHolder
.
getRoute
().
getLength
();
116
// write
117
OutputDevice
& os =
OutputDevice::getDeviceByOption
(
"tripinfo-output"
);
118
os.
openTag
(
"tripinfo"
).
writeAttr
(
"id"
,
myHolder
.
getID
());
119
routeLength -=
myDepartPos
;
120
os.
writeAttr
(
"depart"
,
time2string
(
myHolder
.
getDeparture
())).
writeAttr
(
"departLane"
,
myDepartLane
)
121
.
writeAttr
(
"departPos"
,
myDepartPos
).
writeAttr
(
"departSpeed"
,
myDepartSpeed
)
122
.
writeAttr
(
"departDelay"
,
time2string
(
myHolder
.
getDeparture
() -
myHolder
.
getParameter
().
depart
));
123
if
(
myArrivalLane
!=
""
) {
124
routeLength -=
MSLane::dictionary
(
myArrivalLane
)->getLength() -
myArrivalPos
;
125
}
126
os.
writeAttr
(
"arrival"
,
time2string
(
myArrivalTime
)).
writeAttr
(
"arrivalLane"
,
myArrivalLane
)
127
.
writeAttr
(
"arrivalPos"
,
myArrivalPos
).
writeAttr
(
"arrivalSpeed"
,
myArrivalSpeed
)
128
.
writeAttr
(
"duration"
,
time2string
(
myArrivalTime
-
myHolder
.
getDeparture
()))
129
.
writeAttr
(
"routeLength"
, routeLength).
writeAttr
(
"waitSteps"
,
myWaitingSteps
)
130
.
writeAttr
(
"rerouteNo"
,
myHolder
.
getNumberReroutes
());
131
const
std::vector<MSDevice*>& devices =
myHolder
.
getDevices
();
132
std::ostringstream str;
133
for
(std::vector<MSDevice*>::const_iterator i = devices.begin(); i != devices.end(); ++i) {
134
if
(i != devices.begin()) {
135
str <<
' '
;
136
}
137
str << (*i)->getID();
138
}
139
os.
writeAttr
(
"devices"
, str.str()).writeAttr(
"vType"
,
myHolder
.
getVehicleType
().
getID
())
140
.writeAttr(
"vaporized"
, (
myHolder
.
getEdge
() == *(
myHolder
.
getRoute
().
end
() - 1) ?
""
:
"0"
));
141
}
142
143
144
/****************************************************************************/
145
tmp
buildd
sumo-0.21.0+dfsg
src
microsim
devices
MSDevice_Tripinfo.cpp
Generated on Thu Nov 20 2014 19:49:55 for SUMO - Simulation of Urban MObility by
1.8.1.2