Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
BackendConcepts.h
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <cstdint>
5#include <functional>
6#include <set>
7#include <string>
8#include <unordered_map>
9#include <utility>
10#include <vector>
11
12#include <boost/optional.hpp>
13
14#include "storm/dd/DdType.h"
15#include "storm/dd/Odd.h"
19
34namespace storm {
35namespace dd {
36
41template<typename BddType, typename AddType, typename ManagerType, typename ValueType>
43 std::copyable<BddType> && std::default_initializable<BddType> && std::equality_comparable<BddType> &&
44 requires(BddType const& b, BddType const& other, BddType& mb, std::vector<BddType> const& vars, AddType const& a, std::vector<uint_fast64_t> const& indices,
45 storm::dd::Odd const& odd, std::function<bool(uint_fast64_t)> const& filter, std::string const& file, std::vector<std::string> const& names,
47 std::vector<ValueType> const& src, std::vector<ValueType>& dst) {
48 // Construction.
49 { BddType::fromVector(std::declval<ManagerType const*>(), odd, indices, filter) } -> std::same_as<BddType>;
50
51 // Boolean connectives.
52 { b || other } -> std::same_as<BddType>;
53 { mb |= other } -> std::same_as<BddType&>;
54 { b && other } -> std::same_as<BddType>;
55 { mb &= other } -> std::same_as<BddType&>;
56 { b.iff(other) } -> std::same_as<BddType>;
57 { b.exclusiveOr(other) } -> std::same_as<BddType>;
58 { b.implies(other) } -> std::same_as<BddType>;
59 { !b } -> std::same_as<BddType>;
60 { mb.complement() } -> std::same_as<BddType&>;
61 { b.ite(other, other) } -> std::same_as<BddType>;
62 { b.ite(a, a) } -> std::same_as<AddType>;
63
64 // Quantification, restriction, relational operations. Cubes are passed as BDDs.
65 { b.existsAbstract(other) } -> std::same_as<BddType>;
66 { b.existsAbstractRepresentative(other) } -> std::same_as<BddType>;
67 { b.universalAbstract(other) } -> std::same_as<BddType>;
68 { b.constrain(other) } -> std::same_as<BddType>;
69 { b.restrict(other) } -> std::same_as<BddType>;
70 { b.swapVariables(vars, vars) } -> std::same_as<BddType>;
71 { b.relationalProduct(other, vars, vars) } -> std::same_as<BddType>;
72 { b.getSupport() } -> std::same_as<BddType>;
73 // The following could be derived from other operations
74 { b.andExists(other, other) } -> std::same_as<BddType>;
75 { b.inverseRelationalProduct(other, vars, vars) } -> std::same_as<BddType>;
76 { b.inverseRelationalProductWithExtendedRelation(other, vars, vars) } -> std::same_as<BddType>;
77
78 // Inspection.
79 { b.getNonZeroCount(uint_fast64_t{}) } -> std::same_as<uint_fast64_t>;
80 { b.getLeafCount() } -> std::same_as<uint_fast64_t>;
81 { b.getNodeCount() } -> std::same_as<uint_fast64_t>;
82 { b.isOne() } -> std::same_as<bool>;
83 { b.isZero() } -> std::same_as<bool>;
84 { b.getIndex() } -> std::same_as<uint_fast64_t>;
85 { b.getLevel() } -> std::same_as<uint_fast64_t>;
86
87 // Export.
88 b.exportToDot(file, names, bool{});
89 b.exportToText(file);
90
91 // Conversion to ADD and to explicit data structures (all driven by an ODD).
92 { b.template toAdd<ValueType>() } -> std::same_as<AddType>;
93 { std::hash<BddType>()(b) } -> std::convertible_to<std::size_t>;
94 // The following could be derived from other operations
95 { b.toVector(odd, indices) } -> std::same_as<storm::storage::BitVector>;
96 {
97 b.toExpression(em)
98 } -> std::same_as<std::pair<std::vector<storm::expressions::Expression>, std::unordered_map<uint_fast64_t, storm::expressions::Variable>>>;
99 { b.createOdd(indices) } -> std::same_as<storm::dd::Odd>;
100 b.template filterExplicitVector<ValueType>(odd, indices, src, dst);
101 b.filterExplicitVector(odd, indices, bits, outBits);
102 { b.splitIntoGroups(indices) } -> std::same_as<std::vector<BddType>>;
103 };
104
110template<typename AddType, typename BddType, typename ManagerType, typename ValueType, typename IteratorType, typename GenericManagerType>
112 std::copyable<AddType> && std::default_initializable<AddType> && std::equality_comparable<AddType> &&
113 requires(AddType const& a, AddType const& other, AddType& ma, BddType const& bdd, std::vector<BddType> const& vars, ValueType const& value,
114 ValueType const& precision, std::vector<uint_fast64_t> const& indices, std::vector<uint_fast64_t> const& offsets, storm::dd::Odd const& odd,
115 storm::storage::BitVector const& bits, std::vector<ValueType>& target, std::vector<ValueType> const& vec,
116 std::function<ValueType(ValueType const&, ValueType const&)> const& op, std::function<void(uint_fast64_t, ValueType const&)> const& visitor,
117 std::string const& file, std::vector<std::string> const& names, GenericManagerType const& manager,
118 std::set<storm::expressions::Variable> const& metaVariables) {
119 // Arithmetic.
120 { a + other } -> std::same_as<AddType>;
121 { ma += other } -> std::same_as<AddType&>;
122 { a * other } -> std::same_as<AddType>;
123 { ma *= other } -> std::same_as<AddType&>;
124 { a - other } -> std::same_as<AddType>;
125 { ma -= other } -> std::same_as<AddType&>;
126 { a / other } -> std::same_as<AddType>;
127 { ma /= other } -> std::same_as<AddType&>;
128 { a.pow(other) } -> std::same_as<AddType>;
129 { a.mod(other) } -> std::same_as<AddType>;
130 { a.logxy(other) } -> std::same_as<AddType>;
131 { a.floor() } -> std::same_as<AddType>;
132 { a.ceil() } -> std::same_as<AddType>;
133 { a.minimum(other) } -> std::same_as<AddType>;
134 { a.maximum(other) } -> std::same_as<AddType>;
135
136 // Comparisons (result is a BDD).
137 { a.equals(other) } -> std::same_as<BddType>;
138 { a.notEquals(other) } -> std::same_as<BddType>;
139 { a.less(other) } -> std::same_as<BddType>;
140 { a.lessOrEqual(other) } -> std::same_as<BddType>;
141 { a.greater(other) } -> std::same_as<BddType>;
142 { a.greaterOrEqual(other) } -> std::same_as<BddType>;
143 { a.less(value) } -> std::same_as<BddType>;
144 { a.lessOrEqual(value) } -> std::same_as<BddType>;
145 { a.greater(value) } -> std::same_as<BddType>;
146 { a.greaterOrEqual(value) } -> std::same_as<BddType>;
147 { a.notZero() } -> std::same_as<BddType>;
148 { a.equalModuloPrecision(other, precision, bool{}) } -> std::same_as<bool>;
149
150 // Abstraction and variable manipulation.
151 { a.sumAbstract(bdd) } -> std::same_as<AddType>;
152 { a.minAbstract(bdd) } -> std::same_as<AddType>;
153 { a.maxAbstract(bdd) } -> std::same_as<AddType>;
154 { a.minAbstractRepresentative(bdd) } -> std::same_as<BddType>;
155 { a.maxAbstractRepresentative(bdd) } -> std::same_as<BddType>;
156 { a.swapVariables(vars, vars) } -> std::same_as<AddType>;
157 { a.permuteVariables(vars, vars) } -> std::same_as<AddType>;
158 { a.multiplyMatrix(other, vars) } -> std::same_as<AddType>;
159 { a.multiplyMatrix(bdd, vars) } -> std::same_as<AddType>;
160 { a.constrain(other) } -> std::same_as<AddType>;
161 { a.restrict(other) } -> std::same_as<AddType>;
162 { a.getSupport() } -> std::same_as<BddType>;
163
164 // Inspection.
165 { a.getNonZeroCount(uint_fast64_t{}) } -> std::same_as<uint_fast64_t>;
166 { a.getLeafCount() } -> std::same_as<uint_fast64_t>;
167 { a.getNodeCount() } -> std::same_as<uint_fast64_t>;
168 { a.getMin() } -> std::same_as<ValueType>;
169 { a.getMax() } -> std::same_as<ValueType>;
170 { a.getValue() } -> std::same_as<ValueType>;
171 { a.isOne() } -> std::same_as<bool>;
172 { a.isZero() } -> std::same_as<bool>;
173 { a.isConstant() } -> std::same_as<bool>;
174 { a.getIndex() } -> std::same_as<uint_fast64_t>;
175 { a.getLevel() } -> std::same_as<uint_fast64_t>;
176 { a.getStringId() } -> std::same_as<std::string>;
177
178 // Export.
179 a.exportToDot(file, names, bool{});
180 a.exportToText(file);
181
182 // Iteration over (valuation, value) pairs.
183 { a.begin(manager, bdd, uint_fast64_t{}, metaVariables, bool{}) } -> std::same_as<IteratorType>;
184 { a.end(manager) } -> std::same_as<IteratorType>;
185
186 // Conversion to and from explicit data structures (all driven by an ODD).
187 { a.getInternalDdManager() } -> std::convertible_to<ManagerType const&>;
188 // The following could be derived from other operations
189 { AddType::fromVector(std::declval<ManagerType const*>(), vec, odd, indices) } -> std::same_as<AddType>;
190 { a.createOdd(indices) } -> std::same_as<storm::dd::Odd>;
191 a.composeWithExplicitVector(odd, indices, target, op);
192 a.composeWithExplicitVector(odd, indices, offsets, target, op);
193 a.forEach(odd, indices, visitor);
194 { a.splitIntoGroups(indices) } -> std::same_as<std::vector<AddType>>;
195 { a.decodeGroupLabels(indices, bits) } -> std::same_as<std::vector<uint64_t>>;
196 };
197
203template<typename ManagerType, typename BddType, typename AddType, typename EnvironmentType, typename ValueType>
205 std::constructible_from<ManagerType, EnvironmentType const&> && requires(ManagerType const& m, ManagerType& mm, std::function<void()> const& f) {
206 { m.getBddOne() } -> std::same_as<BddType>;
207 { m.getBddZero() } -> std::same_as<BddType>;
208 { m.template getAddOne<ValueType>() } -> std::same_as<AddType>;
209 { m.template getAddZero<ValueType>() } -> std::same_as<AddType>;
210 { m.template getConstant<ValueType>(ValueType{}) } -> std::same_as<AddType>;
211 { mm.createDdVariables(uint_fast64_t{}, std::declval<boost::optional<uint_fast64_t> const&>()) } -> std::same_as<std::vector<BddType>>;
212 { m.supportsOrderedInsertion() } -> std::same_as<bool>;
213 { m.getNumberOfDdVariables() } -> std::same_as<uint_fast64_t>;
214 m.execute(f);
215 // Could be derived from other operations
216 { m.getBddEncodingLessOrEqualThan(uint_fast64_t{}, std::declval<BddType const&>(), uint_fast64_t{}) } -> std::same_as<BddType>;
217
218 // These are present on every backend, but only functional if the corresponding trait is set.
219 mm.allowDynamicReordering(bool{});
220 { m.isDynamicReorderingAllowed() } -> std::same_as<bool>;
221 mm.triggerReordering();
222 m.debugCheck();
223 };
224
228template<typename IteratorType>
229concept AddIteratorBackend = std::default_initializable<IteratorType> && std::movable<IteratorType> && !std::copy_constructible<IteratorType> &&
230 requires(IteratorType& it, IteratorType const& cit) {
231 ++it;
232 *cit;
233 { cit == cit } -> std::convertible_to<bool>;
234 { cit != cit } -> std::convertible_to<bool>;
235 };
236
237} // namespace dd
238} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
Contract of AddIterator<T, ValueType>: a single-pass input iterator over (valuation,...
Contract of InternalAdd<T, ValueType>.
Contract of InternalBdd<T>.
Contract of InternalDdManager<T>.
The contract of a DD backend.