LydiaSyft
VarMgr.h
1 #ifndef VAR_MGR_H
2 #define VAR_MGR_H
3 
4 #include <memory>
5 #include <unordered_map>
6 #include <vector>
7 
8 #include "cuddObj.hh"
9 
10 namespace Syft {
11 
15  class VarMgr {
16  private:
17 
18  std::shared_ptr<CUDD::Cudd> mgr_;
19  std::unordered_map<int, std::string> index_to_name_;
20  std::unordered_map<std::string, CUDD::BDD> name_to_variable_;
21  std::size_t state_variable_count_ = 0;
22  std::vector<std::vector<CUDD::BDD>> state_variables_;
23  std::vector<CUDD::BDD> input_variables_;
24  std::vector<CUDD::BDD> output_variables_;
25  std::size_t total_variable_count_ = 0;
26 
27  public:
28 
32  VarMgr();
33 
40  void create_named_variables(const std::vector<std::string> &variable_names);
41 
52  std::size_t create_state_variables(std::size_t variable_count);
53 
66  std::size_t create_product_state_space(
67  const std::vector<std::size_t> &automaton_ids);
68 
69 
73  CUDD::BDD state_variable(std::size_t automaton_id, std::size_t i) const;
74 
85  CUDD::BDD state_vector_to_bdd(std::size_t automaton_id,
86  const std::vector<int> &state_vector) const;
87 
96  void partition_variables(const std::vector<std::string> &input_names,
97  const std::vector<std::string> &output_names);
98 
102  std::shared_ptr<CUDD::Cudd> cudd_mgr() const;
103 
107  CUDD::BDD name_to_variable(const std::string &name) const;
108 
112  std::string index_to_name(int index) const;
113 
117  std::size_t total_variable_count() const;
118 
122  std::size_t total_state_variable_count() const;
123 
127  std::size_t state_variable_count(std::size_t automaton_id) const;
128 
132  std::size_t input_variable_count() const;
133 
137  std::size_t output_variable_count() const;
138 
142  CUDD::BDD input_cube() const;
143 
147  CUDD::BDD output_cube() const;
148 
152  CUDD::BDD state_variables_cube(std::size_t automaton_id) const;
153 
165  std::vector<int> make_eval_vector(std::size_t automaton_id,
166  const std::vector<int> &state_vector) const;
167 
179  std::vector<int> make_state_eval_vector(std::size_t automaton_id,
180  const std::vector<int> &state_vector) const;
181 
194  std::vector<CUDD::BDD> make_compose_vector(
195  std::size_t automaton_id,
196  const std::vector<CUDD::BDD> &state_bdds) const;
197 
208  std::vector<std::string> variable_labels() const;
209 
218  std::vector<std::string> input_variable_labels() const;
219 
228  std::vector<std::string> output_variable_labels() const;
229 
238  std::vector<std::string> state_variable_labels(
239  std::size_t automaton_id) const;
240 
249  void dump_dot(const CUDD::ADD &add, const std::string &filename) const;
250 
260  void dump_dot(const std::vector<CUDD::ADD> &adds,
261  const std::vector<std::string> &function_labels,
262  const std::string &filename) const;
263 
268  std::size_t automaton_num() const;
269 
276  std::string bdd_to_string(const CUDD::BDD &bdd) const;
277 
282  std::size_t create_complement_state_space(
283  const std::size_t automaton_id);
284  };
285 
286 }
287 
288 #endif // VAR_MGR_H
A dictionary that maps variable names to indices and vice versa.
Definition: VarMgr.h:15
std::vector< int > make_state_eval_vector(std::size_t automaton_id, const std::vector< int > &state_vector) const
Creates a valid input to CUDD::BDD::Eval.
Definition: VarMgr.cpp:184
std::string index_to_name(int index) const
Returns the name of the variable at index index.
Definition: VarMgr.cpp:136
std::size_t automaton_num() const
Returns the number of DFAs the manager handles.
Definition: VarMgr.cpp:334
std::vector< std::string > output_variable_labels() const
Returns a vector with a label for each output variable.
Definition: VarMgr.cpp:250
VarMgr()
Constructs a VarMgr with no variables.
Definition: VarMgr.cpp:10
CUDD::BDD input_cube() const
Returns a BDD formed by the conjunction of all input variables.
Definition: VarMgr.cpp:160
std::size_t create_complement_state_space(const std::size_t automaton_id)
Create the state space when complementing a DFA.
Definition: VarMgr.cpp:67
std::shared_ptr< CUDD::Cudd > cudd_mgr() const
Returns the CUDD manager used to create the variables.
Definition: VarMgr.cpp:128
CUDD::BDD name_to_variable(const std::string &name) const
Returns the index of the variable with the given name.
Definition: VarMgr.cpp:132
std::size_t total_state_variable_count() const
Returns the total number of state variables.
Definition: VarMgr.cpp:144
std::vector< std::string > input_variable_labels() const
Returns a vector with a label for each input variable.
Definition: VarMgr.cpp:261
CUDD::BDD state_variable(std::size_t automaton_id, std::size_t i) const
Returns the i-th state variable for a given automaton.
Definition: VarMgr.cpp:81
void create_named_variables(const std::vector< std::string > &variable_names)
Creates BDD variables and associates each with a name.
Definition: VarMgr.cpp:14
std::vector< std::string > state_variable_labels(std::size_t automaton_id) const
Returns a vector with a label for each state variable.
Definition: VarMgr.cpp:272
std::string bdd_to_string(const CUDD::BDD &bdd) const
Prints a BDD as a Boolean formula, where each variable has a specific label.
Definition: VarMgr.cpp:338
CUDD::BDD state_vector_to_bdd(std::size_t automaton_id, const std::vector< int > &state_vector) const
Converts a state vector to a BDD.
Definition: VarMgr.cpp:86
void partition_variables(const std::vector< std::string > &input_names, const std::vector< std::string > &output_names)
Partitions the named variables between inputs and outputs.
Definition: VarMgr.cpp:102
void dump_dot(const CUDD::ADD &add, const std::string &filename) const
Saves an ADD in a .dot file.
Definition: VarMgr.cpp:286
CUDD::BDD output_cube() const
Returns a BDD formed by the conjunction of all output variables.
Definition: VarMgr.cpp:164
std::size_t input_variable_count() const
Returns the number of input variables.
Definition: VarMgr.cpp:152
std::size_t output_variable_count() const
Returns the number of output variables.
Definition: VarMgr.cpp:156
std::size_t state_variable_count(std::size_t automaton_id) const
Returns the number of state variables for a given automaton.
Definition: VarMgr.cpp:148
std::size_t create_product_state_space(const std::vector< std::size_t > &automaton_ids)
Registers a new automaton ID associated with a product state space.
Definition: VarMgr.cpp:51
std::size_t create_state_variables(std::size_t variable_count)
Creates and stores state variables.
Definition: VarMgr.cpp:27
std::size_t total_variable_count() const
Returns the total number of variables, including named and state.
Definition: VarMgr.cpp:140
std::vector< int > make_eval_vector(std::size_t automaton_id, const std::vector< int > &state_vector) const
Creates a valid input to CUDD::BDD::Eval.
Definition: VarMgr.cpp:172
std::vector< CUDD::BDD > make_compose_vector(std::size_t automaton_id, const std::vector< CUDD::BDD > &state_bdds) const
Creates a valid input to CUDD::BDD::VectorCompose.
Definition: VarMgr.cpp:196
CUDD::BDD state_variables_cube(std::size_t automaton_id) const
Returns a BDD formed by the conjunction of all state variables of automaton automaton_id.
Definition: VarMgr.cpp:168
std::vector< std::string > variable_labels() const
Returns a vector with a label for each variable.
Definition: VarMgr.cpp:233