Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
IterativePolicySearch.h
Go to the documentation of this file.
1#pragma once
2
3#include <sstream>
4#include <vector>
5
13
14namespace storm {
15namespace pomdp {
16
19 if (in == "int") {
21 } else if (in == "real") {
23 } else {
24 STORM_LOG_ASSERT(in == "bool", "Expected 'bool' path variable type.");
26 }
27}
28
30 public:
31 void setExportSATCalls(std::string const& path) {
32 exportSATcalls = path;
33 }
34
35 std::string const& getExportSATCallsPath() const {
36 return exportSATcalls;
37 }
38
39 bool isExportSATSet() const {
40 return exportSATcalls != "";
41 }
42
43 void setDebugLevel(uint64_t level = 1) {
44 debugLevel = level;
45 }
46
47 bool computeInfoOutput() const {
48 return debugLevel > 0;
49 }
50
51 bool computeDebugOutput() const {
52 return debugLevel > 1;
53 }
54
55 bool computeTraceOutput() const {
56 return debugLevel > 2;
57 }
58
60 bool forceLookahead = false;
61 bool validateEveryStep = false;
62 bool validateResult = false;
65 uint64_t extensionCallTimeout = 0u;
66 uint64_t localIterationMaximum = 600;
67
68 private:
69 std::string exportSATcalls = "";
70 uint64_t debugLevel = 0;
71};
72
74 std::vector<storm::storage::BitVector> actions;
75 std::vector<uint64_t> schedulerRef;
77
78 void reset(uint64_t nrObservations, uint64_t nrActions) {
79 actions = std::vector<storm::storage::BitVector>(nrObservations, storm::storage::BitVector(nrActions));
80 schedulerRef = std::vector<uint64_t>(nrObservations, 0);
81 switchObservations.clear();
82 }
83
84 bool empty() const {
85 return actions.empty();
86 }
87
88 void printForObservations(storm::storage::BitVector const& observations, storm::storage::BitVector const& observationsAfterSwitch) const {
89 for (uint64_t obs = 0; obs < observations.size(); ++obs) {
90 if (observations.get(obs) || observationsAfterSwitch.get(obs)) {
91 STORM_LOG_INFO("For observation: " << obs);
92 }
93 if (observations.get(obs)) {
94 std::stringstream ss;
95 ss << "actions:";
96 for (auto act : actions[obs]) {
97 ss << " " << act;
98 }
99 if (switchObservations.get(obs)) {
100 ss << " and switch.";
101 }
102 STORM_LOG_INFO(ss.str());
103 }
104 if (observationsAfterSwitch.get(obs)) {
105 STORM_LOG_INFO("scheduler ref: " << schedulerRef[obs]);
106 }
107 }
108 }
109};
110
111template<typename ValueType>
113 // Implements an extension to the Chatterjee, Chmelik, Davies (AAAI-16) paper.
114
115 public:
117 public:
118 Statistics() = default;
119 void print() const;
120
128
130
132 outerIterations++;
133 }
134
136 satCalls++;
137 }
138
139 uint64_t getChecks() {
140 return satCalls;
141 }
142
143 uint64_t getIterations() {
144 return outerIterations;
145 }
146
148 return graphBasedAnalysisWinOb;
149 }
150
152 graphBasedAnalysisWinOb++;
153 }
154
155 private:
156 uint64_t satCalls = 0;
157 uint64_t outerIterations = 0;
158 uint64_t graphBasedAnalysisWinOb = 0;
159 };
160
162 storm::storage::BitVector const& surelyReachSinkStates, std::shared_ptr<storm::utility::solver::SmtSolverFactory>& smtSolverFactory,
163 MemlessSearchOptions const& options);
164
165 bool analyzeForInitialStates(uint64_t k) {
166 stats.totalTimer.start();
167 STORM_LOG_TRACE("Bad states: " << surelyReachSinkStates);
168 STORM_LOG_TRACE("Target states: " << targetStates);
169 STORM_LOG_TRACE("Questionmark states: " << (~surelyReachSinkStates & ~targetStates));
170 bool result = analyze(k, ~surelyReachSinkStates & ~targetStates, pomdp.getInitialStates());
171 stats.totalTimer.stop();
172 return result;
173 }
174
175 void computeWinningRegion(uint64_t k) {
176 stats.totalTimer.start();
177 analyze(k, ~surelyReachSinkStates & ~targetStates);
178 stats.totalTimer.stop();
179 }
180
182 return winningRegion;
183 }
184
185 uint64_t getOffsetFromObservation(uint64_t state, uint64_t observation) const;
186
187 bool analyze(uint64_t k, storm::storage::BitVector const& oneOfTheseStates,
188 storm::storage::BitVector const& allOfTheseStates = storm::storage::BitVector());
189
190 Statistics const& getStatistics() const;
191 void finalizeStatistics();
192
193 private:
194 void reset() {
195 STORM_LOG_INFO("Reset solver to restart with current winning region");
196 schedulerForObs.clear();
197 finalSchedulers.clear();
198 smtSolver->reset();
199 }
200 void printScheduler(std::vector<InternalObservationScheduler> const&);
201 void coveredStatesToStream(std::ostream& os, storm::storage::BitVector const& remaining) const;
202
203 bool initialize(uint64_t k);
204
205 bool smtCheck(uint64_t iteration, storm::expressions::ExpressionSet const& assumptions = {});
206
207 std::unique_ptr<storm::solver::SmtSolver> smtSolver;
209 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
210 uint64_t maxK = std::numeric_limits<uint64_t>::max();
211
212 storm::storage::BitVector surelyReachSinkStates;
213 storm::storage::BitVector targetStates;
214 std::vector<std::vector<uint64_t>> statesPerObservation;
215
216 std::vector<storm::expressions::Variable> schedulerVariables;
217 std::vector<storm::expressions::Expression> schedulerVariableExpressions;
218 std::vector<std::vector<storm::expressions::Expression>> actionSelectionVarExpressions; // A_{z,a}
219 std::vector<std::vector<storm::expressions::Variable>> actionSelectionVars; // A_{z,a}
220
221 std::vector<storm::expressions::Variable> reachVars;
222 std::vector<storm::expressions::Expression> reachVarExpressions;
223 std::vector<std::vector<storm::expressions::Expression>> reachVarExpressionsPerObservation;
224
225 std::vector<storm::expressions::Variable> observationUpdatedVariables;
226 std::vector<storm::expressions::Expression> observationUpdatedExpressions;
227
228 std::vector<storm::expressions::Variable> switchVars;
229 std::vector<storm::expressions::Expression> switchVarExpressions;
230 std::vector<storm::expressions::Variable> followVars;
231 std::vector<storm::expressions::Expression> followVarExpressions;
232 std::vector<storm::expressions::Variable> continuationVars;
233 std::vector<storm::expressions::Expression> continuationVarExpressions;
234 std::vector<std::vector<storm::expressions::Variable>> pathVars;
235 std::vector<std::vector<storm::expressions::Expression>> pathVarExpressions;
236
237 std::vector<InternalObservationScheduler> finalSchedulers;
238 std::vector<uint64_t> schedulerForObs;
239 WinningRegion winningRegion;
240
241 MemlessSearchOptions options;
242 Statistics stats;
243
244 std::shared_ptr<storm::utility::solver::SmtSolverFactory>& smtSolverFactory;
245 std::shared_ptr<WinningRegionQueryInterface<ValueType>> validator;
246
247 mutable bool useFindOffset = false;
248};
249} // namespace pomdp
250} // namespace storm
This class represents a partially observable Markov decision process.
Definition Pomdp.h:13
uint64_t getOffsetFromObservation(uint64_t state, uint64_t observation) const
IterativePolicySearch(storm::Environment const &env, storm::models::sparse::Pomdp< ValueType > const &pomdp, storm::storage::BitVector const &targetStates, storm::storage::BitVector const &surelyReachSinkStates, std::shared_ptr< storm::utility::solver::SmtSolverFactory > &smtSolverFactory, MemlessSearchOptions const &options)
WinningRegion const & getLastWinningRegion() const
bool analyze(uint64_t k, storm::storage::BitVector const &oneOfTheseStates, storm::storage::BitVector const &allOfTheseStates=storm::storage::BitVector())
std::string const & getExportSATCallsPath() const
void setExportSATCalls(std::string const &path)
MemlessSearchPathVariables pathVariableType
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
size_t size() const
Retrieves the number of bits this bit vector can store.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
A class that provides convenience operations to display run times.
Definition Stopwatch.h:13
#define STORM_LOG_INFO(message)
Definition logging.h:34
#define STORM_LOG_TRACE(message)
Definition logging.h:22
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
std::set< Expression, ExpressionComparator > ExpressionSet
Definition Expression.h:515
MemlessSearchPathVariables pathVariableTypeFromString(std::string const &in)
std::vector< storm::storage::BitVector > actions
void printForObservations(storm::storage::BitVector const &observations, storm::storage::BitVector const &observationsAfterSwitch) const
void reset(uint64_t nrObservations, uint64_t nrActions)