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-2015 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 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56  : myNet(net) {
57  myActions["SaveTLSStates"] = EV_SAVETLSTATE;
58  myActions["SaveTLSSwitchTimes"] = EV_SAVETLSWITCHES;
59  myActions["SaveTLSSwitchStates"] = EV_SAVETLSWITCHSTATES;
60 }
61 
62 
64 
65 
66 void
68  const std::string& basePath) {
69  bool ok = true;
70  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, 0, ok, "");
71  // check whether the type was given
72  if (type == "" || !ok) {
73  throw InvalidArgument("An action's type is not given.");
74  }
75  // get the numerical representation
76  KnownActions::iterator i = myActions.find(type);
77  if (i == myActions.end()) {
78  throw InvalidArgument("The action type '" + type + "' is not known.");
79  }
80  // build the action
81  switch ((*i).second) {
82  case EV_SAVETLSTATE:
83  buildSaveTLStateCommand(attrs, basePath);
84  break;
85  case EV_SAVETLSWITCHES:
86  buildSaveTLSwitchesCommand(attrs, basePath);
87  break;
89  buildSaveTLSwitchStatesCommand(attrs, basePath);
90  break;
91  }
92 }
93 
94 
95 void
97  const std::string& basePath) {
98  bool ok = true;
99  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
100  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
101  // check the parameter
102  if (dest == "" || !ok) {
103  throw InvalidArgument("Incomplete description of an 'SaveTLSState'-action occured.");
104  }
105  if (source == "") {
106  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
107  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
110  }
111  } else {
112  // get the logic
113  if (!myNet.getTLSControl().knows(source)) {
114  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
115  }
116  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
117  // build the action
119  }
120 }
121 
122 
123 void
125  const std::string& basePath) {
126  bool ok = true;
127  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
128  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
129  // check the parameter
130  if (dest == "" || !ok) {
131  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchTimes'-action occured.");
132  }
133  if (source == "") {
134  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
135  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
138  }
139  } else {
140  // get the logic
141  if (!myNet.getTLSControl().knows(source)) {
142  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
143  }
144  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
145  // build the action
147  }
148 }
149 
150 
151 void
153  const std::string& basePath) {
154  bool ok = true;
155  const std::string dest = attrs.getOpt<std::string>(SUMO_ATTR_DEST, 0, ok, "");
156  const std::string source = attrs.getOpt<std::string>(SUMO_ATTR_SOURCE, 0, ok, "");
157  // check the parameter
158  if (dest == "" || !ok) {
159  throw InvalidArgument("Incomplete description of an 'SaveTLSSwitchStates'-action occured.");
160  }
161  if (source == "") {
162  const std::vector<std::string> ids = myNet.getTLSControl().getAllTLIds();
163  for (std::vector<std::string>::const_iterator tls = ids.begin(); tls != ids.end(); ++tls) {
166  }
167  } else {
168  // get the logic
169  if (!myNet.getTLSControl().knows(source)) {
170  throw InvalidArgument("The traffic light logic to save (" + source + ") is not known.");
171  }
172  const MSTLLogicControl::TLSLogicVariants& logics = myNet.getTLSControl().get(source);
173  // build the action
175  }
176 }
177 
178 
179 /****************************************************************************/
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.
std::vector< std::string > getAllTLIds() const
The simulated network and simulation perfomer.
Definition: MSNet.h:94
Encapsulated SAX-Attributes.
MSTLLogicControl & getTLSControl()
Returns the tls logics control.
Definition: MSNet.h:349
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.
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
Writes the state of the tls to a file (in each second)
NLDiscreteEventBuilder(MSNet &net)
Constructor.
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.
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.
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.
void buildSaveTLSwitchStatesCommand(const SUMOSAXAttributes &attrs, const std::string &basePath)
Builds an action which saves the switch times and states of tls into a file.