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 /****************************************************************************/
18 // }
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
28 #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 }
50 
51 
53 
54 
55 void
57  const std::string& basePath) {
58  bool ok = true;
59  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, nullptr, ok, "");
60  // check whether the type was given
61  if (type == "" || !ok) {
62  throw InvalidArgument("An action's type is not given.");
63  }
64  // get the numerical representation
65  KnownActions::iterator i = myActions.find(type);
66  if (i == myActions.end()) {
67  throw InvalidArgument("The action type '" + type + "' is not known.");
68  }
69  // build the action
70  switch ((*i).second) {
71  case EV_SAVETLSTATE:
72  buildSaveTLStateCommand(attrs, basePath);
73  break;
74  case EV_SAVETLSWITCHES:
75  buildSaveTLSwitchesCommand(attrs, basePath);
76  break;
78  buildSaveTLSwitchStatesCommand(attrs, basePath);
79  break;
80  }
81 }
82 
83 
84 void
86  const std::string& basePath) {
87  bool ok = true;
88  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
89  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
90  // check the parameter
91  if (dest == "" || !ok) {
92  throw InvalidArgument("Incomplete description of an 'SaveTLSState'-action occurred.");
93  }
94  if (source == "") {
95  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
96  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
99  }
100  } else {
101  // get the logic
102  if (!myNet.getTLSControl().knows(source)) {
103  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
104  }
105  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
106  // build the action
108  }
109 }
110 
111 
112 void
114  const std::string& basePath) {
115  bool ok = true;
116  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
117  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
118  // check the parameter
119  if (dest == "" || !ok) {
120  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchTimes'-action occurred.");
121  }
122  if (source == "") {
123  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
124  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
127  }
128  } else {
129  // get the logic
130  if (!myNet.getTLSControl().knows(source)) {
131  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
132  }
133  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
134  // build the action
136  }
137 }
138 
139 
140 void
142  const std::string& basePath) {
143  bool ok = true;
144  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, nullptr, ok, "");
145  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, nullptr, ok, "");
146  // check the parameter
147  if (dest == "" || !ok) {
148  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchStates'-action occurred.");
149  }
150  if (source == "") {
151  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
152  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
155  }
156  } else {
157  // get the logic
158  if (!myNet.getTLSControl().knows(source)) {
159  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
160  }
161  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
162  // build the action
164  }
165 }
166 
167 
168 /****************************************************************************/
Storage for all programs of a single tls.
KnownActions myActions
Build actions that shall be executed during the simulation.
Writes the switch times of a tls into a file when the tls switches.
The simulated network and simulation perfomer.
Definition: MSNet.h:92
Encapsulated SAX-Attributes.
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:410
void buildSaveTLSwitchesCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the switch times of links into a file.
void addAction(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action and saves it for further use.
Writes the state of the tls to a file (in each second)
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
NLDiscreteEventBuilder(MSNet &net)
Constructor.
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.
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
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...
TLSLogicVariants & get(const std::string &id) const
Returns the variants of a named tls.
Writes information about the green durations of a tls.
void buildSaveTLStateCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the state of a certain tls into a file.
std::vector< std::string > getAllTLIds() const
void buildSaveTLSwitchStatesCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the switch times and states of tls into a file.