VDS Class Project
Loading...
Searching...
No Matches
Manager.h
Go to the documentation of this file.
1// A minimalistic BDD library, following Wolfgang Kunz lecture slides
2//
3// Created by Markus Wedler 2014
4
5#ifndef VDSPROJECT_MANAGER_H
6#define VDSPROJECT_MANAGER_H
7
8#include "ManagerInterface.h"
9#include <unordered_map>
10#include <string>
11#include <vector>
12
13namespace ClassProject
14{
15
17 {
18 public:
19 Manager();
20
21 struct Node
22 {
26 std::string label;
27 };
28
35 {
39
40 bool operator==(const Unique_Table_Key &other) const
41 {
42 return TopVar == other.TopVar && low == other.low && high == other.high;
43 }
44 };
45
51 /*struct Unique_Table_Entry
52 {
53 BDD_ID id;
54 };*/
55
62 struct KeyHash
63 {
64 std::size_t operator()(const Unique_Table_Key &k) const
65 {
66 // A hash function
67 return ((std::hash<BDD_ID>()(k.TopVar) ^ (std::hash<BDD_ID>()(k.low) << 1)) >> 1) ^ (std::hash<BDD_ID>()(k.high) << 1);
68 }
69 };
70
71 std::unordered_map<Unique_Table_Key, BDD_ID, KeyHash> Table;
72 std::vector<Node> id_table;
73 std::unordered_map<Unique_Table_Key,BDD_ID,KeyHash> computed_table;
74
75 BDD_ID createVar(const std::string &label) override;
76 const BDD_ID &True() override;
77 const BDD_ID &False() override;
78 bool isConstant(BDD_ID f) override;
79 bool isVariable(BDD_ID x) override;
80 BDD_ID topVar(BDD_ID f) override;
81 std::string getTopVarName(const BDD_ID &root) override;
82 BDD_ID coFactorTrue(BDD_ID f, BDD_ID x) override;
83 BDD_ID coFactorFalse(BDD_ID f, BDD_ID x) override;
84 BDD_ID coFactorTrue(BDD_ID f) override;
85 BDD_ID coFactorFalse(BDD_ID f) override;
86 BDD_ID ite(BDD_ID i, BDD_ID t, BDD_ID e) override;
87 void findNodes(const BDD_ID &root, std::set<BDD_ID> &nodes_of_root) override;
88 void findVars(const BDD_ID &root, std::set<BDD_ID> &vars_of_root) override;
89 size_t uniqueTableSize() override;
90 BDD_ID neg(BDD_ID a) override;
91 BDD_ID and2(BDD_ID a, BDD_ID b) override;
92 BDD_ID or2(BDD_ID a, BDD_ID b) override;
93 BDD_ID xor2(BDD_ID a, BDD_ID b) override;
94 BDD_ID nand2(BDD_ID a, BDD_ID b) override;
95 BDD_ID nor2(BDD_ID a, BDD_ID b) override;
96 BDD_ID xnor2(BDD_ID a, BDD_ID b) override;
97 void visualizeBDD(std::string filepath, BDD_ID &root) override;
98 };
99}
100
101#endif
Definition ManagerInterface.h:15
Definition Manager.h:17
size_t uniqueTableSize() override
Definition Manager.cpp:501
BDD_ID coFactorTrue(BDD_ID f, BDD_ID x) override
Definition Manager.cpp:199
void visualizeBDD(std::string filepath, BDD_ID &root) override
Definition Manager.cpp:402
BDD_ID nand2(BDD_ID a, BDD_ID b) override
nand2
Definition Manager.cpp:370
const BDD_ID & True() override
True.
Definition Manager.cpp:72
bool isVariable(BDD_ID x) override
isVariable
Definition Manager.cpp:113
BDD_ID xor2(BDD_ID a, BDD_ID b) override
xor2
Definition Manager.cpp:357
BDD_ID ite(BDD_ID i, BDD_ID t, BDD_ID e) override
Definition Manager.cpp:154
std::unordered_map< Unique_Table_Key, BDD_ID, KeyHash > Table
Definition Manager.h:71
BDD_ID and2(BDD_ID a, BDD_ID b) override
and2
Definition Manager.cpp:333
BDD_ID coFactorFalse(BDD_ID f, BDD_ID x) override
Definition Manager.cpp:237
const BDD_ID & False() override
False.
Definition Manager.cpp:60
BDD_ID createVar(const std::string &label) override
createVar
Definition Manager.cpp:40
Manager()
Definition Manager.cpp:20
BDD_ID neg(BDD_ID a) override
neg
Definition Manager.cpp:320
std::unordered_map< Unique_Table_Key, BDD_ID, KeyHash > computed_table
Definition Manager.h:73
BDD_ID xnor2(BDD_ID a, BDD_ID b) override
xnor2
Definition Manager.cpp:396
BDD_ID topVar(BDD_ID f) override
topVar
Definition Manager.cpp:137
std::vector< Node > id_table
Definition Manager.h:72
BDD_ID nor2(BDD_ID a, BDD_ID b) override
nor2
Definition Manager.cpp:383
bool isConstant(BDD_ID f) override
isConstant
Definition Manager.cpp:85
BDD_ID or2(BDD_ID a, BDD_ID b) override
or2
Definition Manager.cpp:345
void findNodes(const BDD_ID &root, std::set< BDD_ID > &nodes_of_root) override
Definition Manager.cpp:301
void findVars(const BDD_ID &root, std::set< BDD_ID > &vars_of_root) override
Definition Manager.cpp:488
std::string getTopVarName(const BDD_ID &root) override
getTopVarName
Definition Manager.cpp:282
ClassProject Class.
Definition Manager.cpp:18
size_t BDD_ID
Definition ManagerInterface.h:13
Unique_Table_Entry Defines a structure to be used as a value in the hash map.
Definition Manager.h:63
std::size_t operator()(const Unique_Table_Key &k) const
Definition Manager.h:64
Definition Manager.h:22
BDD_ID high
Definition Manager.h:25
std::string label
Definition Manager.h:26
BDD_ID low
Definition Manager.h:24
BDD_ID TopVar
Definition Manager.h:23
Unique_Table_Key Defines a structure to be used as a key in the hash map.
Definition Manager.h:35
bool operator==(const Unique_Table_Key &other) const
Definition Manager.h:40
BDD_ID low
Definition Manager.h:37
BDD_ID TopVar
Definition Manager.h:36
BDD_ID high
Definition Manager.h:38