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
6#include "storm/io/file.h"
9
10namespace storm::dft {
11namespace storage {
12
23 public:
31 SylvanBddManager() = default;
32
33 // We can only initialize Sylvan once therefore no copy semantics
35
38
42 ~SylvanBddManager() = default;
43
52 void execute(std::function<void()> const &f) const {
53 internalManager.execute(f);
54 }
55
61 uint32_t createVariable(std::string const name) {
62 nameToIndex[name] = nextFreeVariableIndex;
63 indexToName[nextFreeVariableIndex] = name;
64 sylvan::Bdd::bddVar(nextFreeVariableIndex);
65 return nextFreeVariableIndex++;
66 }
67
73 sylvan::Bdd getPositiveLiteral(std::string const name) const {
74 return sylvan::Bdd::bddVar(nameToIndex.at(name));
75 }
76
84 sylvan::Bdd getNegativeLiteral(std::string const name) const {
85 return !sylvan::Bdd::bddVar(nameToIndex.at(name));
86 }
87
93 sylvan::Bdd getPositiveLiteral(uint32_t const index) const {
94 return sylvan::Bdd::bddVar(index);
95 }
96
104 sylvan::Bdd getNegativeLiteral(uint32_t const index) const {
105 return !sylvan::Bdd::bddVar(index);
106 }
107
112 sylvan::Bdd getOne() {
113 return sylvan::Bdd::bddOne();
114 }
115
120 sylvan::Bdd getZero() {
121 return sylvan::Bdd::bddZero();
122 }
123
128 uint32_t getIndex(std::string const name) const {
129 return nameToIndex.at(name);
130 }
131
136 std::string getName(uint32_t const index) const {
137 return indexToName.at(index);
138 }
139
149 void exportBddToDot(sylvan::Bdd const &bdd, std::string const &filename) const {
150 FILE *filePointer = fopen(filename.c_str(), "w+");
151
152 // fopen returns a nullptr on failure
153 if (filePointer == nullptr) {
154 STORM_LOG_ERROR("Failure to open file: " << filename);
155 } else {
156 bdd.PrintDot(filePointer);
157 fclose(filePointer);
158 std::ofstream filestream;
159 storm::io::openFile(filename.c_str(), filestream, true);
160 filestream << "// Mapping from BDD nodes to DFT BEs as follows: \n";
161 for (auto const &[index, name] : indexToName) {
162 filestream << "// " << index << " -> " << name << '\n';
163 }
164 storm::io::closeFile(filestream);
165 }
166 }
167
168 private:
170 uint32_t nextFreeVariableIndex{0};
171
172 std::map<std::string, uint32_t> nameToIndex{};
173 std::map<uint32_t, std::string> indexToName{};
174};
175
176} // namespace storage
177} // 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.
void exportBddToDot(sylvan::Bdd const &bdd, std::string const &filename) const
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
void closeFile(std::ofstream &stream)
Close the given file after writing.
Definition file.h:47
void openFile(std::string const &filepath, std::ofstream &filestream, bool append=false, bool silent=false)
Open the given file for writing.
Definition file.h:18