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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // }
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 "NLDiscreteEventBuilder.h"
35 #include <microsim/MSNet.h>
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
51  : myNet(net) {
52  myActions["SaveTLSStates"] = EV_SAVETLSTATE;
53  myActions["SaveTLSSwitchTimes"] = EV_SAVETLSWITCHES;
54  myActions["SaveTLSSwitchStates"] = EV_SAVETLSWITCHSTATES;
55 }
56 
57 
59 
60 
61 void
63  const std::string& basePath) {
64  bool ok = true;
65  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, 0, ok, "");
66  // check whether the type was given
67  if (type == "" || !ok) {
68  throw InvalidArgument("An action's type is not given.");
69  }
70  // get the numerical representation
71  KnownActions::iterator i = myActions.find(type);
72  if (i == myActions.end()) {
73  throw InvalidArgument("The action type '" + type + "' is not known.");
74  }
75  // build the action
76  switch ((*i).second) {
77  case EV_SAVETLSTATE:
78  buildSaveTLStateCommand(attrs, basePath);
79  break;
80  case EV_SAVETLSWITCHES:
81  buildSaveTLSwitchesCommand(attrs, basePath);
82  break;
84  buildSaveTLSwitchStatesCommand(attrs, basePath);
85  break;
86  }
87 }
88 
89 
90 void
92  const std::string& basePath) {
93  bool ok = true;
94  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
95  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
96  // check the parameter
97  if (dest == "" || !ok) {
98  throw InvalidArgument("Incomplete description of an 'SaveTLSState'-action occured.");
99  }
100  if (source == "") {
101  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
102  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
105  }
106  } else {
107  // get the logic
108  if (!myNet.getTLSControl().knows(source)) {
109  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
110  }
111  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
112  // build the action
114  }
115 }
116 
117 
118 void
120  const std::string& basePath) {
121  bool ok = true;
122  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
123  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
124  // check the parameter
125  if (dest == "" || !ok) {
126  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchTimes'-action occured.");
127  }
128  if (source == "") {
129  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
130  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
133  }
134  } else {
135  // get the logic
136  if (!myNet.getTLSControl().knows(source)) {
137  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
138  }
139  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
140  // build the action
142  }
143 }
144 
145 
146 void
148  const std::string& basePath) {
149  bool ok = true;
150  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
151  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
152  // check the parameter
153  if (dest == "" || !ok) {
154  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchStates'-action occured.");
155  }
156  if (source == "") {
157  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
158  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
161  }
162  } else {
163  // get the logic
164  if (!myNet.getTLSControl().knows(source)) {
165  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
166  }
167  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
168  // build the action
170  }
171 }
172 
173 
174 /****************************************************************************/
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:90
Encapsulated SAX-Attributes.
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:379
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.