SUMO - Simulation of Urban MObility
NLDiscreteEventBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // }
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 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 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "NLDiscreteEventBuilder.h"
36 #include <microsim/MSNet.h>
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
52  : myNet(net) {
53  myActions["SaveTLSStates"] = EV_SAVETLSTATE;
54  myActions["SaveTLSSwitchTimes"] = EV_SAVETLSWITCHES;
55  myActions["SaveTLSSwitchStates"] = EV_SAVETLSWITCHSTATES;
56 }
57 
58 
60 
61 
62 void
64  const std::string& basePath) {
65  bool ok = true;
66  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, 0, ok, "");
67  // check whether the type was given
68  if (type == "" || !ok) {
69  throw InvalidArgument("An action's type is not given.");
70  }
71  // get the numerical representation
72  KnownActions::iterator i = myActions.find(type);
73  if (i == myActions.end()) {
74  throw InvalidArgument("The action type '" + type + "' is not known.");
75  }
76  // build the action
77  switch ((*i).second) {
78  case EV_SAVETLSTATE:
79  buildSaveTLStateCommand(attrs, basePath);
80  break;
81  case EV_SAVETLSWITCHES:
82  buildSaveTLSwitchesCommand(attrs, basePath);
83  break;
85  buildSaveTLSwitchStatesCommand(attrs, basePath);
86  break;
87  }
88 }
89 
90 
91 void
93  const std::string& basePath) {
94  bool ok = true;
95  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
96  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
97  // check the parameter
98  if (dest == "" || !ok) {
99  throw InvalidArgument("Incomplete description of an 'SaveTLSState'-action occured.");
100  }
101  if (source == "") {
102  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
103  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
106  }
107  } else {
108  // get the logic
109  if (!myNet.getTLSControl().knows(source)) {
110  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
111  }
112  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
113  // build the action
115  }
116 }
117 
118 
119 void
121  const std::string& basePath) {
122  bool ok = true;
123  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
124  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
125  // check the parameter
126  if (dest == "" || !ok) {
127  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchTimes'-action occured.");
128  }
129  if (source == "") {
130  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
131  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
134  }
135  } else {
136  // get the logic
137  if (!myNet.getTLSControl().knows(source)) {
138  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
139  }
140  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
141  // build the action
143  }
144 }
145 
146 
147 void
149  const std::string& basePath) {
150  bool ok = true;
151  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
152  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
153  // check the parameter
154  if (dest == "" || !ok) {
155  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchStates'-action occured.");
156  }
157  if (source == "") {
158  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
159  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
162  }
163  } else {
164  // get the logic
165  if (!myNet.getTLSControl().knows(source)) {
166  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
167  }
168  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
169  // build the action
171  }
172 }
173 
174 
175 /****************************************************************************/
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:94
Encapsulated SAX-Attributes.
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:383
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.