Storm 1.14.0.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
8#include "storm/io/file.h"
11
12namespace storm::dft {
13namespace storage {
14
25 public:
36#ifdef STORM_HAVE_SYLVAN
37 explicit SylvanBddManager(storm::Environment const &env) : internalManager{env.dd().get<storm::dd::DdType::Sylvan>()} {}
38#else
40 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
41 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
42 "version of Storm with Sylvan support.");
43 }
44#endif
45
49 static std::shared_ptr<SylvanBddManager> createWithDefaultEnvironment() {
50 return std::make_shared<SylvanBddManager>(storm::Environment());
51 }
52
53 // We can only initialize Sylvan once therefore no copy semantics
55
58
62 ~SylvanBddManager() = default;
63
64#ifdef STORM_HAVE_SYLVAN
73 void execute(std::function<void()> const &f) const {
74 internalManager.execute(f);
75 }
76
82 uint32_t createVariable(std::string const name) {
83 nameToIndex[name] = nextFreeVariableIndex;
84 indexToName[nextFreeVariableIndex] = name;
85 sylvan::Bdd::bddVar(nextFreeVariableIndex);
86 return nextFreeVariableIndex++;
87 }
88
94 sylvan::Bdd getPositiveLiteral(std::string const name) const {
95 return sylvan::Bdd::bddVar(nameToIndex.at(name));
96 }
97
105 sylvan::Bdd getNegativeLiteral(std::string const name) const {
106 return !sylvan::Bdd::bddVar(nameToIndex.at(name));
107 }
108
114 sylvan::Bdd getPositiveLiteral(uint32_t const index) const {
115 return sylvan::Bdd::bddVar(index);
116 }
117
125 sylvan::Bdd getNegativeLiteral(uint32_t const index) const {
126 return !sylvan::Bdd::bddVar(index);
127 }
128
133 sylvan::Bdd getOne() {
134 return sylvan::Bdd::bddOne();
135 }
136
141 sylvan::Bdd getZero() {
142 return sylvan::Bdd::bddZero();
143 }
144
149 uint32_t getIndex(std::string const name) const {
150 return nameToIndex.at(name);
151 }
152
157 std::string getName(uint32_t const index) const {
158 return indexToName.at(index);
159 }
160
170 void exportBddToDot(sylvan::Bdd const &bdd, std::string const &filename) const {
171 FILE *filePointer = fopen(filename.c_str(), "w+");
172
173 // fopen returns a nullptr on failure
174 if (filePointer == nullptr) {
175 STORM_LOG_ERROR("Failure to open file: " << filename);
176 } else {
177 bdd.PrintDot(filePointer);
178 fclose(filePointer);
179 std::ofstream filestream;
180 storm::io::openFile(filename, filestream, true);
181 filestream << "// Mapping from BDD nodes to DFT BEs as follows: \n";
182 for (auto const &[index, name] : indexToName) {
183 filestream << "// " << index << " -> " << name << '\n';
184 }
185 storm::io::closeFile(filestream);
186 }
187 }
188#else
189 void execute(std::function<void()> const &f) const {
190 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
191 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
192 "version of Storm with Sylvan support.");
193 }
194
195 uint32_t createVariable(std::string const name) {
196 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
197 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
198 "version of Storm with Sylvan support.");
199 }
200
201 uint32_t getIndex(std::string const name) const {
202 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
203 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
204 "version of Storm with Sylvan support.");
205 }
206
207 std::string getName(uint32_t const index) const {
208 STORM_LOG_THROW(false, storm::exceptions::MissingLibraryException,
209 "This version of Storm was compiled without support for Sylvan. Yet, a method was called that requires this support. Please choose a "
210 "version of Storm with Sylvan support.");
211 }
212#endif
213
214 private:
215#ifdef STORM_HAVE_SYLVAN
217 uint32_t nextFreeVariableIndex{0};
218
219 std::map<std::string, uint32_t> nameToIndex{};
220 std::map<uint32_t, std::string> indexToName{};
221#endif
222};
223
224} // namespace storage
225} // namespace storm::dft
DdEnvironmentSelector< Type >::type & get()
Retrieves the sub-environment belonging to the given DD type.
DdEnvironment & dd()
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(storm::Environment const &)
Initializes Sylvan.
~SylvanBddManager()=default
Destroys Sylvan.
static std::shared_ptr< SylvanBddManager > createWithDefaultEnvironment()
Creates a new manager that is configured according to a default environment.
SylvanBddManager(SylvanBddManager const &)=delete
uint32_t getIndex(std::string const name) const
#define STORM_LOG_ERROR(message)
Definition logging.h:29
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
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