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
Command_SaveTLSSwitches.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// Writes information about the green durations of a tls
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
// included modules
24
// ===========================================================================
25
#ifdef _MSC_VER
26
#include <
windows_config.h
>
27
#else
28
#include <
config.h
>
29
#endif
30
31
#include "
Command_SaveTLSSwitches.h
"
32
#include <
microsim/traffic_lights/MSTrafficLightLogic.h
>
33
#include <
microsim/MSEventControl.h
>
34
#include <
microsim/MSNet.h
>
35
#include <
microsim/MSLink.h
>
36
#include <
microsim/MSLane.h
>
37
#include <
utils/common/UtilExceptions.h
>
38
#include <
utils/common/MsgHandler.h
>
39
#include <
utils/iodevices/OutputDevice.h
>
40
41
#ifdef CHECK_MEMORY_LEAKS
42
#include <
foreign/nvwa/debug_new.h
>
43
#endif // CHECK_MEMORY_LEAKS
44
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
Command_SaveTLSSwitches::Command_SaveTLSSwitches
(
const
MSTLLogicControl::TLSLogicVariants
& logics,
50
OutputDevice
& od)
51
: myOutputDevice(od), myLogics(logics) {
52
MSNet::getInstance
()->
getEndOfTimestepEvents
().
addEvent
(
this
, 0,
MSEventControl::ADAPT_AFTER_EXECUTION
);
53
myOutputDevice
.
writeXMLHeader
(
"tls-switches"
);
54
}
55
56
57
Command_SaveTLSSwitches::~Command_SaveTLSSwitches
() {
58
}
59
60
61
SUMOTime
62
Command_SaveTLSSwitches::execute
(
SUMOTime
currentTime) {
63
MSTrafficLightLogic
* light =
myLogics
.
getActive
();
64
const
MSTrafficLightLogic::LinkVectorVector
& links = light->
getLinks
();
65
const
std::string& state = light->
getCurrentPhaseDef
().
getState
();
66
for
(
unsigned
int
i = 0; i < (
unsigned
int
) links.size(); i++) {
67
if
(state[i] ==
LINKSTATE_TL_GREEN_MAJOR
|| state[i] ==
LINKSTATE_TL_GREEN_MINOR
) {
68
if
(
myPreviousLinkStates
.find(i) ==
myPreviousLinkStates
.end()) {
69
// was not saved before
70
myPreviousLinkStates
[i] = currentTime;
71
continue
;
72
}
73
}
else
{
74
if
(
myPreviousLinkStates
.find(i) ==
myPreviousLinkStates
.end()) {
75
// was not yet green
76
continue
;
77
}
78
const
MSTrafficLightLogic::LinkVector
& currLinks = links[i];
79
const
MSTrafficLightLogic::LaneVector
& currLanes = light->
getLanesAt
(i);
80
SUMOTime
lastOn =
myPreviousLinkStates
[i];
81
for
(
int
j = 0; j < (
int
) currLinks.size(); j++) {
82
MSLink
* link = currLinks[j];
83
myOutputDevice
<<
" <tlsSwitch id=\""
<< light->
getID
()
84
<<
"\" programID=\""
<< light->
getProgramID
()
85
<<
"\" fromLane=\""
<< currLanes[j]->getID()
86
<<
"\" toLane=\""
<< link->
getLane
()->
getID
()
87
<<
"\" begin=\""
<<
time2string
(lastOn)
88
<<
"\" end=\""
<<
time2string
(currentTime)
89
<<
"\" duration=\""
<<
time2string
(currentTime - lastOn)
90
<<
"\"/>\n"
;
91
}
92
myPreviousLinkStates
.erase(
myPreviousLinkStates
.find(i));
93
}
94
}
95
return
DELTA_T
;
96
}
97
98
99
100
/****************************************************************************/
101
build
buildd
sumo-0.15.0~dfsg
src
microsim
actions
Command_SaveTLSSwitches.cpp
Generated on Wed Jul 18 2012 22:58:31 for SUMO - Simulation of Urban MObility by
1.8.1.1