From 895c2b6aad874c9c205d4f7474c22d75b8ac0992 Mon Sep 17 00:00:00 2001 From: Lanchid Date: Mon, 8 Apr 2013 12:21:47 +0200 Subject: [PATCH] Convenient file parser for PRCTL, and correct reward formula parsing (together with some necessary code for that) --- src/formula/AbstractFormulaChecker.h | 10 ++- src/formula/CumulativeReward.h | 11 ++- src/formula/Formulas.h | 3 + src/formula/SteadyStateReward.h | 106 +++++++++++++++++++++++ src/modelchecker/AbstractModelChecker.h | 11 +-- src/modelchecker/DtmcPrctlModelChecker.h | 88 ------------------- src/parser/PrctlFileParser.cpp | 71 ++++++++++++--- src/parser/PrctlFileParser.h | 38 ++++++-- src/parser/PrctlParser.cpp | 31 +++++-- test/parser/PrctlParserTest.cpp | 16 ++-- 10 files changed, 251 insertions(+), 134 deletions(-) create mode 100644 src/formula/SteadyStateReward.h diff --git a/src/formula/AbstractFormulaChecker.h b/src/formula/AbstractFormulaChecker.h index 6e74c48a4..c7801e0e2 100644 --- a/src/formula/AbstractFormulaChecker.h +++ b/src/formula/AbstractFormulaChecker.h @@ -38,6 +38,14 @@ namespace formula { template class AbstractFormulaChecker { public: + /*! + * Virtual destructor + * To ensure that the right destructor is called + */ + virtual ~AbstractFormulaChecker() { + //intentionally left empty + } + /*! * @brief Checks if the given formula is valid in some logic. * @@ -53,4 +61,4 @@ class AbstractFormulaChecker { } // namespace formula } // namespace storm -#endif \ No newline at end of file +#endif diff --git a/src/formula/CumulativeReward.h b/src/formula/CumulativeReward.h index 6275621db..3c38991a8 100644 --- a/src/formula/CumulativeReward.h +++ b/src/formula/CumulativeReward.h @@ -11,7 +11,6 @@ #include "AbstractPathFormula.h" #include "AbstractStateFormula.h" #include "src/formula/AbstractFormulaChecker.h" -#include "boost/integer/integer_mask.hpp" #include namespace storm { @@ -64,7 +63,7 @@ public: * * @param bound The time bound of the reward formula */ - CumulativeReward(uint_fast64_t bound) { + CumulativeReward(T bound) { this->bound = bound; } @@ -78,7 +77,7 @@ public: /*! * @returns the time instance for the instantaneous reward operator */ - uint_fast64_t getBound() const { + T getBound() const { return bound; } @@ -87,7 +86,7 @@ public: * * @param bound the new bound. */ - void setBound(uint_fast64_t bound) { + void setBound(T bound) { this->bound = bound; } @@ -95,7 +94,7 @@ public: * @returns a string representation of the formula */ virtual std::string toString() const { - std::string result = "C<="; + std::string result = "C <= "; result += std::to_string(bound); return result; } @@ -138,7 +137,7 @@ public: } private: - uint_fast64_t bound; + T bound; }; } //namespace formula diff --git a/src/formula/Formulas.h b/src/formula/Formulas.h index 193114cb1..e5864bbc0 100644 --- a/src/formula/Formulas.h +++ b/src/formula/Formulas.h @@ -19,6 +19,7 @@ #include "Or.h" #include "ProbabilisticNoBoundOperator.h" #include "ProbabilisticBoundOperator.h" + #include "Until.h" #include "Eventually.h" #include "Globally.h" @@ -29,6 +30,8 @@ #include "ReachabilityReward.h" #include "RewardBoundOperator.h" #include "RewardNoBoundOperator.h" +#include "SteadyStateReward.h" + #include "SteadyStateOperator.h" #include "AbstractFormula.h" diff --git a/src/formula/SteadyStateReward.h b/src/formula/SteadyStateReward.h new file mode 100644 index 000000000..799bc50a7 --- /dev/null +++ b/src/formula/SteadyStateReward.h @@ -0,0 +1,106 @@ +/* + * SteadyStateReward.h + * + * Created on: 08.04.2013 + * Author: thomas + */ + +#ifndef STORM_FORMULA_STEADYSTATEREWARD_H_ +#define STORM_FORMULA_STEADYSTATEREWARD_H_ + +#include "AbstractPathFormula.h" +#include "AbstractStateFormula.h" +#include "src/formula/AbstractFormulaChecker.h" +#include + +namespace storm { +namespace formula { + +template class SteadyStateReward; + +/*! + * @brief Interface class for model checkers that support SteadyStateReward. + * + * All model checkers that support the formula class SteadyStateReward must inherit + * this pure virtual class. + */ +template +class ISteadyStateRewardModelChecker { + public: + /*! + * @brief Evaluates CumulativeReward formula within a model checker. + * + * @param obj Formula object with subformulas. + * @return Result of the formula for every node. + */ + virtual std::vector* checkSteadyStateReward(const SteadyStateReward& obj, bool qualitative) const = 0; +}; + +/*! + * @brief + * Class for a Abstract (path) formula tree with a Steady State Reward node as root. + * + * @see AbstractPathFormula + * @see AbstractFormula + */ +template +class SteadyStateReward: public storm::formula::AbstractPathFormula { +public: + /*! + * Empty constructor + */ + SteadyStateReward() { + // Intentionally left empty + + } + virtual ~SteadyStateReward() { + // Intentionally left empty + } + + /*! + * @returns a string representation of the formula + */ + virtual std::string toString() const { + return "S"; + } + + /*! + * Clones the called object. + * + * Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones + * + * @returns a new SteadyState-object that is identical the called object. + */ + virtual AbstractPathFormula* clone() const { + return new SteadyStateReward(); + } + + /*! + * Calls the model checker to check this formula. + * Needed to infer the correct type of formula class. + * + * @note This function should only be called in a generic check function of a model checker class. For other uses, + * the methods of the model checker should be used. + * + * @returns A vector indicating the probability that the formula holds for each state. + */ + virtual std::vector *check(const storm::modelChecker::AbstractModelChecker& modelChecker, bool qualitative) const { + return modelChecker.template as()->checkSteadyStateReward(*this, qualitative); + } + + /*! + * @brief Checks if all subtrees conform to some logic. + * + * As SteadyStateReward objects have no subformulas, we return true here. + * + * @param checker Formula checker object. + * @return true + */ + virtual bool conforms(const AbstractFormulaChecker& checker) const { + return true; + } +}; + +} /* namespace formula */ +} /* namespace storm */ +#endif /* STEADYSTATEREWARD_H_ */ diff --git a/src/modelchecker/AbstractModelChecker.h b/src/modelchecker/AbstractModelChecker.h index 213cb9938..a2a41f1e3 100644 --- a/src/modelchecker/AbstractModelChecker.h +++ b/src/modelchecker/AbstractModelChecker.h @@ -60,6 +60,10 @@ public: : model(modelChecker->model) { } + virtual ~AbstractModelChecker() { + //intentionally left empty + } + template