Storm 1.11.1.1
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
44#ifdef STORM_HAVE_SYLVAN
53 void execute(std::function<void()> const &f) const {
54 internalManager.execute(f);
55 }
56
62 uint32_t createVariable(std::string const name) {
63 nameToIndex[name] = nextFreeVariableIndex;
64 indexToName[nextFreeVariableIndex] = name;
65 sylvan::Bdd::bddVar(nextFreeVariableIndex);
66 return nextFreeVariableIndex++;
67 }
68
74 sylvan::Bdd getPositiveLiteral(std::string const name) const {
75 return sylvan::Bdd::bddVar(nameToIndex.at(name));
76 }
77
85 sylvan::Bdd getNegativeLiteral(std::string const name) const {
86 return !sylvan::Bdd::bddVar(nameToIndex.at(name));
87 }
88
94 sylvan::Bdd getPositiveLiteral(uint32_t const index) const {
95 return sylvan::Bdd::bddVar(index);
96 }
97
105 sylvan::Bdd getNegativeLiteral(uint32_t const index) const {
106 return !sylvan::Bdd::bddVar(index);
107 }
108
113 sylvan::Bdd getOne() {
114 return sylvan::Bdd::bddOne();
115 }
116
121 sylvan::Bdd getZero() {
122 return sylvan::Bdd::bddZero();
123 }
124
129 uint32_t getIndex(std::string const name) const {
130 return nameToIndex.at(name);
131 }
132
137 std::string getName(uint32_t const index) const {
138 return indexToName.at(index);
139 }
140
150 void exportBddToDot(sylvan::Bdd const &bdd, std::string const &filename) const {
151 FILE *filePointer = fopen(filename.c_str(), "w+");
152
153 // fopen returns a nullptr on failure
154 if (filePointer == nullptr) {
155 STORM_LOG_ERROR("Failure to open file: " << filename);
156 } else {
157 bdd.PrintDot(filePointer);
158 fclose(filePointer);
159 std::ofstream filestream;
160 storm::io::openFile(filename.c_str(), filestream, true);
161 filestream << "// Mapping from BDD nodes to DFT BEs as follows: \n";
162 for (auto const &[index, name] : indexToName) {
163 filestream << "// " << index << " -> " << name << '\n';
164 }
165 storm::io::closeFile(filestream);
166 }
167 }
168#else
169 void execute(std::function<void()> const &f) const {
170 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
171 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
172 "version of Storm with Sylvan support.");
173 }
174
175 uint32_t createVariable(std::string const name) {
176 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
177 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
178 "version of Storm with Sylvan support.");
179 }
180
181 uint32_t getIndex(std::string const name) const {
182 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
183 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
184 "version of Storm with Sylvan support.");
185 }
186
187 std::string getName(uint32_t const index) const {
188 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
189 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
190 "version of Storm with Sylvan support.");
191 }
192#endif
193
194 private:
195#ifdef STORM_HAVE_SYLVAN
197 uint32_t nextFreeVariableIndex{0};
198
199 std::map<std::string, uint32_t> nameToIndex{};
200 std::map<uint32_t, std::string> indexToName{};
201#endif
202};
203
204} // namespace storage
205} // namespace storm::dft
uint32_t createVariable(std::string const name)
void execute(std::function< void()> const &f) const
std::string getName(uint32_t const index) const
SylvanBddManager & operator=(SylvanBddManager &&)=default
SylvanBddManager(SylvanBddManager &&)=default
SylvanBddManager()=default
Initializes Sylvan.
~SylvanBddManager()=default
Destroys Sylvan.
SylvanBddManager(SylvanBddManager const &)=delete
uint32_t getIndex(std::string const name) const
#define STORM_LOG_ERROR(message)
Definition logging.h:26
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
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