Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DFTASFChecker.cpp
Go to the documentation of this file.
1#include "DFTASFChecker.h"
2
3#include <string>
4
11#include "storm/io/file.h"
15
16namespace storm::dft {
17namespace modelchecker {
18
20 // Intentionally left empty.
21}
22
23uint64_t DFTASFChecker::getClaimVariableIndex(uint64_t spare, uint64_t child) const {
24 return claimVariables.at(SpareAndChildPair(spare, child));
25}
26
28 std::vector<uint64_t> beVariables;
29 uint64_t failedBeVariables;
30 std::vector<uint64_t> failsafeBeVariables;
31 bool failedBeIsSet = false;
32 notFailed = dft.nrBasicElements() + 1; // Value indicating the element is not failed
33
34 // Initialize variables
35 for (size_t i = 0; i < dft.nrElements(); ++i) {
36 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(i);
37 varNames.push_back("t_" + element->name());
38 timePointVariables.emplace(i, varNames.size() - 1);
39 switch (element->type()) {
41 auto be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<double> const>(element);
42 switch (be->beType()) {
44 beVariables.push_back(varNames.size() - 1);
45 break;
47 STORM_LOG_WARN("Constant BEs are only experimentally supported in the SMT encoding");
48 // Constant BEs are initially either failed or failsafe, treat them differently
49 auto be = std::static_pointer_cast<storm::dft::storage::elements::BEConst<double> const>(element);
50 if (be->failed()) {
51 STORM_LOG_THROW(!failedBeIsSet, storm::exceptions::NotSupportedException,
52 "DFTs containing more than one constantly failed BE are not supported.");
53 notFailed = dft.nrBasicElements();
54 failedBeVariables = varNames.size() - 1;
55 failedBeIsSet = true;
56 } else {
57 failsafeBeVariables.push_back(varNames.size() - 1);
58 }
59 break;
60 }
61 default:
62 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "BE type '" << be->beType() << "' not known.");
63 break;
64 }
65 break;
66 }
68 auto spare = std::static_pointer_cast<storm::dft::storage::elements::DFTSpare<double> const>(element);
69 for (auto const &spareChild : spare->children()) {
70 varNames.push_back("c_" + element->name() + "_" + spareChild->name());
71 claimVariables.emplace(SpareAndChildPair(element->id(), spareChild->id()), varNames.size() - 1);
72 }
73 break;
74 }
76 varNames.push_back("dep_" + element->name());
77 dependencyVariables.emplace(element->id(), varNames.size() - 1);
78 break;
79 }
80 default:
81 break;
82 }
83 }
84 // Initialize variables indicating Markovian states
85 for (size_t i = 0; i < dft.nrBasicElements(); ++i) {
86 varNames.push_back("m_" + std::to_string(i));
87 markovianVariables.emplace(i, varNames.size() - 1);
88 }
89
90 // Generate constraints
91
92 // All exponential BEs have to fail (first part of constraint 12)
93 for (auto const &beV : beVariables) {
94 constraints.push_back(std::make_shared<BetweenValues>(beV, 1, notFailed - 1));
95 }
96
97 // Constantly failsafe BEs may also be fail-safe
98 for (auto const &beV : failsafeBeVariables) {
99 constraints.push_back(std::make_shared<BetweenValues>(beV, 1, notFailed));
100 }
101
102 // Constantly failed BEs fail before other types
103 if (failedBeIsSet) {
104 constraints.push_back(std::make_shared<IsConstantValue>(failedBeVariables, 0));
105 }
106
107 std::vector<uint64_t> allBeVariables;
108 allBeVariables.insert(std::end(allBeVariables), std::begin(beVariables), std::end(beVariables));
109 allBeVariables.insert(std::end(allBeVariables), std::begin(failsafeBeVariables), std::end(failsafeBeVariables));
110
111 // No two exponential BEs fail at the same time (second part of constraint 12)
112 if (beVariables.size() > 1) {
113 constraints.push_back(std::make_shared<PairwiseDifferent>(beVariables));
114 constraints.back()->setDescription("No two BEs fail at the same time");
115 }
116
117 bool descFlag = true;
118 for (auto const &failsafeBe : failsafeBeVariables) {
119 std::vector<std::shared_ptr<SmtConstraint>> unequalConstraints;
120 for (auto const &otherBe : allBeVariables) {
121 if (otherBe != failsafeBe) {
122 unequalConstraints.push_back(std::make_shared<IsUnequal>(failsafeBe, otherBe));
123 }
124 }
125 constraints.push_back(
126 std::make_shared<Implies>(std::make_shared<IsNotConstantValue>(failsafeBe, notFailed), std::make_shared<And>(unequalConstraints)));
127 if (descFlag) {
128 constraints.back()->setDescription("Initially failsafe BEs don't fail at the same time as other BEs");
129 descFlag = false;
130 }
131 }
132
133 // Initialize claim variables in [1, |BE|+1]
134 for (auto const &claimVariable : claimVariables) {
135 constraints.push_back(std::make_shared<BetweenValues>(claimVariable.second, 0, notFailed));
136 }
137
138 // Encoding for gates
139 for (size_t i = 0; i < dft.nrElements(); ++i) {
140 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(i);
141 STORM_LOG_ASSERT(i == element->id(), "Id and index should match.");
142
143 // Get indices for gate children
144 std::vector<uint64_t> childVarIndices;
145 if (element->isGate()) {
146 std::shared_ptr<storm::dft::storage::elements::DFTGate<ValueType> const> gate = dft.getGate(i);
147 for (auto const &child : gate->children()) {
148 childVarIndices.push_back(timePointVariables.at(child->id()));
149 }
150 }
151
152 switch (element->type()) {
154 // BEs were already considered before
155 break;
157 generateAndConstraint(i, childVarIndices, element);
158 break;
160 generateOrConstraint(i, childVarIndices, element);
161 break;
163 generateVotConstraint(i, childVarIndices, element);
164 break;
166 generatePandConstraint(i, childVarIndices, element);
167 break;
169 generatePorConstraint(i, childVarIndices, element);
170 break;
172 generateSeqConstraint(childVarIndices, element);
173 break;
175 generateSpareConstraint(i, childVarIndices, element);
176 break;
178 generatePdepConstraint(i, childVarIndices, element);
179 break;
180 default:
181 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException, "SMT encoding for type '" << element->type() << "' is not supported.");
182 break;
183 }
184 }
185
186 // Constraint (8) intentionally commented out for testing purposes
187 // addClaimingConstraints();
188
189 // Handle dependencies
190 addMarkovianConstraints();
191
192 // Failsafe BEs may only fail in non-Markovian states (i.e. if they were triggered)
193 std::vector<std::shared_ptr<SmtConstraint>> failsafeNotIConstr;
194 for (uint64_t i = 0; i < dft.nrBasicElements(); ++i) {
195 failsafeNotIConstr.clear();
196 for (auto const &beV : failsafeBeVariables) {
197 failsafeNotIConstr.push_back(std::make_shared<IsNotConstantValue>(beV, i + 1));
198 }
199 // If state i+1 is Markovian (i.e. m_i = true), all failsafeBEVariables are not equal to i+1
200 constraints.push_back(
201 std::make_shared<Implies>(std::make_shared<IsBoolValue>(markovianVariables.at(i), true), std::make_shared<And>(failsafeNotIConstr)));
202 if (i == 0) {
203 constraints.back()->setDescription("Failsafe BEs fail only if they are triggered");
204 }
205 }
206
207 // A failsafe BE only stays failsafe if no trigger has been triggered
208 std::vector<std::shared_ptr<SmtConstraint>> triggerConstraints;
209 for (size_t i = 0; i < dft.nrElements(); ++i) {
210 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(i);
211 if (element->isBasicElement()) {
212 auto be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<double> const>(element);
214 triggerConstraints.clear();
215 for (auto const &dependency : be->ingoingDependencies()) {
216 triggerConstraints.push_back(std::make_shared<IsConstantValue>(timePointVariables.at(dependency->triggerEvent()->id()), notFailed));
217 }
218 if (!triggerConstraints.empty()) {
219 constraints.push_back(std::make_shared<Implies>(std::make_shared<IsConstantValue>(timePointVariables.at(be->id()), notFailed),
220 std::make_shared<And>(triggerConstraints)));
221 constraints.back()->setDescription("Failsafe BE " + be->name() + " stays failsafe if no trigger fails");
222 }
223 }
224 }
225 }
226}
227
228// Constraint Generator Functions
229
230void DFTASFChecker::generateAndConstraint(size_t i, std::vector<uint64_t> childVarIndices,
231 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
232 // Constraint for AND gate (constraint 1)
233 constraints.push_back(std::make_shared<IsMaximum>(timePointVariables.at(i), childVarIndices));
234 constraints.back()->setDescription("AND gate " + element->name());
235}
236
237void DFTASFChecker::generateOrConstraint(size_t i, std::vector<uint64_t> childVarIndices,
238 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
239 // Constraint for OR gate (constraint 2)
240 constraints.push_back(std::make_shared<IsMinimum>(timePointVariables.at(i), childVarIndices));
241 constraints.back()->setDescription("OR gate " + element->name());
242}
243
244void DFTASFChecker::generateVotConstraint(size_t i, std::vector<uint64_t> childVarIndices,
245 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
246 auto vot = std::static_pointer_cast<storm::dft::storage::elements::DFTVot<double> const>(element);
247 // VOTs are implemented via OR over ANDs with all possible combinations
248 std::vector<uint64_t> tmpVars;
249 size_t k = 0;
250 // Generate all permutations of k out of n
251 uint64_t combination = smallestIntWithNBitsSet(static_cast<uint64_t>(vot->threshold()));
252 do {
253 // Construct selected children from combination
254 std::vector<uint64_t> combinationChildren;
255 STORM_LOG_ASSERT(vot->nrChildren() < 64, "Too many children of a VOT Gate.");
256 for (uint8_t j = 0; j < static_cast<uint8_t>(vot->nrChildren()); ++j) {
257 if (combination & (1ul << j)) {
258 combinationChildren.push_back(childVarIndices.at(j));
259 }
260 }
261 // Introduce temporary variable for this AND
262 varNames.push_back("v_" + vot->name() + "_" + std::to_string(k));
263 size_t index = varNames.size() - 1;
264 tmpVars.push_back(index);
265 tmpTimePointVariables.push_back(index);
266 // AND over the selected children
267 constraints.push_back(std::make_shared<IsMaximum>(index, combinationChildren));
268 constraints.back()->setDescription("VOT gate " + element->name() + ": AND no. " + std::to_string(k));
269 // Generate next permutation
270 combination = nextBitPermutation(combination);
271 ++k;
272 } while (combination < (1ul << vot->nrChildren()) && combination != 0);
273
274 // Constraint is OR over all possible combinations
275 constraints.push_back(std::make_shared<IsMinimum>(timePointVariables.at(i), tmpVars));
276 constraints.back()->setDescription("VOT gate " + element->name() + ": OR");
277}
278
279void DFTASFChecker::generatePandConstraint(size_t i, std::vector<uint64_t> childVarIndices,
280 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
281 // Constraint for PAND gate (constraint 3)
282 std::shared_ptr<SmtConstraint> ifC = std::make_shared<Sorted>(childVarIndices);
283 std::shared_ptr<SmtConstraint> thenC = std::make_shared<IsEqual>(timePointVariables.at(i), childVarIndices.back());
284 std::shared_ptr<SmtConstraint> elseC = std::make_shared<IsConstantValue>(timePointVariables.at(i), notFailed);
285 constraints.push_back(std::make_shared<IfThenElse>(ifC, thenC, elseC));
286 constraints.back()->setDescription("PAND gate " + element->name());
287}
288
289void DFTASFChecker::generatePorConstraint(size_t i, std::vector<uint64_t> childVarIndices,
290 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
291 // Constraint for POR gate
292 // First child fails before all others
293 std::vector<std::shared_ptr<SmtConstraint>> firstSmallestC;
294 uint64_t timeFirstChild = childVarIndices.front();
295 for (uint64_t i = 1; i < childVarIndices.size(); ++i) {
296 firstSmallestC.push_back(std::make_shared<IsLess>(timeFirstChild, childVarIndices.at(i)));
297 }
298 std::shared_ptr<SmtConstraint> ifC = std::make_shared<And>(firstSmallestC);
299 std::shared_ptr<SmtConstraint> thenC = std::make_shared<IsEqual>(timePointVariables.at(i), childVarIndices.front());
300 std::shared_ptr<SmtConstraint> elseC = std::make_shared<IsConstantValue>(timePointVariables.at(i), notFailed);
301 constraints.push_back(std::make_shared<IfThenElse>(ifC, thenC, elseC));
302 constraints.back()->setDescription("POR gate " + element->name());
303}
304
305void DFTASFChecker::generateSeqConstraint(std::vector<uint64_t> childVarIndices,
306 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
307 // Constraint for SEQ gate (constraint 4)
308 // As the restriction is not a gate we have to enumerate its children here
309 auto seq = std::static_pointer_cast<storm::dft::storage::elements::DFTRestriction<double> const>(element);
310 for (auto const &child : seq->children()) {
311 childVarIndices.push_back(timePointVariables.at(child->id()));
312 }
313
314 constraints.push_back(std::make_shared<Sorted>(childVarIndices));
315 constraints.back()->setDescription("SEQ gate " + element->name());
316}
317
318void DFTASFChecker::generateSpareConstraint(size_t i, std::vector<uint64_t> childVarIndices,
319 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
320 auto spare = std::static_pointer_cast<storm::dft::storage::elements::DFTSpare<double> const>(element);
321 auto const &children = spare->children();
322 uint64_t firstChild = children.front()->id();
323 uint64_t lastChild = children.back()->id();
324
325 // First child of each spare is claimed in the beginning
326 constraints.push_back(std::make_shared<IsConstantValue>(getClaimVariableIndex(spare->id(), firstChild), 0));
327 constraints.back()->setDescription("SPARE gate " + spare->name() + " claims first child");
328
329 // If last child is claimed before failure, then the spare fails when the last child fails (constraint 5)
330 std::shared_ptr<SmtConstraint> leftC = std::make_shared<IsLess>(getClaimVariableIndex(spare->id(), lastChild), childVarIndices.back());
331 constraints.push_back(std::make_shared<Implies>(leftC, std::make_shared<IsEqual>(timePointVariables.at(i), childVarIndices.back())));
332 constraints.back()->setDescription("Last child & claimed -> SPARE fails");
333
334 // Construct constraint for trying to claim next child
335 STORM_LOG_ASSERT(children.size() >= 2, "Spare has only one child.");
336 for (uint64_t currChild = 0; currChild < children.size() - 1; ++currChild) {
337 uint64_t timeCurrChild = childVarIndices.at(currChild); // Moment when current child fails
338 // If i-th child fails after being claimed, then try to claim next child (constraint 6)
339 std::shared_ptr<SmtConstraint> tryClaimC = generateTryToClaimConstraint(spare, currChild + 1, timeCurrChild);
340 constraints.push_back(
341 std::make_shared<Iff>(std::make_shared<IsLess>(getClaimVariableIndex(spare->id(), children.at(currChild)->id()), timeCurrChild), tryClaimC));
342 constraints.back()->setDescription("Try to claim " + std::to_string(currChild + 2) + "th child");
343 }
344}
345
346std::shared_ptr<SmtConstraint> DFTASFChecker::generateTryToClaimConstraint(std::shared_ptr<storm::dft::storage::elements::DFTSpare<ValueType> const> spare,
347 uint64_t childIndex, uint64_t timepoint) const {
348 auto child = spare->children().at(childIndex);
349 uint64_t timeChild = timePointVariables.at(child->id()); // Moment when the child fails
350 uint64_t claimChild = getClaimVariableIndex(spare->id(), child->id()); // Moment the spare claims the child
351
352 std::vector<std::shared_ptr<SmtConstraint>> noClaimingPossible;
353 // Child cannot be claimed.
354 if (childIndex + 1 < spare->children().size()) {
355 // Consider next child for claiming (second case in constraint 7)
356 noClaimingPossible.push_back(generateTryToClaimConstraint(spare, childIndex + 1, timepoint));
357 } else {
358 // Last child: spare fails at same point as this child (third case in constraint 7)
359 noClaimingPossible.push_back(std::make_shared<IsEqual>(timePointVariables.at(spare->id()), timepoint));
360 }
361 std::shared_ptr<SmtConstraint> elseCaseC = std::make_shared<And>(noClaimingPossible);
362
363 // Check if next child is available (first case in constraint 7)
364 std::vector<std::shared_ptr<SmtConstraint>> claimingPossibleC;
365 // Next child is not yet failed
366 claimingPossibleC.push_back(std::make_shared<IsLess>(timepoint, timeChild));
367 // Child is not yet claimed by a different spare
368 for (auto const &otherSpare : child->parents()) {
369 if (otherSpare->id() == spare->id()) {
370 // not a different spare.
371 continue;
372 }
373 claimingPossibleC.push_back(std::make_shared<IsLess>(timepoint, getClaimVariableIndex(otherSpare->id(), child->id())));
374 }
375
376 // Claim child if available
377 std::shared_ptr<SmtConstraint> firstCaseC =
378 std::make_shared<IfThenElse>(std::make_shared<And>(claimingPossibleC), std::make_shared<IsEqual>(claimChild, timepoint), elseCaseC);
379 return firstCaseC;
380}
381
382void DFTASFChecker::addClaimingConstraints() {
383 // Only one spare can claim a child (constraint 8)
384 // and only not failed children can be claimed (addition to constrain 8)
385 for (size_t i = 0; i < dft.nrElements(); ++i) {
386 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(i);
387 if (element->isSpareGate()) {
388 auto spare = std::static_pointer_cast<storm::dft::storage::elements::DFTSpare<double> const>(element);
389 for (auto const &child : spare->children()) {
390 std::vector<std::shared_ptr<SmtConstraint>> additionalC;
391 uint64_t timeClaiming = getClaimVariableIndex(spare->id(), child->id());
392 std::shared_ptr<SmtConstraint> leftC = std::make_shared<IsLessConstant>(timeClaiming, notFailed);
393 // Child must be operational at time of claiming
394 additionalC.push_back(std::make_shared<IsLess>(timeClaiming, timePointVariables.at(child->id())));
395 // No other spare claims this child
396 for (auto const &parent : child->parents()) {
397 if (parent->isSpareGate() && parent->id() != spare->id()) {
398 // Different spare
399 additionalC.push_back(std::make_shared<IsConstantValue>(getClaimVariableIndex(parent->id(), child->id()), notFailed));
400 }
401 }
402 constraints.push_back(std::make_shared<Implies>(leftC, std::make_shared<And>(additionalC)));
403 constraints.back()->setDescription("Child " + child->name() + " must be operational at time of claiming by spare " + spare->name() +
404 " and can only be claimed by one spare.");
405 }
406 }
407 }
408}
409
410void DFTASFChecker::generatePdepConstraint(size_t i, std::vector<uint64_t> childVarIndices,
411 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element) {
412 auto dependency = std::static_pointer_cast<storm::dft::storage::elements::DFTDependency<double> const>(element);
413 auto const &dependentEvents = dependency->dependentEvents();
414 auto const &trigger = dependency->triggerEvent();
415 std::vector<uint64_t> dependentIndices;
416 for (size_t j = 0; j < dependentEvents.size(); ++j) {
417 dependentIndices.push_back(timePointVariables.at(dependentEvents[j]->id()));
418 }
419
420 constraints.push_back(std::make_shared<IsMaximum>(dependencyVariables.at(i), dependentIndices));
421 constraints.back()->setDescription("Dependency " + element->name() + ": Last element");
422 constraints.push_back(std::make_shared<IsEqual>(timePointVariables.at(i), timePointVariables.at(trigger->id())));
423 constraints.back()->setDescription("Dependency " + element->name() + ": Trigger element");
424}
425
426void DFTASFChecker::addMarkovianConstraints() {
427 uint64_t nrMarkovian = dft.nrBasicElements();
428 std::set<size_t> depElements;
429 // Vector containing (non-)Markovian constraints for each timepoint
430 std::vector<std::vector<std::shared_ptr<SmtConstraint>>> markovianC(nrMarkovian);
431 std::vector<std::vector<std::shared_ptr<SmtConstraint>>> nonMarkovianC(nrMarkovian);
432 std::vector<std::vector<std::shared_ptr<SmtConstraint>>> notColdC(nrMarkovian);
433
434 // All dependent events of a failed trigger have failed as well (constraint 9)
435 for (size_t j = 0; j < dft.nrElements(); ++j) {
436 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(j);
437 if (element->hasOutgoingDependencies()) {
438 for (uint64_t i = 0; i < nrMarkovian; ++i) {
439 std::shared_ptr<SmtConstraint> triggerFailed = std::make_shared<IsLessEqualConstant>(timePointVariables.at(j), i);
440 std::vector<std::shared_ptr<SmtConstraint>> depFailed;
441 for (auto const &dependency : element->outgoingDependencies()) {
442 for (auto const &depElement : dependency->dependentEvents()) {
443 depFailed.push_back(std::make_shared<IsLessEqualConstant>(timePointVariables.at(depElement->id()), i));
444 }
445 }
446 markovianC[i].push_back(std::make_shared<Implies>(triggerFailed, std::make_shared<And>(depFailed)));
447 }
448 }
449 }
450 for (uint64_t i = 0; i < nrMarkovian; ++i) {
451 constraints.push_back(std::make_shared<Iff>(std::make_shared<IsBoolValue>(markovianVariables.at(i), true), std::make_shared<And>(markovianC[i])));
452 constraints.back()->setDescription("Markovian (" + std::to_string(i) + ") iff all dependent events which trigger failed also failed.");
453 }
454
455 // In non-Markovian steps the next failed element is a dependent BE (constraint 10) + additions to specification in paper
456 for (size_t j = 0; j < dft.nrElements(); ++j) {
457 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(j);
458 if (element->isBasicElement()) {
459 auto be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<double> const>(element);
460
461 if (be->hasIngoingDependencies()) {
462 depElements.emplace(j);
463 for (uint64_t i = 0; i < nrMarkovian - 1; ++i) {
464 std::shared_ptr<SmtConstraint> nextFailure = std::make_shared<IsConstantValue>(timePointVariables.at(j), i + 1);
465 std::vector<std::shared_ptr<SmtConstraint>> triggerFailed;
466 for (auto const &dependency : be->ingoingDependencies()) {
467 triggerFailed.push_back(std::make_shared<IsLessEqualConstant>(timePointVariables.at(dependency->triggerEvent()->id()), i));
468 }
469 nonMarkovianC[i].push_back(std::make_shared<Implies>(nextFailure, std::make_shared<Or>(triggerFailed)));
470 }
471 }
472 }
473 }
474 for (uint64_t i = 0; i < nrMarkovian; ++i) {
475 std::vector<std::shared_ptr<SmtConstraint>> dependentConstr;
476 for (auto dependentEvent : depElements) {
477 std::shared_ptr<SmtConstraint> nextFailure = std::make_shared<IsConstantValue>(timePointVariables.at(dependentEvent), i + 1);
478 dependentConstr.push_back(nextFailure);
479 }
480 // Add Constraint that any DEPENDENT event has to fail next
481 nonMarkovianC[i].push_back(std::make_shared<Or>(dependentConstr));
482 constraints.push_back(
483 std::make_shared<Implies>(std::make_shared<IsBoolValue>(markovianVariables.at(i), false), std::make_shared<And>(nonMarkovianC[i])));
484 constraints.back()->setDescription("Non-Markovian (" + std::to_string(i) + ") -> next failure is dependent BE.");
485 }
486
487 // In Markovian steps the failure rate is positive (constraint 11)
488 for (size_t j = 0; j < dft.nrElements(); ++j) {
489 std::shared_ptr<storm::dft::storage::elements::DFTElement<ValueType> const> element = dft.getElement(j);
490 if (element->isBasicElement()) {
491 auto be = std::static_pointer_cast<storm::dft::storage::elements::DFTBE<double> const>(element);
492 for (uint64_t i = 0; i < nrMarkovian; ++i) {
493 std::shared_ptr<SmtConstraint> nextFailure = std::make_shared<IsConstantValue>(timePointVariables.at(j), i + 1);
494 // BE is not cold
495 // TODO: implement use of activation variables here
496 notColdC[i].push_back(std::make_shared<Implies>(nextFailure, std::make_shared<IsTrue>(be->canFail())));
497 }
498 }
499 }
500 for (uint64_t i = 0; i < nrMarkovian; ++i) {
501 constraints.push_back(std::make_shared<Implies>(std::make_shared<IsBoolValue>(markovianVariables.at(i), true), std::make_shared<And>(notColdC[i])));
502 constraints.back()->setDescription("Markovian (" + std::to_string(i) + ") -> positive failure rate.");
503 }
504}
505
506void DFTASFChecker::toFile(std::string const &filename) {
507 std::ofstream stream;
508 storm::io::openFile(filename, stream);
509 stream << "; time point variables\n";
510 for (auto const &timeVarEntry : timePointVariables) {
511 stream << "(declare-fun " << varNames[timeVarEntry.second] << "() Int)\n";
512 }
513 stream << "; claim variables\n";
514 for (auto const &claimVarEntry : claimVariables) {
515 stream << "(declare-fun " << varNames[claimVarEntry.second] << "() Int)\n";
516 }
517 stream << "; Markovian variables\n";
518 for (auto const &markovianVarEntry : markovianVariables) {
519 stream << "(declare-fun " << varNames[markovianVarEntry.second] << "() Bool)\n";
520 }
521 stream << "; Dependency variables\n";
522 for (auto const &depVarEntry : dependencyVariables) {
523 stream << "(declare-fun " << varNames[depVarEntry.second] << "() Int)\n";
524 }
525 if (!tmpTimePointVariables.empty()) {
526 stream << "; Temporary variables\n";
527 for (auto const &tmpVar : tmpTimePointVariables) {
528 stream << "(declare-fun " << varNames[tmpVar] << "() Int)\n";
529 }
530 }
531 for (auto const &constraint : constraints) {
532 if (!constraint->description().empty()) {
533 stream << "; " << constraint->description() << '\n';
534 }
535 stream << "(assert " << constraint->toSmtlib2(varNames) << ")\n";
536 }
537 stream << "(check-sat)\n";
538 storm::io::closeFile(stream);
539}
540
542 // First convert the DFT
543 convert();
544
545 std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager());
546 solver = storm::utility::solver::getSmtSolver(*manager);
547 // Add variables to manager
548 for (auto const &timeVarEntry : timePointVariables) {
549 manager->declareIntegerVariable(varNames[timeVarEntry.second]);
550 }
551 for (auto const &claimVarEntry : claimVariables) {
552 manager->declareIntegerVariable(varNames[claimVarEntry.second]);
553 }
554 for (auto const &markovianVarEntry : markovianVariables) {
555 manager->declareBooleanVariable(varNames[markovianVarEntry.second]);
556 }
557 if (!tmpTimePointVariables.empty()) {
558 for (auto const &tmpVar : tmpTimePointVariables) {
559 manager->declareIntegerVariable(varNames[tmpVar]);
560 }
561 }
562 for (auto const &depVarEntry : dependencyVariables) {
563 manager->declareIntegerVariable(varNames[depVarEntry.second]);
564 }
565 // Add constraints to solver
566 for (auto const &constraint : constraints) {
567 solver->add(constraint->toExpression(varNames, manager));
568 }
569}
570
572 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, call toSolver() before checking queries.");
573
574 // Set backtracking marker to check several properties without reconstructing DFT encoding
575 solver->push();
576 // Constraint that toplevel element can fail with less or equal 'bound' failures
577 std::shared_ptr<SmtConstraint> tleFailedConstr = std::make_shared<IsConstantValue>(timePointVariables.at(dft.getTopLevelIndex()), bound);
578 std::shared_ptr<storm::expressions::ExpressionManager> manager = solver->getManager().getSharedPointer();
579 solver->add(tleFailedConstr->toExpression(varNames, manager));
580 storm::solver::SmtSolver::CheckResult res = solver->check();
581 solver->pop();
582 return res;
583}
584
586 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, call toSolver() before checking queries.");
587
588 // Set backtracking marker to check several properties without reconstructing DFT encoding
589 solver->push();
590 // Constraint that toplevel element can fail with less or equal 'bound' failures
591 std::shared_ptr<SmtConstraint> tleNeverFailedConstr = std::make_shared<IsLessEqualConstant>(timePointVariables.at(dft.getTopLevelIndex()), bound);
592 std::shared_ptr<storm::expressions::ExpressionManager> manager = solver->getManager().getSharedPointer();
593 solver->add(tleNeverFailedConstr->toExpression(varNames, manager));
594 storm::solver::SmtSolver::CheckResult res = solver->check();
595 solver->pop();
596 return res;
597}
598
599void DFTASFChecker::setSolverTimeout(uint_fast64_t milliseconds) {
600 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, timeout cannot be set.");
601 solver->setTimeout(milliseconds);
602}
603
605 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, timeout cannot be unset.");
606 solver->unsetTimeout();
607}
608
610 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, call toSolver() before checking queries.");
611 return checkTleFailsWithEq(notFailed);
612}
613
615 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, call toSolver() before checking queries.");
616 std::vector<uint64_t> markovianIndices;
617 checkbound = std::min<int>(checkbound, markovianVariables.size());
618 // Get Markovian variable indices up until given timepoint
619 for (uint64_t i = 0; i < checkbound; ++i) {
620 markovianIndices.push_back(markovianVariables.at(i));
621 }
622 // Set backtracking marker to check several properties without reconstructing DFT encoding
623 solver->push();
624 // Constraint that TLE fails before or during given timepoint
625 std::shared_ptr<SmtConstraint> tleFailedConstr = std::make_shared<IsLessEqualConstant>(timePointVariables.at(dft.getTopLevelIndex()), checkbound);
626 std::shared_ptr<storm::expressions::ExpressionManager> manager = solver->getManager().getSharedPointer();
627 solver->add(tleFailedConstr->toExpression(varNames, manager));
628 // Constraint that a given number of non-Markovian states are visited
629 std::shared_ptr<SmtConstraint> nonMarkovianConstr = std::make_shared<FalseCountIsEqualConstant>(markovianIndices, nrNonMarkovian);
630 solver->add(nonMarkovianConstr->toExpression(varNames, manager));
631 storm::solver::SmtSolver::CheckResult res = solver->check();
632 solver->pop();
633 return res;
634}
635
637 STORM_LOG_ASSERT(solver, "SMT Solver was not initialized, call toSolver() before checking queries.");
638 std::vector<uint64_t> markovianIndices;
639 timepoint = std::min<int>(timepoint, markovianVariables.size());
640 // Get Markovian variable indices up until given timepoint
641 for (uint64_t i = 0; i < timepoint; ++i) {
642 markovianIndices.push_back(markovianVariables.at(i));
643 }
644 // Set backtracking marker to check several properties without reconstructing DFT encoding
645 solver->push();
646 // Constraint that TLE fails before or during given timepoint
647 std::shared_ptr<SmtConstraint> tleFailedConstr = std::make_shared<IsConstantValue>(timePointVariables.at(dft.getTopLevelIndex()), timepoint);
648 std::shared_ptr<storm::expressions::ExpressionManager> manager = solver->getManager().getSharedPointer();
649 solver->add(tleFailedConstr->toExpression(varNames, manager));
650 // Constraint that a given number of non-Markovian states are visited
651 std::shared_ptr<SmtConstraint> nonMarkovianConstr = std::make_shared<FalseCountIsEqualConstant>(markovianIndices, nrNonMarkovian);
652 solver->add(nonMarkovianConstr->toExpression(varNames, manager));
653 storm::solver::SmtSolver::CheckResult res = solver->check();
654 solver->pop();
655 return res;
656}
657
658storm::solver::SmtSolver::CheckResult DFTASFChecker::checkDependencyConflict(uint64_t dep1Index, uint64_t dep2Index, uint64_t timeout) {
659 std::vector<std::shared_ptr<SmtConstraint>> andConstr;
660 std::vector<std::shared_ptr<SmtConstraint>> orConstr;
661 STORM_LOG_DEBUG("Check " << dft.getElement(dep1Index)->name() << " and " << dft.getElement(dep2Index)->name());
662 andConstr.clear();
663 // AND FDEP1 is triggered before FDEP2 is resolved
664 andConstr.push_back(std::make_shared<IsLessEqual>(timePointVariables.at(dep2Index), timePointVariables.at(dep1Index)));
665 andConstr.push_back(std::make_shared<IsLess>(timePointVariables.at(dep1Index), dependencyVariables.at(dep2Index)));
666 std::shared_ptr<SmtConstraint> betweenConstr1 = std::make_shared<And>(andConstr);
667
668 andConstr.clear();
669 // AND FDEP2 is triggered before FDEP1 is resolved
670 andConstr.push_back(std::make_shared<IsLessEqual>(timePointVariables.at(dep1Index), timePointVariables.at(dep2Index)));
671 andConstr.push_back(std::make_shared<IsLess>(timePointVariables.at(dep2Index), dependencyVariables.at(dep1Index)));
672 std::shared_ptr<SmtConstraint> betweenConstr2 = std::make_shared<And>(andConstr);
673
674 orConstr.clear();
675 // Either one of the above constraints holds
676 orConstr.push_back(betweenConstr1);
677 orConstr.push_back(betweenConstr2);
678
679 // Both FDEPs were triggered before dependent elements have failed
680 andConstr.clear();
681 andConstr.push_back(std::make_shared<IsLess>(timePointVariables.at(dep1Index), dependencyVariables.at(dep1Index)));
682 andConstr.push_back(std::make_shared<IsLess>(timePointVariables.at(dep2Index), dependencyVariables.at(dep2Index)));
683 andConstr.push_back(std::make_shared<Or>(orConstr));
684
685 std::shared_ptr<SmtConstraint> checkConstr = std::make_shared<And>(andConstr);
686
687 std::shared_ptr<storm::expressions::ExpressionManager> manager = solver->getManager().getSharedPointer();
688 solver->push();
689 solver->add(checkConstr->toExpression(varNames, manager));
690 setSolverTimeout(timeout * 1000);
691 storm::solver::SmtSolver::CheckResult res = solver->check();
693 solver->pop();
694 return res;
695}
696
697} // namespace modelchecker
698} // namespace storm::dft
uint64_t nextBitPermutation(uint64_t v)
The next bit permutation in a lexicographical sense.
uint64_t smallestIntWithNBitsSet(uint64_t n)
storm::solver::SmtSolver::CheckResult checkTleFailsWithLeq(uint64_t bound)
Check if there exists a sequence of BE failures of at least given length such that the TLE of the DFT...
void setSolverTimeout(uint_fast64_t milliseconds)
Set the timeout of the solver.
storm::solver::SmtSolver::CheckResult checkFailsAtTimepointWithEqNonMarkovianState(uint64_t timepoint, uint64_t nrNonMarkovian)
Helper function that checks if the DFT can fail at a timepoint while visiting a given number of Marko...
void convert()
Generate general variables and constraints for the DFT and store them in the corresponding maps and v...
DFTASFChecker(storm::dft::storage::DFT< ValueType > const &)
storm::solver::SmtSolver::CheckResult checkFailsLeqWithEqNonMarkovianState(uint64_t checkbound, uint64_t nrNonMarkovian)
Helper function to check if the TLE fails before or at a given timepoint while visiting exactly a giv...
void toSolver()
Generates a new solver instance and prepares it for SMT checking of the DFT.
void unsetSolverTimeout()
Unset the timeout for the solver.
storm::solver::SmtSolver::CheckResult checkTleNeverFailed()
Check if the TLE of the DFT never fails.
storm::solver::SmtSolver::CheckResult checkDependencyConflict(uint64_t dep1Index, uint64_t dep2Index, uint64_t timeout=10)
Check if two given dependencies are conflicting in their resolution, i.e.
storm::solver::SmtSolver::CheckResult checkTleFailsWithEq(uint64_t bound)
Check if there exists a sequence of BE failures of exactly given length such that the TLE of the DFT ...
Represents a Dynamic Fault Tree.
Definition DFT.h:50
Abstract base class for DFT elements.
Definition DFTElement.h:38
This class is responsible for managing a set of typed variables and all expressions using these varia...
CheckResult
possible check results
Definition SmtSolver.h:24
#define STORM_LOG_WARN(message)
Definition logging.h:35
#define STORM_LOG_DEBUG(message)
Definition logging.h:28
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:39
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
std::unique_ptr< storm::solver::SmtSolver > getSmtSolver(storm::expressions::ExpressionManager &manager)
Creates a new SMT solver instance.
Definition solver.cpp:215