25template<
typename SparseModelType,
typename ConstantType>
27 : model(model), options(options) {}
29template<
typename SparseModelType,
typename ConstantType>
31 storm::Environment const& env, std::shared_ptr<storm::pars::FeasibilitySynthesisTask const>
const& task) {
33 STORM_LOG_THROW(options.trustRegionInitial > 1.0, storm::exceptions::NotSupportedException,
"ScpOptions::trustRegionInitial must be > 1.");
34 STORM_LOG_THROW(options.trustRegionFactor > 1.0, storm::exceptions::NotSupportedException,
"ScpOptions::trustRegionFactor must be > 1.");
35 STORM_LOG_THROW(options.trustRegionMax > 1.0, storm::exceptions::NotSupportedException,
"ScpOptions::trustRegionMax must be > 1.");
36 STORM_LOG_THROW(options.trustRegionMinExcess >= 0.0, storm::exceptions::NotSupportedException,
"ScpOptions::trustRegionMinExcess must be >= 0.");
37 STORM_LOG_THROW(options.maxIterations >= 1, storm::exceptions::NotSupportedException,
"ScpOptions::maxIterations must be >= 1.");
39 STORM_LOG_THROW(task->getFormula().isProbabilityOperatorFormula() || task->getFormula().isRewardOperatorFormula(), storm::exceptions::NotSupportedException,
40 "SCP currently only supports probability- and reward operator formulas.");
41 bool const isReward = task->getFormula().isRewardOperatorFormula();
42 STORM_LOG_THROW(task->getFormula().asOperatorFormula().getSubformula().isEventuallyFormula(), storm::exceptions::NotSupportedException,
43 "SCP currently only supports unbounded reachability (F) properties.");
44 STORM_LOG_THROW(task->isBoundSet(), storm::exceptions::NotSupportedException,
"SCP requires an explicitly given bound.");
52 (direction ==
ThresholdDirection::AtLeast) ? storm::solver::OptimizationDirection::Minimize : storm::solver::OptimizationDirection::Maximize;
55 auto const& targetSubformula = task->getFormula().asOperatorFormula().getSubformula().asEventuallyFormula().getSubformula();
59 propositionalChecker.
check(targetCheckTask)->template asExplicitQualitativeCheckResult<ParametricType>().getTruthValuesVector();
67 if constexpr (std::is_same_v<SparseModelType, storm::models::sparse::Mdp<ParametricType>>) {
69 zeroStates = targetStates;
73 model.getBackwardTransitions(), allStates, targetStates)
75 model.getBackwardTransitions(), allStates, targetStates);
80 excludedRows = ~model.getTransitionMatrix().getRowFilter(maybeStates, ~infiniteStates);
84 zeroStates = std::move(probs.first);
85 oneStates = std::move(probs.second);
89 static_assert(std::is_same_v<SparseModelType, storm::models::sparse::Dtmc<ParametricType>>,
90 "SparseScpInstantiationSearcher only supports Mdp and Dtmc models.");
92 zeroStates = targetStates;
99 zeroStates = std::move(probs.first);
100 oneStates = std::move(probs.second);
107 auto const& rewardFormula = task->getFormula().asRewardOperatorFormula();
108 if (rewardFormula.hasRewardModelName()) {
109 STORM_LOG_THROW(model.hasRewardModel(rewardFormula.getRewardModelName()), storm::exceptions::NotSupportedException,
110 "The model has no reward model named '" << rewardFormula.getRewardModelName() <<
"'.");
111 rewardModel = &model.getRewardModel(rewardFormula.getRewardModelName());
113 STORM_LOG_THROW(model.hasUniqueRewardModel(), storm::exceptions::NotSupportedException,
114 "The reward formula does not name a reward model, and the model does not have a unique reward model either.");
115 rewardModel = &model.getUniqueRewardModel();
123 if (task->isRegionSet()) {
124 region = task->getRegion();
127 "The given region does not cover parameter '" << var <<
"', which occurs in the model.");
130 Valuation lower, upper;
138 std::map<VariableType, std::pair<double, double>> parameterBounds;
145 STORM_LOG_THROW(model.getInitialStates().getNumberOfSetBits() == 1, storm::exceptions::NotSupportedException,
146 "SCP requires a model with a unique initial state.");
147 uint64_t initialState = model.getInitialStates().getNextSetIndex(0);
149 if (zeroStates.
get(initialState) || oneStates.
get(initialState) || infiniteStates.
get(initialState)) {
158 std::vector<uint64_t> rowGroupIndices(model.getTransitionMatrix().getRowGroupIndices().begin(), model.getTransitionMatrix().getRowGroupIndices().end());
160 ScpLpEncoder encoder(decomposition, rowGroupIndices, zeroStates, oneStates, infiniteStates, excludedRows, initialState, parameterBounds, threshold,
161 direction, propertyKind, options);
165 if constexpr (std::is_same_v<SparseModelType, storm::models::sparse::Mdp<ParametricType>>) {
169 "SCP requires the formula's optimization direction (if explicitly given, e.g. Pmax=?/Pmin=?) to match the "
170 "robust reading implied by the threshold direction (AtLeast -> Pmin, AtMost -> Pmax); mismatched combinations "
171 "like 'Pmax >= lambda' are not supported.");
178 return runLoop(env, instantiationChecker, encoder, bound, direction, initialState, initialValuation);
183 return runLoop(env, instantiationChecker, encoder, bound, direction, initialState, initialValuation);
187template<
typename SparseModelType,
typename ConstantType>
188template<
typename InstantiationChecker>
190 InstantiationChecker& instantiationChecker,
193 Valuation
const& initialValuation)
const {
195 auto modelCheck = [&](Valuation
const& valuation) -> std::vector<ConstantType> {
196 auto result = instantiationChecker.check(env, valuation);
197 return result->template asExplicitQuantitativeCheckResult<ConstantType>().getFiniteValueVector();
199 auto toDouble = [](Valuation
const& v) -> std::map<VariableType, double> {
200 std::map<VariableType, double> result;
201 for (
auto const& [var, val] : v) {
206 auto toDoubleVec = [](std::vector<ConstantType>
const& v) -> std::vector<double> {
207 std::vector<double> result(v.size());
208 for (uint64_t i = 0; i < v.size(); ++i) {
215 std::vector<ConstantType> pHat = modelCheck(vHat);
216 ConstantType betaStar = pHat.at(initialState);
224 double delta = options.trustRegionInitial;
226 uint64_t iteration = 0;
227 for (; iteration < options.maxIterations; ++iteration) {
234 if (delta - 1.0 <= options.trustRegionMinExcess) {
239 EncodedLp lp = encoder.
encode(env, toDouble(vHat), toDoubleVec(pHat), delta);
241 if (!lp.solver->isOptimal()) {
242 delta = (delta - 1.0) / options.trustRegionFactor + 1.0;
247 for (
auto const& [var, lpVar] : lp.parameterVariables) {
251 std::vector<ConstantType> valueVector = modelCheck(candidate);
252 ConstantType beta = valueVector.at(initialState);
261 pHat = std::move(valueVector);
264 delta = std::min(options.trustRegionMax, (delta - 1.0) * options.trustRegionFactor + 1.0);
266 delta = (delta - 1.0) / options.trustRegionFactor + 1.0;
double evaluateAsDouble(Valuation const *valuation=nullptr) const
Evaluates the expression under the valuation of variables given by the valuation and returns the resu...
virtual std::unique_ptr< CheckResult > check(Environment const &env, CheckTask< storm::logic::Formula, SolutionType > const &checkTask)
Checks the provided formula.
void setOptimizationDirection(storm::OptimizationDirection const &dir)
Sets the optimization direction.
bool isOptimizationDirectionSet() const
Retrieves whether an optimization direction was set.
storm::OptimizationDirection const & getOptimizationDirection() const
Retrieves the optimization direction (if set).
Class to efficiently check a formula on a parametric model with different parameter instantiations.
void specifyFormula(CheckTask< storm::logic::Formula, typename SparseModelType::ValueType > const &checkTask)
void setInstantiationsAreGraphPreserving(bool value)
Class to efficiently check a formula on a parametric model with different parameter instantiations.
Decomposes the transition matrix of an affine pMDP (or pDTMC), and optionally one reward model's stat...
std::set< storm::RationalFunctionVariable > const & getParameters() const
All parameters occurring anywhere in the model's transition matrix, or (if a reward model was given t...
Builds the linearized-Bellman LP of one SCP iteration (Cubuktepe et al., "Convex Optimization forPara...
EncodedLp encode(storm::Environment const &env, std::map< storm::RationalFunctionVariable, double > const &valuation, std::vector< double > const &stateValues, double trustRegionRadius) const
Builds the LP for one SCP iteration, linearized around (valuation, stateValues) with the given trust ...
Finds a parameter valuation satisfying an unbounded reachability threshold property (probability or r...
ScpResult< ConstantType > run(storm::Environment const &env, std::shared_ptr< storm::pars::FeasibilitySynthesisTask const > const &task)
SparseScpInstantiationSearcher(SparseModelType const &model, ScpOptions options=ScpOptions())
A bit vector that is internally represented as a vector of 64-bit values.
void complement()
Negates all bits in the bit vector.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
std::set< VariableType > const & getVariables() const
Valuation getCenterPoint() const
Returns the center point of this region.
CoefficientType const & getLowerBoundary(VariableType const &variable) const
CoefficientType const & getUpperBoundary(VariableType const &variable) const
#define STORM_LOG_THROW(cond, exception, message)
PropertyKind
The kind of property the LP is built for.
ThresholdDirection
Which side of the threshold a witness is searched for, read robustly over schedulers:
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)
std::pair< storm::storage::BitVector, storm::storage::BitVector > performProb01(storm::models::sparse::DeterministicModel< T > const &model, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
Computes the sets of states that have probability 0 or 1, respectively, of satisfying phi until psi i...
std::pair< storm::storage::BitVector, storm::storage::BitVector > performProb01Max(storm::storage::SparseMatrix< T > const &transitionMatrix, std::vector< uint_fast64_t > const &nondeterministicChoiceIndices, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
storm::storage::BitVector performProb1A(storm::models::sparse::NondeterministicModel< T, RM > const &model, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
Computes the sets of states that have probability 1 of satisfying phi until psi under all possible re...
storm::storage::BitVector performProb1(storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &, storm::storage::BitVector const &psiStates, storm::storage::BitVector const &statesWithProbabilityGreater0)
Computes the set of states of the given model for which all paths lead to the given set of target sta...
std::pair< storm::storage::BitVector, storm::storage::BitVector > performProb01Min(storm::storage::SparseMatrix< T > const &transitionMatrix, std::vector< uint_fast64_t > const &nondeterministicChoiceIndices, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates)
storm::storage::BitVector performProb1E(storm::storage::SparseMatrix< T > const &transitionMatrix, std::vector< uint_fast64_t > const &nondeterministicChoiceIndices, storm::storage::SparseMatrix< T > const &backwardTransitions, storm::storage::BitVector const &phiStates, storm::storage::BitVector const &psiStates, boost::optional< storm::storage::BitVector > const &choiceConstraint)
Computes the sets of states that have probability 1 of satisfying phi until psi under at least one po...
std::map< typename VariableType< FunctionType >::type, typename CoefficientType< FunctionType >::type > Valuation
bool isTerminate()
Check whether the program should terminate (due to some abort signal).
ExtendedValueType< ValueType > positiveInfinity()
std::conditional_t< storm::NumberTraits< ValueType >::HasInfinity, ValueType, ExtendedNumber< ValueType > > ExtendedValueType
The type to use for values that may be infinite.
TargetType convertNumber(SourceType const &number)
bool isLowerBound() const
storm::expressions::Expression threshold
bool isSatisfied(ValueType const &compareValue) const
The LP built for one SCP iteration, with the handles needed to read a solution back.
std::unique_ptr< storm::solver::LpSolver< double > > solver
Configuration for the SCP feasibility search (SparseScpInstantiationSearcher).
The outcome of an SCP search at ConstantType precision (double or storm::RationalNumber): the best po...