Browse Source

CheckTask may now hold info about shielding query

tempestpy_adaptions
Stefan Pranger 4 years ago
parent
commit
102b26b933
  1. 114
      src/storm/modelchecker/CheckTask.h

114
src/storm/modelchecker/CheckTask.h

@ -10,6 +10,7 @@
#include "storm/solver/OptimizationDirection.h" #include "storm/solver/OptimizationDirection.h"
#include "storm/logic/ComparisonType.h" #include "storm/logic/ComparisonType.h"
#include "storm/logic/PlayerCoalition.h" #include "storm/logic/PlayerCoalition.h"
#include "storm/logic/ShieldExpression.h"
#include "storm/modelchecker/hints/ModelCheckerHint.h" #include "storm/modelchecker/hints/ModelCheckerHint.h"
#include "storm/exceptions/InvalidOperationException.h" #include "storm/exceptions/InvalidOperationException.h"
@ -19,13 +20,13 @@ namespace storm {
namespace logic { namespace logic {
class Formula; class Formula;
} }
namespace modelchecker { namespace modelchecker {
enum class CheckType { enum class CheckType {
Probabilities, Rewards Probabilities, Rewards
}; };
/* /*
* This class is used to customize the checking process of a formula. * This class is used to customize the checking process of a formula.
*/ */
@ -34,7 +35,7 @@ namespace storm {
public: public:
template<typename OtherFormulaType, typename OtherValueType> template<typename OtherFormulaType, typename OtherValueType>
friend class CheckTask; friend class CheckTask;
/*! /*!
* Creates a task object with the default options for the given formula. * Creates a task object with the default options for the given formula.
*/ */
@ -42,10 +43,10 @@ namespace storm {
this->onlyInitialStatesRelevant = onlyInitialStatesRelevant; this->onlyInitialStatesRelevant = onlyInitialStatesRelevant;
this->produceSchedulers = false; this->produceSchedulers = false;
this->qualitative = false; this->qualitative = false;
updateOperatorInformation(); updateOperatorInformation();
} }
/*! /*!
* Copies the check task from the source while replacing the formula with the new one. In particular, this * Copies the check task from the source while replacing the formula with the new one. In particular, this
* changes the formula type of the check task object. * changes the formula type of the check task object.
@ -56,7 +57,7 @@ namespace storm {
result.updateOperatorInformation(); result.updateOperatorInformation();
return result; return result;
} }
/*! /*!
* If the currently specified formula is an OperatorFormula, this method updates the information that is given in the Operator formula. * If the currently specified formula is an OperatorFormula, this method updates the information that is given in the Operator formula.
* Calling this method has no effect if the provided formula is not an operator formula. * Calling this method has no effect if the provided formula is not an operator formula.
@ -67,20 +68,20 @@ namespace storm {
if (operatorFormula.hasOptimalityType()) { if (operatorFormula.hasOptimalityType()) {
this->optimizationDirection = operatorFormula.getOptimalityType(); this->optimizationDirection = operatorFormula.getOptimalityType();
} }
if (operatorFormula.hasBound()) { if (operatorFormula.hasBound()) {
this->bound = operatorFormula.getBound(); this->bound = operatorFormula.getBound();
} }
if (operatorFormula.hasOptimalityType()) { if (operatorFormula.hasOptimalityType()) {
this->optimizationDirection = operatorFormula.getOptimalityType(); this->optimizationDirection = operatorFormula.getOptimalityType();
} else if (operatorFormula.hasBound()) { } else if (operatorFormula.hasBound()) {
this->optimizationDirection = operatorFormula.getComparisonType() == storm::logic::ComparisonType::Less || operatorFormula.getComparisonType() == storm::logic::ComparisonType::LessEqual ? OptimizationDirection::Maximize : OptimizationDirection::Minimize; this->optimizationDirection = operatorFormula.getComparisonType() == storm::logic::ComparisonType::Less || operatorFormula.getComparisonType() == storm::logic::ComparisonType::LessEqual ? OptimizationDirection::Maximize : OptimizationDirection::Minimize;
} }
if (formula.get().isProbabilityOperatorFormula()) { if (formula.get().isProbabilityOperatorFormula()) {
storm::logic::ProbabilityOperatorFormula const& probabilityOperatorFormula = formula.get().asProbabilityOperatorFormula(); storm::logic::ProbabilityOperatorFormula const& probabilityOperatorFormula = formula.get().asProbabilityOperatorFormula();
if (probabilityOperatorFormula.hasBound()) { if (probabilityOperatorFormula.hasBound()) {
if (storm::utility::isZero(probabilityOperatorFormula.template getThresholdAs<ValueType>()) || storm::utility::isOne(probabilityOperatorFormula.template getThresholdAs<ValueType>())) { if (storm::utility::isZero(probabilityOperatorFormula.template getThresholdAs<ValueType>()) || storm::utility::isOne(probabilityOperatorFormula.template getThresholdAs<ValueType>())) {
this->qualitative = true; this->qualitative = true;
@ -89,7 +90,7 @@ namespace storm {
} else if (formula.get().isRewardOperatorFormula()) { } else if (formula.get().isRewardOperatorFormula()) {
storm::logic::RewardOperatorFormula const& rewardOperatorFormula = formula.get().asRewardOperatorFormula(); storm::logic::RewardOperatorFormula const& rewardOperatorFormula = formula.get().asRewardOperatorFormula();
this->rewardModel = rewardOperatorFormula.getOptionalRewardModelName(); this->rewardModel = rewardOperatorFormula.getOptionalRewardModelName();
if (rewardOperatorFormula.hasBound()) { if (rewardOperatorFormula.hasBound()) {
if (storm::utility::isZero(rewardOperatorFormula.template getThresholdAs<ValueType>())) { if (storm::utility::isZero(rewardOperatorFormula.template getThresholdAs<ValueType>())) {
this->qualitative = true; this->qualitative = true;
@ -107,49 +108,49 @@ namespace storm {
CheckTask<FormulaType, NewValueType> convertValueType() const { CheckTask<FormulaType, NewValueType> convertValueType() const {
return CheckTask<FormulaType, NewValueType>(this->formula, this->optimizationDirection, this->playerCoalition, this->rewardModel, this->onlyInitialStatesRelevant, this->bound, this->qualitative, this->produceSchedulers, this->hint); return CheckTask<FormulaType, NewValueType>(this->formula, this->optimizationDirection, this->playerCoalition, this->rewardModel, this->onlyInitialStatesRelevant, this->bound, this->qualitative, this->produceSchedulers, this->hint);
} }
/*! /*!
* Retrieves the formula from this task. * Retrieves the formula from this task.
*/ */
FormulaType const& getFormula() const { FormulaType const& getFormula() const {
return formula.get(); return formula.get();
} }
/*! /*!
* Retrieves whether an optimization direction was set. * Retrieves whether an optimization direction was set.
*/ */
bool isOptimizationDirectionSet() const { bool isOptimizationDirectionSet() const {
return static_cast<bool>(optimizationDirection); return static_cast<bool>(optimizationDirection);
} }
/*! /*!
* Retrieves the optimization direction (if set). * Retrieves the optimization direction (if set).
*/ */
storm::OptimizationDirection const& getOptimizationDirection() const { storm::OptimizationDirection const& getOptimizationDirection() const {
return optimizationDirection.get(); return optimizationDirection.get();
} }
/*! /*!
* Sets the optimization direction. * Sets the optimization direction.
*/ */
void setOptimizationDirection(storm::OptimizationDirection const& dir) { void setOptimizationDirection(storm::OptimizationDirection const& dir) {
optimizationDirection = dir; optimizationDirection = dir;
} }
/*! /*!
* Retrieves whether a player coalition was set. * Retrieves whether a player coalition was set.
*/ */
bool isPlayerCoalitionSet() const { bool isPlayerCoalitionSet() const {
return static_cast<bool>(playerCoalition); return static_cast<bool>(playerCoalition);
} }
/*! /*!
* Retrieves the player coalition (if set). * Retrieves the player coalition (if set).
*/ */
storm::logic::PlayerCoalition const& getPlayerCoalition() const { storm::logic::PlayerCoalition const& getPlayerCoalition() const {
return playerCoalition.get(); return playerCoalition.get();
} }
/*! /*!
* Sets the player coalition. * Sets the player coalition.
*/ */
@ -157,28 +158,28 @@ namespace storm {
playerCoalition = coalition; playerCoalition = coalition;
return *this; return *this;
} }
/*! /*!
* Retrieves whether a reward model was set. * Retrieves whether a reward model was set.
*/ */
bool isRewardModelSet() const { bool isRewardModelSet() const {
return static_cast<bool>(rewardModel); return static_cast<bool>(rewardModel);
} }
/*! /*!
* Retrieves the reward model over which to perform the checking (if set). * Retrieves the reward model over which to perform the checking (if set).
*/ */
std::string const& getRewardModel() const { std::string const& getRewardModel() const {
return rewardModel.get(); return rewardModel.get();
} }
/*! /*!
* Retrieves whether only the initial states are relevant in the computation. * Retrieves whether only the initial states are relevant in the computation.
*/ */
bool isOnlyInitialStatesRelevantSet() const { bool isOnlyInitialStatesRelevantSet() const {
return onlyInitialStatesRelevant; return onlyInitialStatesRelevant;
} }
/*! /*!
* Sets whether only initial states are relevant. * Sets whether only initial states are relevant.
*/ */
@ -186,14 +187,37 @@ namespace storm {
this->onlyInitialStatesRelevant = value; this->onlyInitialStatesRelevant = value;
return *this; return *this;
} }
/*
* TODO
*/
bool isShieldingTask() const {
return static_cast<bool>(shieldingExpression);
}
/*
* TODO
*/
std::shared_ptr<storm::logic::ShieldExpression const> getShieldingExpression() const {
return shieldingExpression.get();
}
/*
* TODO
*/
CheckTask<FormulaType, ValueType>& setShieldingExpression(std::shared_ptr<storm::logic::ShieldExpression const> const& shieldingExpression) {
this->shieldingExpression = shieldingExpression;
this->produceSchedulers = true;
return *this;
}
/*! /*!
* Retrieves whether there is a bound with which the values for the states will be compared. * Retrieves whether there is a bound with which the values for the states will be compared.
*/ */
bool isBoundSet() const { bool isBoundSet() const {
return static_cast<bool>(bound); return static_cast<bool>(bound);
} }
/*! /*!
* Retrieves the value of the bound (if set). * Retrieves the value of the bound (if set).
*/ */
@ -201,14 +225,14 @@ namespace storm {
STORM_LOG_THROW(!bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException, "Cannot evaluate threshold '" << bound.get().threshold << "' as it contains undefined constants."); STORM_LOG_THROW(!bound.get().threshold.containsVariables(), storm::exceptions::InvalidOperationException, "Cannot evaluate threshold '" << bound.get().threshold << "' as it contains undefined constants.");
return storm::utility::convertNumber<ValueType>(bound.get().threshold.evaluateAsRational()); return storm::utility::convertNumber<ValueType>(bound.get().threshold.evaluateAsRational());
} }
/*! /*!
* Retrieves the comparison type of the bound (if set). * Retrieves the comparison type of the bound (if set).
*/ */
storm::logic::ComparisonType const& getBoundComparisonType() const { storm::logic::ComparisonType const& getBoundComparisonType() const {
return bound.get().comparisonType; return bound.get().comparisonType;
} }
/*! /*!
* Retrieves the bound (if set). * Retrieves the bound (if set).
*/ */
@ -238,46 +262,46 @@ namespace storm {
void setQualitative(bool value) { void setQualitative(bool value) {
qualitative = value; qualitative = value;
} }
/*! /*!
* Sets whether to produce schedulers (if supported). * Sets whether to produce schedulers (if supported).
*/ */
void setProduceSchedulers(bool produceSchedulers = true) { void setProduceSchedulers(bool produceSchedulers = true) {
this->produceSchedulers = produceSchedulers; this->produceSchedulers = produceSchedulers;
} }
/*! /*!
* Retrieves whether scheduler(s) are to be produced (if supported). * Retrieves whether scheduler(s) are to be produced (if supported).
*/ */
bool isProduceSchedulersSet() const { bool isProduceSchedulersSet() const {
return produceSchedulers; return produceSchedulers;
} }
/*! /*!
* sets a hint that might contain information that speeds up the modelchecking process (if supported by the model checker) * sets a hint that might contain information that speeds up the modelchecking process (if supported by the model checker)
*/ */
void setHint(std::shared_ptr<ModelCheckerHint> const& hint) { void setHint(std::shared_ptr<ModelCheckerHint> const& hint) {
this->hint = hint; this->hint = hint;
} }
/*! /*!
* Retrieves a hint that might contain information that speeds up the modelchecking process (if supported by the model checker) * Retrieves a hint that might contain information that speeds up the modelchecking process (if supported by the model checker)
*/ */
ModelCheckerHint const& getHint() const { ModelCheckerHint const& getHint() const {
return *hint; return *hint;
} }
ModelCheckerHint& getHint() { ModelCheckerHint& getHint() {
return *hint; return *hint;
} }
/*! /*!
* Conversion operator that strips the type of the formula. * Conversion operator that strips the type of the formula.
*/ */
operator CheckTask<storm::logic::Formula, ValueType>() const { operator CheckTask<storm::logic::Formula, ValueType>() const {
return this->substituteFormula<storm::logic::Formula>(this->getFormula()); return this->substituteFormula<storm::logic::Formula>(this->getFormula());
} }
private: private:
/*! /*!
* Creates a task object with the given options. * Creates a task object with the given options.
@ -297,36 +321,42 @@ namespace storm {
CheckTask(std::reference_wrapper<FormulaType const> const& formula, boost::optional<storm::OptimizationDirection> const& optimizationDirection, boost::optional<storm::logic::PlayerCoalition> playerCoalition, boost::optional<std::string> const& rewardModel, bool onlyInitialStatesRelevant, boost::optional<storm::logic::Bound> const& bound, bool qualitative, bool produceSchedulers, std::shared_ptr<ModelCheckerHint> const& hint) : formula(formula), optimizationDirection(optimizationDirection), playerCoalition(playerCoalition), rewardModel(rewardModel), onlyInitialStatesRelevant(onlyInitialStatesRelevant), bound(bound), qualitative(qualitative), produceSchedulers(produceSchedulers), hint(hint) { CheckTask(std::reference_wrapper<FormulaType const> const& formula, boost::optional<storm::OptimizationDirection> const& optimizationDirection, boost::optional<storm::logic::PlayerCoalition> playerCoalition, boost::optional<std::string> const& rewardModel, bool onlyInitialStatesRelevant, boost::optional<storm::logic::Bound> const& bound, bool qualitative, bool produceSchedulers, std::shared_ptr<ModelCheckerHint> const& hint) : formula(formula), optimizationDirection(optimizationDirection), playerCoalition(playerCoalition), rewardModel(rewardModel), onlyInitialStatesRelevant(onlyInitialStatesRelevant), bound(bound), qualitative(qualitative), produceSchedulers(produceSchedulers), hint(hint) {
// Intentionally left empty. // Intentionally left empty.
} }
// The formula that is to be checked. // The formula that is to be checked.
std::reference_wrapper<FormulaType const> formula; std::reference_wrapper<FormulaType const> formula;
// If set, the probabilities will be minimized/maximized. // If set, the probabilities will be minimized/maximized.
boost::optional<storm::OptimizationDirection> optimizationDirection; boost::optional<storm::OptimizationDirection> optimizationDirection;
// If set, the given coalitions of players will be assumed. // If set, the given coalitions of players will be assumed.
boost::optional<storm::logic::PlayerCoalition> playerCoalition; boost::optional<storm::logic::PlayerCoalition> playerCoalition;
// If set, the reward property has to be interpreted over this model. // If set, the reward property has to be interpreted over this model.
boost::optional<std::string> rewardModel; boost::optional<std::string> rewardModel;
// If set to true, the model checker may decide to only compute the values for the initial states. // If set to true, the model checker may decide to only compute the values for the initial states.
bool onlyInitialStatesRelevant; bool onlyInitialStatesRelevant;
// If set to true, we will create the appropriate shield.
bool shieldingTask = false;
// The according ShieldExpression.
boost::optional<std::shared_ptr<storm::logic::ShieldExpression const>> shieldingExpression;
// The bound with which the states will be compared. // The bound with which the states will be compared.
boost::optional<storm::logic::Bound> bound; boost::optional<storm::logic::Bound> bound;
// A flag specifying whether the property needs to be checked qualitatively, i.e. compared with bounds 0/1. // A flag specifying whether the property needs to be checked qualitatively, i.e. compared with bounds 0/1.
bool qualitative; bool qualitative;
// If supported by the model checker and the model formalism, schedulers to achieve a value will be produced // If supported by the model checker and the model formalism, schedulers to achieve a value will be produced
// if this flag is set. // if this flag is set.
bool produceSchedulers; bool produceSchedulers;
// A hint that might contain information that speeds up the modelchecking process (if supported by the model checker) // A hint that might contain information that speeds up the modelchecking process (if supported by the model checker)
std::shared_ptr<ModelCheckerHint> hint; std::shared_ptr<ModelCheckerHint> hint;
}; };
} }
} }

Loading…
Cancel
Save