Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
PartitionRefiner.cpp
Go to the documentation of this file.
2
4
6
9
10namespace storm {
11namespace dd {
12namespace bisimulation {
13
14template<storm::dd::DdType DdType, typename ValueType>
16 Partition<DdType, ValueType> const& initialStatePartition)
17 : status(Status::Initialized),
18 refinements(0),
19 statePartition(initialStatePartition),
20 signatureComputer(model),
21 signatureRefiner(model.getManager(), statePartition.getBlockVariable(), model.getRowAndNondeterminismVariables(), model.getColumnVariables(),
22 !model.isNondeterministicModel(), model.getNondeterminismVariables()),
23 totalSignatureTime(0),
24 totalRefinementTime(0) {
25 // Intentionally left empty.
26}
27
28template<storm::dd::DdType DdType, typename ValueType>
30 Partition<DdType, ValueType> newStatePartition = this->internalRefine(signatureComputer, signatureRefiner, statePartition, statePartition, mode);
31 if (statePartition.getNumberOfBlocks() == newStatePartition.getNumberOfBlocks()) {
32 this->status = Status::FixedPoint;
33 return false;
34 } else {
35 this->statePartition = newStatePartition;
36 return true;
37 }
38}
39
40template<storm::dd::DdType DdType, typename ValueType>
43 Partition<DdType, ValueType> const& oldPartition,
44 Partition<DdType, ValueType> const& targetPartition,
45 SignatureMode const& mode) {
46 auto start = std::chrono::high_resolution_clock::now();
47
48 if (this->status != Status::FixedPoint) {
49 this->status = Status::InComputation;
50
51 signatureComputer.setSignatureMode(mode);
52
53 std::chrono::milliseconds::rep signatureTime = 0;
54 std::chrono::milliseconds::rep refinementTime = 0;
55
56 bool refined = false;
57 uint64_t index = 0;
59 auto signatureIterator = signatureComputer.compute(targetPartition);
60 while (signatureIterator.hasNext() && !refined) {
61 auto signatureStart = std::chrono::high_resolution_clock::now();
62 auto signature = signatureIterator.next();
63 auto signatureEnd = std::chrono::high_resolution_clock::now();
64 totalSignatureTime += (signatureEnd - signatureStart);
65 STORM_LOG_TRACE("Signature " << refinements << "[" << index << "] DD has " << signature.getSignatureAdd().getNodeCount() << " nodes.");
66
67 auto refinementStart = std::chrono::high_resolution_clock::now();
68 newPartition = signatureRefiner.refine(oldPartition, signature);
69 auto refinementEnd = std::chrono::high_resolution_clock::now();
70 totalRefinementTime += (refinementEnd - refinementStart);
71
72 signatureTime += std::chrono::duration_cast<std::chrono::milliseconds>(signatureEnd - signatureStart).count();
73 refinementTime = std::chrono::duration_cast<std::chrono::milliseconds>(refinementEnd - refinementStart).count();
74
75 // Potentially exit early in case we have refined the partition already.
76 if (newPartition.getNumberOfBlocks() > oldPartition.getNumberOfBlocks()) {
77 refined = true;
78 }
79 }
80
81 auto totalTimeInRefinement = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start).count();
82 STORM_LOG_INFO("Refinement " << refinements << " produced " << newPartition.getNumberOfBlocks() << " blocks and was completed in "
83 << totalTimeInRefinement << "ms (signature: " << signatureTime << "ms, refinement: " << refinementTime << "ms).");
84 ++refinements;
85 return newPartition;
86 } else {
87 return oldPartition;
88 }
89}
90
91template<storm::dd::DdType DdType, typename ValueType>
94 Partition<DdType, ValueType> const& oldPartition) {
95 STORM_LOG_TRACE("Signature " << refinements << " DD has " << signature.getSignatureAdd().getNodeCount() << " nodes.");
96 auto refinementStart = std::chrono::high_resolution_clock::now();
97 auto newPartition = signatureRefiner.refine(oldPartition, signature);
98 auto refinementEnd = std::chrono::high_resolution_clock::now();
99 totalRefinementTime += (refinementEnd - refinementStart);
100
101 ++refinements;
102 return newPartition;
103}
104
105template<storm::dd::DdType DdType, typename ValueType>
107 STORM_LOG_THROW(!rewardModel.hasTransitionRewards(), storm::exceptions::NotSupportedException,
108 "Symbolic bisimulation currently does not support transition rewards.");
109 STORM_LOG_TRACE("Refining with respect to reward model.");
110 bool result = false;
111 if (rewardModel.hasStateRewards()) {
112 result |= refineWrtStateRewards(rewardModel.getStateRewardVector());
113 }
114 if (rewardModel.hasStateActionRewards()) {
115 result |= refineWrtStateActionRewards(rewardModel.getStateActionRewardVector());
116 }
117 return result;
118}
119
120template<storm::dd::DdType DdType, typename ValueType>
122 STORM_LOG_TRACE("Refining with respect to state rewards.");
123 Partition<DdType, ValueType> newPartition = signatureRefiner.refine(statePartition, Signature<DdType, ValueType>(stateRewards));
124 if (newPartition == statePartition) {
125 return false;
126 } else {
127 this->statePartition = newPartition;
128 return true;
129 }
130}
131
132template<storm::dd::DdType DdType, typename ValueType>
134 STORM_LOG_TRACE("Refining with respect to state-action rewards.");
135 // By default, we treat state-action rewards just like state-rewards, which works for DTMCs and CTMCs.
136 return refineWrtStateRewards(stateActionRewards);
137}
138
139template<storm::dd::DdType DdType, typename ValueType>
143
144template<storm::dd::DdType DdType, typename ValueType>
146 return signatureComputer.getFullSignature(statePartition);
147}
148
149template<storm::dd::DdType DdType, typename ValueType>
153
154template<storm::dd::DdType DdType, typename ValueType>
155std::chrono::high_resolution_clock::duration PartitionRefiner<DdType, ValueType>::getTotalSignatureTime() const {
156 return totalSignatureTime;
157}
158
159template<storm::dd::DdType DdType, typename ValueType>
160std::chrono::high_resolution_clock::duration PartitionRefiner<DdType, ValueType>::getTotalRefinementTime() const {
161 return totalRefinementTime;
162}
163
165
169
170} // namespace bisimulation
171} // namespace dd
172} // namespace storm
virtual uint_fast64_t getNodeCount() const override
Retrieves the number of nodes necessary to represent the DD.
Definition Add.cpp:465
virtual bool refineWrtStateActionRewards(storm::dd::Add< DdType, ValueType > const &stateActionRewards)
std::chrono::high_resolution_clock::duration getTotalRefinementTime() const
virtual bool refineWrtStateRewards(storm::dd::Add< DdType, ValueType > const &stateRewards)
Signature< DdType, ValueType > getFullSignature() const
Retrieves the full signature of all states wrt.
Partition< DdType, ValueType > const & getStatePartition() const
Retrieves the current state partition in the refinement process.
virtual bool refine(SignatureMode const &mode=SignatureMode::Eager)
Refines the partition.
Status getStatus() const
Retrieves the status of the refinement process.
bool refineWrtRewardModel(storm::models::symbolic::StandardRewardModel< DdType, ValueType > const &rewardModel)
Refines the partition wrt.
PartitionRefiner(storm::models::symbolic::Model< DdType, ValueType > const &model, Partition< DdType, ValueType > const &initialStatePartition)
Partition< DdType, ValueType > internalRefine(SignatureComputer< DdType, ValueType > &stateSignatureComputer, SignatureRefiner< DdType, ValueType > &signatureRefiner, Partition< DdType, ValueType > const &oldPartition, Partition< DdType, ValueType > const &targetPartition, SignatureMode const &mode=SignatureMode::Eager)
std::chrono::high_resolution_clock::duration getTotalSignatureTime() const
SignatureIterator< DdType, ValueType > compute(Partition< DdType, ValueType > const &partition)
void setSignatureMode(SignatureMode const &newMode)
storm::dd::Add< DdType, ValueType > const & getSignatureAdd() const
Definition Signature.cpp:13
Partition< DdType, ValueType > refine(Partition< DdType, ValueType > const &oldPartition, Signature< DdType, ValueType > const &signature)
Base class for all symbolic models.
Definition Model.h:46
storm::dd::Add< Type, ValueType > const & getStateActionRewardVector() const
Retrieves the state-action rewards of the reward model.
bool hasStateRewards() const
Retrieves whether the reward model has state rewards.
storm::dd::Add< Type, ValueType > const & getStateRewardVector() const
Retrieves the state rewards of the reward model.
bool hasStateActionRewards() const
Retrieves whether the reward model has state-action rewards.
bool hasTransitionRewards() const
Retrieves whether the reward model has transition rewards.
#define STORM_LOG_INFO(message)
Definition logging.h:29
#define STORM_LOG_TRACE(message)
Definition logging.h:17
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18