Eclipse SUMO - Simulation of Urban MObility
NLDiscreteEventBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // }
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
27 #include <microsim/MSNet.h>
38 #include "NLDiscreteEventBuilder.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
45  : myNet(net) {
46  myActions["SaveTLSStates"] = EV_SAVETLSTATE;
47  myActions["SaveTLSSwitchTimes"] = EV_SAVETLSWITCHES;
48  myActions["SaveTLSSwitchStates"] = EV_SAVETLSWITCHSTATES;
49  myActions["SaveTLSProgram"] = EV_SAVETLSPROGRAM;
50 }
51 
52 
54 
55 
56 void
58  const std::string& basePath) {
59  bool ok = true;
60  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, nullptr, ok, "");
61  // check whether the type was given
62  if (type == "" || !ok) {
63  throw InvalidArgument("An action's type is not given.");
64  }
65  // get the numerical representation
66  KnownActions::iterator i = myActions.find(type);
67  if (i == myActions.end()) {
68  throw InvalidArgument("The action type '" + type + "' is not known.");
69  }
70  // build the action
71  switch ((*i).second) {
72  case EV_SAVETLSTATE:
73  buildSaveTLStateCommand(attrs, basePath);
74  break;
75  case EV_SAVETLSWITCHES:
76  buildSaveTLSwitchesCommand(attrs, basePath);
77  break;
79  buildSaveTLSwitchStatesCommand(attrs, basePath);
80  break;
81  case EV_SAVETLSPROGRAM:
82  buildSaveTLSProgramCommand(attrs, basePath);
83  break;
84  }
85 }
86 
87 
88 void
90  const std::string& basePath) {
91  bool ok = true;
92  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
93  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
94  // check the parameter
95  if (dest == "" || !ok) {
96  throw InvalidArgument("Incomplete description of an 'SaveTLSState'-action occurred.");
97  }
98  if (source == "") {
99  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
100  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
103  }
104  } else {
105  // get the logic
106  if (!myNet.getTLSControl().knows(source)) {
107  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
108  }
109  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
110  // build the action
112  }
113 }
114 
115 
116 void
118  const std::string& basePath) {
119  bool ok = true;
120  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
121  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
122  // check the parameter
123  if (dest == "" || !ok) {
124  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchTimes'-action occurred.");
125  }
126  if (source == "") {
127  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
128  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
131  }
132  } else {
133  // get the logic
134  if (!myNet.getTLSControl().knows(source)) {
135  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
136  }
137  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
138  // build the action
140  }
141 }
142 
143 
144 void
146  const std::string& basePath) {
147  bool ok = true;
148  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
149  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
150  // check the parameter
151  if (dest == "" || !ok) {
152  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchStates'-action occurred.");
153  }
154  if (source == "") {
155  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
156  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
159  }
160  } else {
161  // get the logic
162  if (!myNet.getTLSControl().knows(source)) {
163  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
164  }
165  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
166  // build the action
168  }
169 }
170 
171 
172 void
174  const std::string& basePath) {
175  bool ok = true;
176  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
177  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
178  // check the parameter
179  if (dest == "" || !ok) {
180  throw InvalidArgument("Incomplete description of an 'SaveTLSProgram'-action occurred.");
181  }
182  if (source == "") {
183  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
184  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
187  }
188  } else {
189  // get the logic
190  if (!myNet.getTLSControl().knows(source)) {
191  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
192  }
193  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
194  // build the action
196  }
197 }
198 
199 /****************************************************************************/
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
Command_SaveTLSSwitchStates.h
MSTLLogicControl.h
MSNet.h
MSTLLogicControl::getAllTLIds
std::vector< std::string > getAllTLIds() const
Definition: MSTLLogicControl.cpp:609
NLDiscreteEventBuilder::NLDiscreteEventBuilder
NLDiscreteEventBuilder(MSNet &net)
Constructor.
Definition: NLDiscreteEventBuilder.cpp:44
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:91
FileHelpers.h
NLDiscreteEventBuilder::buildSaveTLSwitchesCommand
void buildSaveTLSwitchesCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the switch times of links into a file.
Definition: NLDiscreteEventBuilder.cpp:117
Command_SaveTLSProgram.h
NLDiscreteEventBuilder::EV_SAVETLSPROGRAM
"SaveTLSProgram"
Definition: NLDiscreteEventBuilder.h:56
NLDiscreteEventBuilder::myActions
KnownActions myActions
Build actions that shall be executed during the simulation.
Definition: NLDiscreteEventBuilder.h:89
Command_SaveTLSProgram
Writes the switch times of a tls into a file when the tls switches.
Definition: Command_SaveTLSProgram.h:48
FileHelpers::checkForRelativity
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessable from the current working directory.
Definition: FileHelpers.cpp:152
NLDiscreteEventBuilder::EV_SAVETLSWITCHES
"SaveTLSSwitchTimes"
Definition: NLDiscreteEventBuilder.h:52
SUMO_ATTR_SOURCE
Definition: SUMOXMLDefinitions.h:722
Command_SaveTLSSwitches.h
MSTLLogicControl::knows
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
Definition: MSTLLogicControl.cpp:631
MSTrafficLightLogic.h
NLDiscreteEventBuilder::myNet
MSNet & myNet
Definition: NLDiscreteEventBuilder.h:91
NLDiscreteEventBuilder::~NLDiscreteEventBuilder
~NLDiscreteEventBuilder()
Destructor.
Definition: NLDiscreteEventBuilder.cpp:53
MSTLLogicControl::get
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
Definition: MSTLLogicControl.cpp:589
NLDiscreteEventBuilder::EV_SAVETLSTATE
"SaveTLSStates"
Definition: NLDiscreteEventBuilder.h:50
NLDiscreteEventBuilder::addAction
void addAction(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action and saves it for further use.
Definition: NLDiscreteEventBuilder.cpp:57
NLDiscreteEventBuilder::buildSaveTLSwitchStatesCommand
void buildSaveTLSwitchStatesCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the switch times and states of tls into a file.
Definition: NLDiscreteEventBuilder.cpp:145
OutputDevice.h
NLDiscreteEventBuilder::buildSaveTLSProgramCommand
void buildSaveTLSProgramCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the tls states as a loadable program into a file.
Definition: NLDiscreteEventBuilder.cpp:173
UtilExceptions.h
SUMOSAXAttributes::getOpt
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:518
NLDiscreteEventBuilder::buildSaveTLStateCommand
void buildSaveTLStateCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the state of a certain tls into a file.
Definition: NLDiscreteEventBuilder.cpp:89
Command_SaveTLSSwitchStates
Writes the switch times of a tls into a file when the tls switches.
Definition: Command_SaveTLSSwitchStates.h:48
MSNet::getTLSControl
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:409
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:54
Command_SaveTLSState
Writes the state of the tls to a file (in each second)
Definition: Command_SaveTLSState.h:46
InvalidArgument
Definition: UtilExceptions.h:56
SUMO_ATTR_DEST
Definition: SUMOXMLDefinitions.h:721
Command_SaveTLSState.h
MSTLLogicControl::TLSLogicVariants
Storage for all programs of a single tls.
Definition: MSTLLogicControl.h:85
config.h
MSEventControl.h
NLDiscreteEventBuilder.h
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
Command_SaveTLSSwitches
Writes information about the green durations of a tls.
Definition: Command_SaveTLSSwitches.h:48
SUMOXMLDefinitions.h
NLDiscreteEventBuilder::EV_SAVETLSWITCHSTATES
"SaveTLSSwitchStates"
Definition: NLDiscreteEventBuilder.h:54