Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SylvanBddManager.h
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4
8
9namespace storm::dft {
10namespace storage {
11
22 public:
30 SylvanBddManager() = default;
31
32 // We can only initialize Sylvan once therefore no copy semantics
34
37
41 ~SylvanBddManager() = default;
42
51 void execute(std::function<void()> const &f) const {
52 internalManager.execute(f);
53 }
54
60 uint32_t createVariable(std::string const name) {
61 nameToIndex[name] = nextFreeVariableIndex;
62 indexToName[nextFreeVariableIndex] = name;
63 sylvan::Bdd::bddVar(nextFreeVariableIndex);
64 return nextFreeVariableIndex++;
65 }
66
72 sylvan::Bdd getPositiveLiteral(std::string const name) const {
73 return sylvan::Bdd::bddVar(nameToIndex.at(name));
74 }
75
83 sylvan::Bdd getNegativeLiteral(std::string const name) const {
84 return !sylvan::Bdd::bddVar(nameToIndex.at(name));
85 }
86
92 sylvan::Bdd getPositiveLiteral(uint32_t const index) const {
93 return sylvan::Bdd::bddVar(index);
94 }
95
103 sylvan::Bdd getNegativeLiteral(uint32_t const index) const {
104 return !sylvan::Bdd::bddVar(index);
105 }
106
111 sylvan::Bdd getOne() {
112 return sylvan::Bdd::bddOne();
113 }
114
119 sylvan::Bdd getZero() {
120 return sylvan::Bdd::bddZero();
121 }
122
127 uint32_t getIndex(std::string const name) const {
128 return nameToIndex.at(name);
129 }
130
135 std::string getName(uint32_t const index) const {
136 return indexToName.at(index);
137 }
138
148 static void exportBddToDot(sylvan::Bdd const &bdd, std::string const &filename) {
149 FILE *filePointer = fopen(filename.c_str(), "w+");
150
151 // fopen returns a nullptr on failure
152 if (filePointer == nullptr) {
153 STORM_LOG_ERROR("Failure to open file: " << filename);
154 } else {
155 bdd.PrintDot(filePointer);
156 fclose(filePointer);
157 }
158 }
159
160 private:
162 uint32_t nextFreeVariableIndex{0};
163
164 std::map<std::string, uint32_t> nameToIndex{};
165 std::map<uint32_t, std::string> indexToName{};
166};
167
168} // namespace storage
169} // namespace storm::dft
sylvan::Bdd getNegativeLiteral(std::string const name) const
uint32_t createVariable(std::string const name)
Creates a variable with a unique name.
void execute(std::function< void()> const &f) const
All code that manipulates DDs shall be called through this function.
std::string getName(uint32_t const index) const
SylvanBddManager & operator=(SylvanBddManager &&)=default
sylvan::Bdd getPositiveLiteral(uint32_t const index) const
SylvanBddManager(SylvanBddManager &&)=default
sylvan::Bdd getPositiveLiteral(std::string const name) const
sylvan::Bdd getNegativeLiteral(uint32_t const index) const
SylvanBddManager()=default
Initializes Sylvan.
~SylvanBddManager()=default
Destroys Sylvan.
static void exportBddToDot(sylvan::Bdd const &bdd, std::string const &filename)
Exports the given Bdd to a file in the dot format.
SylvanBddManager(SylvanBddManager const &)=delete
uint32_t getIndex(std::string const name) const
#define STORM_LOG_ERROR(message)
Definition logging.h:31