Browse Source

Merge branch 'interfacelogic'

Conflicts:
	src/models/Mdp.h
	src/parser/NonDeterministicSparseTransitionParser.cpp
	src/parser/NonDeterministicSparseTransitionParser.h
tempestpy_adaptions
gereon 12 years ago
parent
commit
bd39a9b44c
  1. 73
      src/formula/AbstractFormula.h
  2. 56
      src/formula/AbstractFormulaChecker.h
  3. 31
      src/formula/AbstractPathFormula.h
  4. 30
      src/formula/AbstractStateFormula.h
  5. 65
      src/formula/And.h
  6. 51
      src/formula/Ap.h
  7. 60
      src/formula/BoundOperator.h
  8. 60
      src/formula/BoundedEventually.h
  9. 211
      src/formula/BoundedNaryUntil.h
  10. 67
      src/formula/BoundedUntil.h
  11. 53
      src/formula/CumulativeReward.h
  12. 61
      src/formula/Eventually.h
  13. 8
      src/formula/Formulas.h
  14. 61
      src/formula/Globally.h
  15. 53
      src/formula/InstantaneousReward.h
  16. 59
      src/formula/Next.h
  17. 63
      src/formula/NoBoundOperator.h
  18. 58
      src/formula/Not.h
  19. 66
      src/formula/Or.h
  20. 48
      src/formula/PctlFormula.h
  21. 46
      src/formula/PrctlFormulaChecker.h
  22. 22
      src/formula/ProbabilisticBoundOperator.h
  23. 20
      src/formula/ProbabilisticNoBoundOperator.h
  24. 64
      src/formula/ReachabilityReward.h
  25. 19
      src/formula/RewardBoundOperator.h
  26. 20
      src/formula/RewardNoBoundOperator.h
  27. 66
      src/formula/Until.h
  28. 57
      src/modelChecker/AbstractModelChecker.h
  29. 19
      src/modelChecker/DtmcPrctlModelChecker.h
  30. 2
      src/parser/NonDeterministicSparseTransitionParser.h
  31. 6
      src/parser/PrctlParser.cpp
  32. 5
      src/parser/PrctlParser.h

73
src/formula/AbstractFormula.h

@ -0,0 +1,73 @@
/*
* Abstractformula.h
*
* Created on: 19.10.2012
* Author: Thomas Heinemann
*/
#ifndef STORM_FORMULA_ABSTRACTFORMULA_H_
#define STORM_FORMULA_ABSTRACTFORMULA_H_
#include <string>
namespace storm { namespace formula {
template <class T> class AbstractFormula;
}}
#include "src/modelChecker/AbstractModelChecker.h"
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
//abstract
/*!
* @brief Abstract base class for Abstract formulas in general.
*
* @attention This class is abstract.
* @note Formula classes do not have copy constructors. The parameters of the constructors are usually the subtrees, so
* the syntax conflicts with copy constructors for unary operators. To produce an identical object, the classes
* AbstractPathFormula and AbstractStateFormula offer the method clone().
*
* This is the base class for every formula class in every logic.
*/
template <class T>
class AbstractFormula {
public:
/*!
* Virtual destructor.
*/
virtual ~AbstractFormula() { }
/*!
* @brief Return string representation of this formula.
*
* @note very subclass must implement this method.
*
* @returns a string representation of the formula
*/
virtual std::string toString() const = 0;
/*!
* @brief Checks if all subtrees are valid in some logic.
*
* @note Every subclass must implement this method.
*
* This method is given a checker object that knows which formula
* classes are allowed within the logic the checker represents. Every
* subclass is supposed to call checker.conforms() for all child
* formulas and return true if and only if all those calls returned
* true.
*
* @param checker Checker object.
* @return true iff all subtrees are valid.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const = 0;
};
} // namespace formula
} // namespace storm
#endif /* STORM_FORMULA_ABSTRACTFORMULA_H_ */

56
src/formula/AbstractFormulaChecker.h

@ -0,0 +1,56 @@
#ifndef STORM_FORMULA_ABSTRACTFORMULACHECKER_H_
#define STORM_FORMULA_ABSTRACTFORMULACHECKER_H_
#include "src/formula/AbstractFormula.h"
namespace storm {
namespace formula {
/*!
* @brief Base class for all formula checkers.
*
* A formula checker is used to check if a given formula is valid in some
* logic. Hence, this pure virtual base class should be subclassed for
* every logic we support.
*
* Every subclass must implement conforms(). It gets a pointer to an
* AbstractFormula object and should return if the subtree represented by
* this formula is valid in the logic.
*
* Usually, this will be implemented like this:
* @code
* if (
* dynamic_cast<const And<T>*>(formula) ||
* dynamic_cast<const Not<T>*>(formula) ||
* dynamic_cast<const Or<T>*>(formula)
* ) {
* return formula->conforms(*this);
* } else return false;
* @endcode
*
* Every formula class implements a conforms() method itself which calls
* conforms() on the given checker for every child in the formula tree.
*
* If the formula structure is not an actual tree, but an directed acyclic
* graph, the shared subtrees will be checked twice. If we have directed
* cycles, we will have infinite recursions.
*/
template <class T>
class AbstractFormulaChecker {
public:
/*!
* @brief Checks if the given formula is valid in some logic.
*
* Every subclass must implement this method and check, if the
* formula object is valid in the logic of the subclass.
*
* @param formula A pointer to some formula object.
* @return true iff the formula is valid.
*/
virtual bool conforms(const AbstractFormula<T>* formula) const = 0;
};
} // namespace formula
} // namespace storm
#endif

31
src/formula/PctlPathFormula.h → src/formula/AbstractPathFormula.h

@ -1,24 +1,30 @@
/*
* PctlPathFormula.h
* AbstractPathFormula.h
*
* Created on: 19.10.2012
* Author: Thomas Heinemann
*/
#ifndef STORM_FORMULA_PCTLPATHFORMULA_H_
#define STORM_FORMULA_PCTLPATHFORMULA_H_
#ifndef STORM_FORMULA_ABSTRACTPATHFORMULA_H_
#define STORM_FORMULA_ABSTRACTPATHFORMULA_H_
#include "PctlFormula.h"
#include "modelChecker/DtmcPrctlModelChecker.h"
namespace storm { namespace formula {
template <class T> class AbstractPathFormula;
}}
#include "src/formula/AbstractFormula.h"
#include "modelChecker/AbstractModelChecker.h"
#include <vector>
#include <iostream>
#include <typeinfo>
namespace storm {
namespace formula {
/*!
* @brief
* Abstract base class for PCTL path formulas.
* Abstract base class for Abstract path formulas.
*
* @attention This class is abstract.
* @note Formula classes do not have copy constructors. The parameters of the constructors are usually the subtrees, so
@ -26,13 +32,13 @@ namespace formula {
* clone().
*/
template <class T>
class PctlPathFormula : public PctlFormula<T> {
class AbstractPathFormula : public virtual AbstractFormula<T> {
public:
/*!
* empty destructor
*/
virtual ~PctlPathFormula() { }
virtual ~AbstractPathFormula() { }
/*!
* Clones the called object.
@ -42,7 +48,7 @@ public:
* @note This function is not implemented in this class.
* @returns a new AND-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const = 0;
virtual AbstractPathFormula<T>* clone() const = 0;
/*!
* Calls the model checker to check this formula.
@ -55,11 +61,10 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T>* check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const = 0;
virtual std::vector<T>* check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const = 0;
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_PCTLPATHFORMULA_H_ */
#endif /* STORM_FORMULA_ABSTRACTPATHFORMULA_H_ */

30
src/formula/PctlStateFormula.h → src/formula/AbstractStateFormula.h

@ -1,24 +1,27 @@
/*
* PctlStateFormula.h
* AbstractStateFormula.h
*
* Created on: 19.10.2012
* Author: Thomas Heinemann
*/
#ifndef STORM_FORMULA_PCTLSTATEFORMULA_H_
#define STORM_FORMULA_PCTLSTATEFORMULA_H_
#ifndef STORM_FORMULA_ABSTRACTSTATEFORMULA_H_
#define STORM_FORMULA_ABSTRACTSTATEFORMULA_H_
#include "PctlFormula.h"
#include "storage/BitVector.h"
#include "modelChecker/DtmcPrctlModelChecker.h"
namespace storm { namespace formula {
template <class T> class AbstractStateFormula;
}}
namespace storm {
#include "AbstractFormula.h"
#include "src/storage/BitVector.h"
#include "src/modelChecker/AbstractModelChecker.h"
namespace storm {
namespace formula {
/*!
* @brief
* Abstract base class for PCTL state formulas.
* Abstract base class for Abstract state formulas.
*
* @attention This class is abstract.
* @note Formula classes do not have copy constructors. The parameters of the constructors are usually the subtrees, so
@ -26,13 +29,13 @@ namespace formula {
* clone().
*/
template <class T>
class PctlStateFormula : public PctlFormula<T> {
class AbstractStateFormula : public AbstractFormula<T> {
public:
/*!
* empty destructor
*/
virtual ~PctlStateFormula() { }
virtual ~AbstractStateFormula() { }
/*!
* Clones the called object.
@ -42,7 +45,7 @@ public:
* @note This function is not implemented in this class.
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const = 0;
virtual AbstractStateFormula<T>* clone() const = 0;
/*!
* Calls the model checker to check this formula.
@ -55,12 +58,11 @@ public:
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual storm::storage::BitVector *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const = 0;
virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const = 0; // {
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_PCTLSTATEFORMULA_H_ */
#endif /* STORM_FORMULA_AbstractSTATEFORMULA_H_ */

65
src/formula/And.h

@ -8,18 +8,39 @@
#ifndef STORM_FORMULA_AND_H_
#define STORM_FORMULA_AND_H_
#include "PctlStateFormula.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "src/modelChecker/AbstractModelChecker.h"
#include <string>
namespace storm {
namespace formula {
template <class T> class And;
/*!
* @brief Interface class for model checkers that support And.
*
* All model checkers that support the formula class And must inherit
* this pure virtual class.
*/
template <class T>
class IAndModelChecker {
public:
/*!
* @brief Evaluates And formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual storm::storage::BitVector* checkAnd(const And<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL formula tree with AND node as root.
* Class for a Abstract formula tree with AND node as root.
*
* Has two PCTL state formulas as sub formulas/trees.
* Has two Abstract state formulas as sub formulas/trees.
*
* As AND is commutative, the order is \e theoretically not important, but will influence the order in which
* the model checker works.
@ -27,11 +48,11 @@ namespace formula {
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlStateFormula
* @see PctlFormula
* @see AbstractStateFormula
* @see AbstractFormula
*/
template <class T>
class And : public PctlStateFormula<T> {
class And : public AbstractStateFormula<T> {
public:
/*!
@ -50,7 +71,7 @@ public:
* @param left The left sub formula
* @param right The right sub formula
*/
And(PctlStateFormula<T>* left, PctlStateFormula<T>* right) {
And(AbstractStateFormula<T>* left, AbstractStateFormula<T>* right) {
this->left = left;
this->right = right;
}
@ -75,7 +96,7 @@ public:
*
* @param newLeft the new left child.
*/
void setLeft(PctlStateFormula<T>* newLeft) {
void setLeft(AbstractStateFormula<T>* newLeft) {
left = newLeft;
}
@ -84,21 +105,21 @@ public:
*
* @param newRight the new right child.
*/
void setRight(PctlStateFormula<T>* newRight) {
void setRight(AbstractStateFormula<T>* newRight) {
right = newRight;
}
/*!
* @returns a pointer to the left child node
*/
const PctlStateFormula<T>& getLeft() const {
const AbstractStateFormula<T>& getLeft() const {
return *left;
}
/*!
* @returns a pointer to the right child node
*/
const PctlStateFormula<T>& getRight() const {
const AbstractStateFormula<T>& getRight() const {
return *right;
}
@ -121,7 +142,7 @@ public:
*
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const {
virtual AbstractStateFormula<T>* clone() const {
And<T>* result = new And();
if (this->left != NULL) {
result->setLeft(left->clone());
@ -141,13 +162,23 @@ public:
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual storm::storage::BitVector *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkAnd(*this);
virtual storm::storage::BitVector* check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IAndModelChecker>()->checkAnd(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* @param checker Formula checker object.
* @return true iff all subtrees conform to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->left) && checker.conforms(this->right);
}
private:
PctlStateFormula<T>* left;
PctlStateFormula<T>* right;
AbstractStateFormula<T>* left;
AbstractStateFormula<T>* right;
};
} //namespace formula

51
src/formula/Ap.h

@ -8,23 +8,44 @@
#ifndef STORM_FORMULA_AP_H_
#define STORM_FORMULA_AP_H_
#include "PctlStateFormula.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "src/modelChecker/AbstractModelChecker.h"
namespace storm {
namespace formula {
template <class T> class Ap;
/*!
* @brief Interface class for model checkers that support Ap.
*
* All model checkers that support the formula class Ap must inherit
* this pure virtual class.
*/
template <class T>
class IApModelChecker {
public:
/*!
* @brief Evaluates Ap formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual storm::storage::BitVector* checkAp(const Ap<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL formula tree with atomic proposition as root.
* Class for a Abstract formula tree with atomic proposition as root.
*
* This class represents the leaves in the formula tree.
*
* @see PctlStateFormula
* @see PctlFormula
* @see AbstractStateFormula
* @see AbstractFormula
*/
template <class T>
class Ap : public PctlStateFormula<T> {
class Ap : public AbstractStateFormula<T> {
public:
/*!
@ -64,7 +85,7 @@ public:
*
* @returns a new Ap-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const {
virtual AbstractStateFormula<T>* clone() const {
return new Ap(ap);
}
@ -77,8 +98,20 @@ public:
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual storm::storage::BitVector *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkAp(*this);
virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IApModelChecker>()->checkAp(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* As atomic propositions have no subformulas, we return true here.
*
* @param checker Formula checker object.
* @return true
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return true;
}
private:

60
src/formula/BoundOperator.h

@ -8,20 +8,36 @@
#ifndef STORM_FORMULA_BOUNDOPERATOR_H_
#define STORM_FORMULA_BOUNDOPERATOR_H_
#include "PctlStateFormula.h"
#include "PctlPathFormula.h"
#include "utility/ConstTemplates.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/formula/AbstractPathFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "src/modelChecker/AbstractModelChecker.h"
#include "src/utility/ConstTemplates.h"
namespace storm {
namespace formula {
template <class T> class BoundOperator;
/*!
* @brief Interface class for model checkers that support BoundOperator.
*
* All model checkers that support the formula class BoundOperator must inherit
* this pure virtual class.
*/
template <class T>
class IBoundOperatorModelChecker {
public:
virtual storm::storage::BitVector* checkBoundOperator(const BoundOperator<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL formula tree with a P (probablistic) operator node over a probability interval
* Class for a Abstract formula tree with a P (probablistic) operator node over a probability interval
* as root.
*
* Has one PCTL path formula as sub formula/tree.
* Has one Abstract path formula as sub formula/tree.
*
* @par Semantics
* The formula holds iff the probability that the path formula holds is inside the bounds
@ -31,14 +47,14 @@ namespace formula {
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PctlStateFormula
* @see PctlPathFormula
* @see AbstractStateFormula
* @see AbstractPathFormula
* @see ProbabilisticOperator
* @see ProbabilisticNoBoundsOperator
* @see PctlFormula
* @see AbstractFormula
*/
template<class T>
class BoundOperator : public PctlStateFormula<T> {
class BoundOperator : public AbstractStateFormula<T> {
public:
enum ComparisonType { LESS, LESS_EQUAL, GREATER, GREATER_EQUAL };
@ -50,7 +66,7 @@ public:
* @param upperBound The upper bound for the probability
* @param pathFormula The child node
*/
BoundOperator(ComparisonType comparisonOperator, T bound, PctlPathFormula<T>* pathFormula)
BoundOperator(ComparisonType comparisonOperator, T bound, AbstractPathFormula<T>* pathFormula)
: comparisonOperator(comparisonOperator), bound(bound), pathFormula(pathFormula) {
// Intentionally left empty
}
@ -68,9 +84,9 @@ public:
}
/*!
* @returns the child node (representation of a PCTL path formula)
* @returns the child node (representation of a Abstract path formula)
*/
const PctlPathFormula<T>& getPathFormula () const {
const AbstractPathFormula<T>& getPathFormula () const {
return *pathFormula;
}
@ -79,7 +95,7 @@ public:
*
* @param pathFormula the path formula that becomes the new child node
*/
void setPathFormula(PctlPathFormula<T>* pathFormula) {
void setPathFormula(AbstractPathFormula<T>* pathFormula) {
this->pathFormula = pathFormula;
}
@ -134,7 +150,7 @@ public:
*
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const = 0;
virtual AbstractStateFormula<T>* clone() const = 0;
/*!
* Calls the model checker to check this formula.
@ -145,14 +161,24 @@ public:
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual storm::storage::BitVector *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkBoundOperator(*this);
virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IBoundOperatorModelChecker>()->checkBoundOperator(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->pathFormula);
}
private:
ComparisonType comparisonOperator;
T bound;
PctlPathFormula<T>* pathFormula;
AbstractPathFormula<T>* pathFormula;
};
} //namespace formula

60
src/formula/BoundedEventually.h

@ -8,20 +8,42 @@
#ifndef STORM_FORMULA_BOUNDEDEVENTUALLY_H_
#define STORM_FORMULA_BOUNDEDEVENTUALLY_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "boost/integer/integer_mask.hpp"
#include <string>
#include "src/modelChecker/AbstractModelChecker.h"
namespace storm {
namespace formula {
template <class T> class BoundedEventually;
/*!
* @brief Interface class for model checkers that support BoundedEventually.
*
* All model checkers that support the formula class BoundedEventually must inherit
* this pure virtual class.
*/
template <class T>
class IBoundedEventuallyModelChecker {
public:
/*!
* @brief Evaluates BoundedEventually formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkBoundedEventually(const BoundedEventually<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with a BoundedEventually node as root.
* Class for a Abstract (path) formula tree with a BoundedEventually node as root.
*
* Has one PCTL state formulas as sub formula/tree.
* Has one Abstract state formulas as sub formula/tree.
*
* @par Semantics
* The formula holds iff in at most \e bound steps, formula \e child holds.
@ -29,11 +51,11 @@ namespace formula {
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class BoundedEventually : public PctlPathFormula<T> {
class BoundedEventually : public AbstractPathFormula<T> {
public:
/*!
@ -50,7 +72,7 @@ public:
* @param child The child formula subtree
* @param bound The maximal number of steps
*/
BoundedEventually(PctlStateFormula<T>* child, uint_fast64_t bound) {
BoundedEventually(AbstractStateFormula<T>* child, uint_fast64_t bound) {
this->child = child;
this->bound = bound;
}
@ -70,7 +92,7 @@ public:
/*!
* @returns the child node
*/
const PctlStateFormula<T>& getChild() const {
const AbstractStateFormula<T>& getChild() const {
return *child;
}
@ -78,7 +100,7 @@ public:
* Sets the subtree
* @param child the new child node
*/
void setChild(PctlStateFormula<T>* child) {
void setChild(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -116,7 +138,7 @@ public:
*
* @returns a new BoundedUntil-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
BoundedEventually<T>* result = new BoundedEventually<T>();
result->setBound(bound);
if (child != nullptr) {
@ -135,12 +157,22 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkBoundedEventually(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IBoundedEventuallyModelChecker>()->checkBoundedEventually(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->child);
}
private:
PctlStateFormula<T>* child;
AbstractStateFormula<T>* child;
uint_fast64_t bound;
};

211
src/formula/BoundedNaryUntil.h

@ -0,0 +1,211 @@
/*
* BoundedNaryUntil.h
*
* Created on: 19.10.2012
* Author: Thomas Heinemann
*/
#ifndef STORM_FORMULA_BOUNDEDNARYUNTIL_H_
#define STORM_FORMULA_BOUNDEDNARYUNTIL_H_
#include "src/formula/AbstractPathFormula.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/modelChecker/AbstractModelChecker.h"
#include "boost/integer/integer_mask.hpp"
#include <string>
#include <vector>
#include <tuple>
#include <sstream>
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class BoundedNaryUntil;
/*!
* @brief Interface class for model checkers that support BoundedNaryUntil.
*
* All model checkers that support the formula class BoundedNaryUntil must inherit
* this pure virtual class.
*/
template <class T>
class IBoundedNaryUntilModelChecker {
public:
/*!
* @brief Evaluates BoundedNaryUntil formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkBoundedNaryUntil(const BoundedNaryUntil<T>& obj) const = 0;
};
/*!
* @brief
* Class for a Abstract (path) formula tree with a BoundedNaryUntil node as root.
*
* Has at least two Abstract state formulas as sub formulas and an interval
* associated with all but the first sub formula. We'll call the first one
* \e left and all other one \e right.
*
* @par Semantics
* The formula holds iff \e left holds until eventually any of the \e right
* formulas holds after a number of steps contained in the interval
* associated with this formula.
*
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class BoundedNaryUntil : public AbstractPathFormula<T> {
public:
/*!
* Empty constructor
*/
BoundedNaryUntil() {
this->left = NULL;
this->right = new std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>();
}
/*!
* Constructor
*
* @param left The left formula subtree
* @param right The left formula subtree
* @param bound The maximal number of steps
*/
BoundedNaryUntil(AbstractStateFormula<T>* left, std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>* right) {
this->left = left;
this->right = right;
}
/*!
* Destructor.
*
* Also deletes the subtrees.
* (this behaviour can be prevented by setting the subtrees to NULL before deletion)
*/
virtual ~BoundedNaryUntil() {
if (left != NULL) {
delete left;
}
if (right != NULL) {
delete right;
}
}
/*!
* Sets the left child node.
*
* @param newLeft the new left child.
*/
void setLeft(AbstractStateFormula<T>* newLeft) {
left = newLeft;
}
void setRight(std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>* newRight) {
right = newRight;
}
/*!
* Sets the right child node.
*
* @param newRight the new right child.
*/
void addRight(AbstractStateFormula<T>* newRight, T upperBound, T lowerBound) {
this->right->push_back(std::tuple<AbstractStateFormula<T>*,T,T>(newRight, upperBound, lowerBound));
}
/*!
* @returns a pointer to the left child node
*/
const AbstractStateFormula<T>& getLeft() const {
return *left;
}
/*!
* @returns a pointer to the right child nodes.
*/
const std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>& getRight() const {
return *right;
}
/*!
* @returns a string representation of the formula
*/
virtual std::string toString() const {
std::stringstream result;
result << "( " << left->toString();
for (auto it = this->right->begin(); it != this->right->end(); ++it) {
result << " U[" << std::get<1>(*it) << "," << std::get<2>(*it) << "] " << std::get<0>(*it)->toString();
}
result << ")";
return result.str();
}
/*!
* 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 BoundedNaryUntil-object that is identical the called object.
*/
virtual AbstractPathFormula<T>* clone() const {
BoundedNaryUntil<T>* result = new BoundedNaryUntil<T>();
if (left != NULL) {
result->setLeft(left->clone());
}
if (right != NULL) {
std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>* newright = new std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>();
for (auto it = this->right->begin(); it != this->right->end(); ++it) {
newright->push_back(std::tuple<AbstractStateFormula<T>*,T,T>(std::get<0>(*it)->clone(), std::get<1>(*it), std::get<2>(*it)));
}
result->setRight(newright);
}
return result;
}
/*!
* 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<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IBoundedNaryUntilModelChecker>()->checkBoundedNaryUntil(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* @param checker Formula checker object.
* @return true iff all subtrees conform to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
bool res = checker.conforms(this->left);
for (auto it = this->right->begin(); it != this->right->end(); ++it) {
res &= checker.conforms(std::get<0>(*it));
}
return res;
}
private:
AbstractStateFormula<T>* left;
std::vector<std::tuple<AbstractStateFormula<T>*,T,T>>* right;
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_BOUNDEDNARYUNTIL_H_ */

67
src/formula/BoundedUntil.h

@ -8,20 +8,41 @@
#ifndef STORM_FORMULA_BOUNDEDUNTIL_H_
#define STORM_FORMULA_BOUNDEDUNTIL_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "src/formula/AbstractPathFormula.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/modelChecker/AbstractModelChecker.h"
#include "boost/integer/integer_mask.hpp"
#include <string>
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class BoundedUntil;
/*!
* @brief Interface class for model checkers that support BoundedUntil.
*
* All model checkers that support the formula class BoundedUntil must inherit
* this pure virtual class.
*/
template <class T>
class IBoundedUntilModelChecker {
public:
/*!
* @brief Evaluates BoundedUntil formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkBoundedUntil(const BoundedUntil<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with a BoundedUntil node as root.
* Class for a Abstract (path) formula tree with a BoundedUntil node as root.
*
* Has two PCTL state formulas as sub formulas/trees.
* Has two Abstract state formulas as sub formulas/trees.
*
* @par Semantics
* The formula holds iff in at most \e bound steps, formula \e right (the right subtree) holds, and before,
@ -30,11 +51,11 @@ namespace formula {
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class BoundedUntil : public PctlPathFormula<T> {
class BoundedUntil : public AbstractPathFormula<T> {
public:
/*!
@ -53,7 +74,7 @@ public:
* @param right The left formula subtree
* @param bound The maximal number of steps
*/
BoundedUntil(PctlStateFormula<T>* left, PctlStateFormula<T>* right,
BoundedUntil(AbstractStateFormula<T>* left, AbstractStateFormula<T>* right,
uint_fast64_t bound) {
this->left = left;
this->right = right;
@ -80,7 +101,7 @@ public:
*
* @param newLeft the new left child.
*/
void setLeft(PctlStateFormula<T>* newLeft) {
void setLeft(AbstractStateFormula<T>* newLeft) {
left = newLeft;
}
@ -89,21 +110,21 @@ public:
*
* @param newRight the new right child.
*/
void setRight(PctlStateFormula<T>* newRight) {
void setRight(AbstractStateFormula<T>* newRight) {
right = newRight;
}
/*!
* @returns a pointer to the left child node
*/
const PctlStateFormula<T>& getLeft() const {
const AbstractStateFormula<T>& getLeft() const {
return *left;
}
/*!
* @returns a pointer to the right child node
*/
const PctlStateFormula<T>& getRight() const {
const AbstractStateFormula<T>& getRight() const {
return *right;
}
@ -144,7 +165,7 @@ public:
*
* @returns a new BoundedUntil-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
BoundedUntil<T>* result = new BoundedUntil<T>();
result->setBound(bound);
if (left != NULL) {
@ -166,13 +187,23 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkBoundedUntil(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IBoundedUntilModelChecker>()->checkBoundedUntil(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* @param checker Formula checker object.
* @return true iff all subtrees conform to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->left) && checker.conforms(this->right);
}
private:
PctlStateFormula<T>* left;
PctlStateFormula<T>* right;
AbstractStateFormula<T>* left;
AbstractStateFormula<T>* right;
uint_fast64_t bound;
};

53
src/formula/CumulativeReward.h

@ -8,8 +8,9 @@
#ifndef STORM_FORMULA_CUMULATIVEREWARD_H_
#define STORM_FORMULA_CUMULATIVEREWARD_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "boost/integer/integer_mask.hpp"
#include <string>
@ -17,18 +18,38 @@ namespace storm {
namespace formula {
template <class T> class CumulativeReward;
/*!
* @brief Interface class for model checkers that support CumulativeReward.
*
* All model checkers that support the formula class CumulativeReward must inherit
* this pure virtual class.
*/
template <class T>
class ICumulativeRewardModelChecker {
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<T>* checkCumulativeReward(const CumulativeReward<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with a Cumulative Reward node as root.
* Class for a Abstract (path) formula tree with a Cumulative Reward node as root.
*
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class CumulativeReward : public PctlPathFormula<T> {
class CumulativeReward : public AbstractPathFormula<T> {
public:
/*!
@ -84,9 +105,9 @@ public:
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new BoundedUntil-object that is identical the called object.
* @returns a new CumulativeReward-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
return new CumulativeReward(bound);
}
@ -100,8 +121,20 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkCumulativeReward(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<ICumulativeRewardModelChecker>()->checkCumulativeReward(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* As CumulativeReward objects have no subformulas, we return true here.
*
* @param checker Formula checker object.
* @return true
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return true;
}
private:

61
src/formula/Eventually.h

@ -8,18 +8,39 @@
#ifndef STORM_FORMULA_EVENTUALLY_H_
#define STORM_FORMULA_EVENTUALLY_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/modelChecker/AbstractModelChecker.h"
namespace storm {
namespace formula {
template <class T> class Eventually;
/*!
* @brief Interface class for model checkers that support Eventually.
*
* All model checkers that support the formula class Eventually must inherit
* this pure virtual class.
*/
template <class T>
class IEventuallyModelChecker {
public:
/*!
* @brief Evaluates Eventually formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkEventually(const Eventually<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with an Eventually node as root.
* Class for a Abstract (path) formula tree with an Eventually node as root.
*
* Has one PCTL state formula as sub formula/tree.
* Has one Abstract state formula as sub formula/tree.
*
* @par Semantics
* The formula holds iff eventually \e child holds.
@ -27,11 +48,11 @@ namespace formula {
* The subtree is seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to nullptr before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class Eventually : public PctlPathFormula<T> {
class Eventually : public AbstractPathFormula<T> {
public:
/*!
@ -46,7 +67,7 @@ public:
*
* @param child The child node
*/
Eventually(PctlStateFormula<T>* child) {
Eventually(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -65,7 +86,7 @@ public:
/*!
* @returns the child node
*/
const PctlStateFormula<T>& getChild() const {
const AbstractStateFormula<T>& getChild() const {
return *child;
}
@ -73,7 +94,7 @@ public:
* Sets the subtree
* @param child the new child node
*/
void setChild(PctlStateFormula<T>* child) {
void setChild(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -91,9 +112,9 @@ public:
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new BoundedUntil-object that is identical the called object.
* @returns a new Eventually-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
Eventually<T>* result = new Eventually<T>();
if (child != nullptr) {
result->setChild(child);
@ -110,12 +131,22 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkEventually(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IEventuallyModelChecker>()->checkEventually(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->child);
}
private:
PctlStateFormula<T>* child;
AbstractStateFormula<T>* child;
};
} //namespace formula

8
src/formula/Formulas.h

@ -8,15 +8,17 @@
#ifndef STORM_FORMULA_FORMULAS_H_
#define STORM_FORMULA_FORMULAS_H_
#include "AbstractFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "And.h"
#include "Ap.h"
#include "BoundedUntil.h"
#include "BoundedNaryUntil.h"
#include "Next.h"
#include "Not.h"
#include "Or.h"
#include "PctlFormula.h"
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "ProbabilisticNoBoundOperator.h"
#include "ProbabilisticBoundOperator.h"
#include "Until.h"

61
src/formula/Globally.h

@ -8,18 +8,39 @@
#ifndef STORM_FORMULA_GLOBALLY_H_
#define STORM_FORMULA_GLOBALLY_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class Globally;
/*!
* @brief Interface class for model checkers that support Globally.
*
* All model checkers that support the formula class Globally must inherit
* this pure virtual class.
*/
template <class T>
class IGloballyModelChecker {
public:
/*!
* @brief Evaluates Globally formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkGlobally(const Globally<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with a Globally node as root.
* Class for a Abstract (path) formula tree with a Globally node as root.
*
* Has one PCTL state formula as sub formula/tree.
* Has one Abstract state formula as sub formula/tree.
*
* @par Semantics
* The formula holds iff globally \e child holds.
@ -27,11 +48,11 @@ namespace formula {
* The subtree is seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to nullptr before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class Globally : public PctlPathFormula<T> {
class Globally : public AbstractPathFormula<T> {
public:
/*!
@ -46,7 +67,7 @@ public:
*
* @param child The child node
*/
Globally(PctlStateFormula<T>* child) {
Globally(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -65,7 +86,7 @@ public:
/*!
* @returns the child node
*/
const PctlStateFormula<T>& getChild() const {
const AbstractStateFormula<T>& getChild() const {
return *child;
}
@ -73,7 +94,7 @@ public:
* Sets the subtree
* @param child the new child node
*/
void setChild(PctlStateFormula<T>* child) {
void setChild(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -91,9 +112,9 @@ public:
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new BoundedUntil-object that is identical the called object.
* @returns a new Globally-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
Next<T>* result = new Next<T>();
if (child != nullptr) {
result->setChild(child);
@ -110,12 +131,22 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkGlobally(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IGloballyModelChecker>()->checkGlobally(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->child);
}
private:
PctlStateFormula<T>* child;
AbstractStateFormula<T>* child;
};
} //namespace formula

53
src/formula/InstantaneousReward.h

@ -8,8 +8,9 @@
#ifndef STORM_FORMULA_INSTANTANEOUSREWARD_H_
#define STORM_FORMULA_INSTANTANEOUSREWARD_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "boost/integer/integer_mask.hpp"
#include <string>
@ -17,18 +18,38 @@ namespace storm {
namespace formula {
template <class T> class InstantaneousReward;
/*!
* @brief Interface class for model checkers that support InstantaneousReward.
*
* All model checkers that support the formula class InstantaneousReward must inherit
* this pure virtual class.
*/
template <class T>
class IInstantaneousRewardModelChecker {
public:
/*!
* @brief Evaluates InstantaneousReward formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkInstantaneousReward(const InstantaneousReward<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with a Instantaneous Reward node as root.
* Class for a Abstract (path) formula tree with a Instantaneous Reward node as root.
*
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class InstantaneousReward : public PctlPathFormula<T> {
class InstantaneousReward : public AbstractPathFormula<T> {
public:
/*!
@ -84,9 +105,9 @@ public:
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new BoundedUntil-object that is identical the called object.
* @returns a new InstantaneousReward-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
return new InstantaneousReward(bound);
}
@ -100,8 +121,20 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkInstantaneousReward(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IInstantaneousRewardModelChecker>()->checkInstantaneousReward(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* As InstantaneousReward formulas have no subformulas, we return true here.
*
* @param checker Formula checker object.
* @return true
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return true;
}
private:

59
src/formula/Next.h

@ -8,18 +8,39 @@
#ifndef STORM_FORMULA_NEXT_H_
#define STORM_FORMULA_NEXT_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class Next;
/*!
* @brief Interface class for model checkers that support Next.
*
* All model checkers that support the formula class Next must inherit
* this pure virtual class.
*/
template <class T>
class INextModelChecker {
public:
/*!
* @brief Evaluates Next formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkNext(const Next<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with a Next node as root.
* Class for a Abstract (path) formula tree with a Next node as root.
*
* Has two PCTL state formulas as sub formulas/trees.
* Has two Abstract state formulas as sub formulas/trees.
*
* @par Semantics
* The formula holds iff in the next step, \e child holds
@ -27,11 +48,11 @@ namespace formula {
* The subtree is seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class Next : public PctlPathFormula<T> {
class Next : public AbstractPathFormula<T> {
public:
/*!
@ -46,7 +67,7 @@ public:
*
* @param child The child node
*/
Next(PctlStateFormula<T>* child) {
Next(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -65,7 +86,7 @@ public:
/*!
* @returns the child node
*/
const PctlStateFormula<T>& getChild() const {
const AbstractStateFormula<T>& getChild() const {
return *child;
}
@ -73,7 +94,7 @@ public:
* Sets the subtree
* @param child the new child node
*/
void setChild(PctlStateFormula<T>* child) {
void setChild(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -95,7 +116,7 @@ public:
*
* @returns a new BoundedUntil-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
Next<T>* result = new Next<T>();
if (child != NULL) {
result->setChild(child);
@ -112,12 +133,22 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkNext(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<INextModelChecker>()->checkNext(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->child);
}
private:
PctlStateFormula<T>* child;
AbstractStateFormula<T>* child;
};
} //namespace formula

63
src/formula/NoBoundOperator.h

@ -8,26 +8,47 @@
#ifndef STORM_FORMULA_NOBOUNDOPERATOR_H_
#define STORM_FORMULA_NOBOUNDOPERATOR_H_
#include "PctlFormula.h"
#include "PctlPathFormula.h"
#include "AbstractFormula.h"
#include "AbstractPathFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class NoBoundOperator;
/*!
* @brief Interface class for model checkers that support NoBoundOperator.
*
* All model checkers that support the formula class NoBoundOperator must inherit
* this pure virtual class.
*/
template <class T>
class INoBoundOperatorModelChecker {
public:
/*!
* @brief Evaluates NoBoundOperator formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkNoBoundOperator(const NoBoundOperator<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL formula tree with a P (probablistic) operator without declaration of probabilities
* Class for a Abstract formula tree with a P (probablistic) operator without declaration of probabilities
* as root.
*
* Checking a formula with this operator as root returns the probabilities that the path formula holds
* (for each state)
*
* Has one PCTL path formula as sub formula/tree.
* Has one Abstract path formula as sub formula/tree.
*
* @note
* This class is a hybrid of a state and path formula, and may only appear as the outermost operator.
* Hence, it is seen as neither a state nor a path formula, but is directly derived from PctlFormula.
* Hence, it is seen as neither a state nor a path formula, but is directly derived from AbstractFormula.
*
* @note
* This class does not contain a check() method like the other formula classes.
@ -39,14 +60,14 @@ namespace formula {
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PctlStateFormula
* @see PctlPathFormula
* @see AbstractStateFormula
* @see AbstractPathFormula
* @see ProbabilisticOperator
* @see ProbabilisticIntervalOperator
* @see PctlFormula
* @see AbstractFormula
*/
template <class T>
class NoBoundOperator: public storm::formula::PctlFormula<T> {
class NoBoundOperator: public storm::formula::AbstractFormula<T> {
public:
/*!
* Empty constructor
@ -60,7 +81,7 @@ public:
*
* @param pathFormula The child node.
*/
NoBoundOperator(PctlPathFormula<T>* pathFormula) {
NoBoundOperator(AbstractPathFormula<T>* pathFormula) {
this->pathFormula = pathFormula;
}
@ -74,9 +95,9 @@ public:
}
/*!
* @returns the child node (representation of a PCTL path formula)
* @returns the child node (representation of a Abstract path formula)
*/
const PctlPathFormula<T>& getPathFormula () const {
const AbstractPathFormula<T>& getPathFormula () const {
return *pathFormula;
}
@ -85,7 +106,7 @@ public:
*
* @param pathFormula the path formula that becomes the new child node
*/
void setPathFormula(PctlPathFormula<T>* pathFormula) {
void setPathFormula(AbstractPathFormula<T>* pathFormula) {
this->pathFormula = pathFormula;
}
@ -100,17 +121,27 @@ public:
*
* @returns A vector indicating all states that satisfy the formula represented by the called object.
*/
virtual std::vector<T>* check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkNoBoundOperator(*this);
virtual std::vector<T>* check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<INoBoundOperatorModelChecker>()->checkNoBoundOperator(*this);
}
/*!
* @returns a string representation of the formula
*/
virtual std::string toString() const = 0;
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->pathFormula);
}
private:
PctlPathFormula<T>* pathFormula;
AbstractPathFormula<T>* pathFormula;
};
} /* namespace formula */

58
src/formula/Not.h

@ -8,26 +8,48 @@
#ifndef STORM_FORMULA_NOT_H_
#define STORM_FORMULA_NOT_H_
#include "PctlStateFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "src/modelChecker/AbstractModelChecker.h"
namespace storm {
namespace formula {
template <class T> class Not;
/*!
* @brief Interface class for model checkers that support Not.
*
* All model checkers that support the formula class Not must inherit
* this pure virtual class.
*/
template <class T>
class INotModelChecker {
public:
/*!
* @brief Evaluates Not formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual storm::storage::BitVector* checkNot(const Not<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL formula tree with NOT node as root.
* Class for a Abstract formula tree with NOT node as root.
*
* Has one PCTL state formula as sub formula/tree.
* Has one Abstract state formula as sub formula/tree.
*
* The subtree is seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlStateFormula
* @see PctlFormula
* @see AbstractStateFormula
* @see AbstractFormula
*/
template <class T>
class Not : public PctlStateFormula<T> {
class Not : public AbstractStateFormula<T> {
public:
/*!
@ -41,7 +63,7 @@ public:
* Constructor
* @param child The child node
*/
Not(PctlStateFormula<T>* child) {
Not(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -60,7 +82,7 @@ public:
/*!
* @returns The child node
*/
const PctlStateFormula<T>& getChild() const {
const AbstractStateFormula<T>& getChild() const {
return *child;
}
@ -68,7 +90,7 @@ public:
* Sets the subtree
* @param child the new child node
*/
void setChild(PctlStateFormula<T>* child) {
void setChild(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -88,7 +110,7 @@ public:
*
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const {
virtual AbstractStateFormula<T>* clone() const {
Not<T>* result = new Not<T>();
if (child != NULL) {
result->setChild(child);
@ -105,12 +127,22 @@ public:
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual storm::storage::BitVector *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkNot(*this);
virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<INotModelChecker>()->checkNot(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->child);
}
private:
PctlStateFormula<T>* child;
AbstractStateFormula<T>* child;
};
} //namespace formula

66
src/formula/Or.h

@ -8,17 +8,37 @@
#ifndef STORM_FORMULA_OR_H_
#define STORM_FORMULA_OR_H_
#include "PctlStateFormula.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class Or;
/*!
* @brief Interface class for model checkers that support Or.
*
* All model checkers that support the formula class Or must inherit
* this pure virtual class.
*/
template <class T>
class IOrModelChecker {
public:
/*!
* @brief Evaluates Or formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual storm::storage::BitVector* checkOr(const Or<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL formula tree with OR node as root.
* Class for a Abstract formula tree with OR node as root.
*
* Has two PCTL state formulas as sub formulas/trees.
* Has two Abstract state formulas as sub formulas/trees.
*
* As OR is commutative, the order is \e theoretically not important, but will influence the order in which
* the model checker works.
@ -26,11 +46,11 @@ namespace formula {
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlStateFormula
* @see PctlFormula
* @see AbstractStateFormula
* @see AbstractFormula
*/
template <class T>
class Or : public PctlStateFormula<T> {
class Or : public AbstractStateFormula<T> {
public:
/*!
@ -49,7 +69,7 @@ public:
* @param left The left sub formula
* @param right The right sub formula
*/
Or(PctlStateFormula<T>* left, PctlStateFormula<T>* right) {
Or(AbstractStateFormula<T>* left, AbstractStateFormula<T>* right) {
this->left = left;
this->right = right;
}
@ -74,7 +94,7 @@ public:
*
* @param newLeft the new left child.
*/
void setLeft(PctlStateFormula<T>* newLeft) {
void setLeft(AbstractStateFormula<T>* newLeft) {
left = newLeft;
}
@ -83,21 +103,21 @@ public:
*
* @param newRight the new right child.
*/
void setRight(PctlStateFormula<T>* newRight) {
void setRight(AbstractStateFormula<T>* newRight) {
right = newRight;
}
/*!
* @returns a pointer to the left child node
*/
const PctlStateFormula<T>& getLeft() const {
const AbstractStateFormula<T>& getLeft() const {
return *left;
}
/*!
* @returns a pointer to the right child node
*/
const PctlStateFormula<T>& getRight() const {
const AbstractStateFormula<T>& getRight() const {
return *right;
}
@ -120,7 +140,7 @@ public:
*
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const {
virtual AbstractStateFormula<T>* clone() const {
Or<T>* result = new Or();
if (this->left != NULL) {
result->setLeft(left->clone());
@ -130,7 +150,7 @@ public:
}
return result;
}
/*!
* Calls the model checker to check this formula.
* Needed to infer the correct type of formula class.
@ -140,13 +160,23 @@ public:
*
* @returns A bit vector indicating all states that satisfy the formula represented by the called object.
*/
virtual storm::storage::BitVector *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkOr(*this);
virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IOrModelChecker>()->checkOr(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* @param checker Formula checker object.
* @return true iff all subtrees conform to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->left) && checker.conforms(this->right);
}
private:
PctlStateFormula<T>* left;
PctlStateFormula<T>* right;
AbstractStateFormula<T>* left;
AbstractStateFormula<T>* right;
};
} //namespace formula

48
src/formula/PctlFormula.h

@ -1,48 +0,0 @@
/*
* Pctlformula.h
*
* Created on: 19.10.2012
* Author: Thomas Heinemann
*/
#ifndef STORM_FORMULA_PCTLFORMULA_H_
#define STORM_FORMULA_PCTLFORMULA_H_
#include <string>
namespace storm {
namespace formula {
//abstract
/*!
* @brief
* Abstract base class for PCTL formulas in general.
*
* @attention This class is abstract.
* @note Formula classes do not have copy constructors. The parameters of the constructors are usually the subtrees, so
* the syntax conflicts with copy constructors for unary operators. To produce an identical object, the classes
* PctlPathFormula and PctlStateFormula offer the method clone().
*/
template <class T>
class PctlFormula {
public:
/*!
* virtual destructor
*/
virtual ~PctlFormula() { }
/*!
* @note This function is not implemented in this class.
* @returns a string representation of the formula
*/
virtual std::string toString() const = 0;
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_PCTLFORMULA_H_ */

46
src/formula/PrctlFormulaChecker.h

@ -0,0 +1,46 @@
#ifndef STORM_FORMULA_PRCTLFORMULACHECKER_H_
#define STORM_FORMULA_PRCTLFORMULACHECKER_H_
#include "src/formula/AbstractFormulaChecker.h"
#include "src/formula/Formulas.h"
#include <iostream>
namespace storm {
namespace formula {
/*!
* @brief Checks formulas if they are within PRCTL.
*
* This class implements AbstractFormulaChecker to check if a given formula
* is part of PRCTL logic.
*/
template <class T>
class PrctlFormulaChecker : public AbstractFormulaChecker<T> {
public:
/*!
* Implementation of AbstractFormulaChecker::conforms() using code
* looking exactly like the sample code given there.
*
* We currently allow And, Ap, Eventually, Not, Or,
* ProbabilisticNoBoundOperator.
*/
virtual bool conforms(const AbstractFormula<T>* formula) const {
if (
dynamic_cast<const And<T>*>(formula) ||
dynamic_cast<const Ap<T>*>(formula) ||
dynamic_cast<const Eventually<T>*>(formula) ||
dynamic_cast<const Not<T>*>(formula) ||
dynamic_cast<const Or<T>*>(formula) ||
dynamic_cast<const ProbabilisticNoBoundOperator<T>*>(formula)
) {
return formula->conforms(*this);
}
return false;
}
};
} // namespace formula
} // namespace storm
#endif

22
src/formula/ProbabilisticBoundOperator.h

@ -8,21 +8,20 @@
#ifndef STORM_FORMULA_PROBABILISTICBOUNDOPERATOR_H_
#define STORM_FORMULA_PROBABILISTICBOUNDOPERATOR_H_
#include "PctlStateFormula.h"
#include "PctlPathFormula.h"
#include "AbstractStateFormula.h"
#include "AbstractPathFormula.h"
#include "BoundOperator.h"
#include "utility/ConstTemplates.h"
namespace storm {
namespace formula {
/*!
* @brief
* Class for a PCTL formula tree with a P (probablistic) operator node over a probability interval
* Class for a Abstract formula tree with a P (probablistic) operator node over a probability interval
* as root.
*
* Has one PCTL path formula as sub formula/tree.
* Has one Abstract path formula as sub formula/tree.
*
* @par Semantics
* The formula holds iff the probability that the path formula holds is inside the bounds
@ -32,11 +31,11 @@ namespace formula {
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PctlStateFormula
* @see PctlPathFormula
* @see AbstractStateFormula
* @see AbstractPathFormula
* @see ProbabilisticOperator
* @see ProbabilisticNoBoundsOperator
* @see PctlFormula
* @see AbstractFormula
*/
template<class T>
class ProbabilisticBoundOperator : public BoundOperator<T> {
@ -45,10 +44,12 @@ public:
/*!
* Empty constructor
*/
//! TODO: this constructor should give a comparisontype as first argument
ProbabilisticBoundOperator() : BoundOperator<T>(storm::utility::constGetZero<T>(), storm::utility::constGetZero<T>(), nullptr) {
// Intentionally left empty
}
/*!
* Constructor
*
@ -56,7 +57,7 @@ public:
* @param upperBound The upper bound for the probability
* @param pathFormula The child node
*/
ProbabilisticBoundOperator(T lowerBound, T upperBound, PctlPathFormula<T>& pathFormula) : BoundOperator<T>(lowerBound, upperBound, pathFormula) {
ProbabilisticBoundOperator(T lowerBound, T upperBound, AbstractPathFormula<T>& pathFormula) : BoundOperator<T>(lowerBound, upperBound, pathFormula) {
// Intentionally left empty
}
@ -81,7 +82,7 @@ public:
*
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const {
virtual AbstractStateFormula<T>* clone() const {
ProbabilisticBoundOperator<T>* result = new ProbabilisticBoundOperator<T>();
result->setInterval(this->getLowerBound(), this->getUpperBound());
result->setPathFormula(this->getPathFormula()->clone());
@ -90,7 +91,6 @@ public:
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_PROBABILISTICBOUNDOPERATOR_H_ */

20
src/formula/ProbabilisticNoBoundOperator.h

@ -8,27 +8,26 @@
#ifndef STORM_FORMULA_PROBABILISTICNOBOUNDOPERATOR_H_
#define STORM_FORMULA_PROBABILISTICNOBOUNDOPERATOR_H_
#include "PctlFormula.h"
#include "PctlPathFormula.h"
#include "AbstractFormula.h"
#include "AbstractPathFormula.h"
#include "NoBoundOperator.h"
namespace storm {
namespace formula {
/*!
* @brief
* Class for a PCTL formula tree with a P (probablistic) operator without declaration of probabilities
* Class for a Abstract formula tree with a P (probablistic) operator without declaration of probabilities
* as root.
*
* Checking a formula with this operator as root returns the probabilities that the path formula holds
* (for each state)
*
* Has one PCTL path formula as sub formula/tree.
* Has one Abstract path formula as sub formula/tree.
*
* @note
* This class is a hybrid of a state and path formula, and may only appear as the outermost operator.
* Hence, it is seen as neither a state nor a path formula, but is directly derived from PctlFormula.
* Hence, it is seen as neither a state nor a path formula, but is directly derived from AbstractFormula.
*
* @note
* This class does not contain a check() method like the other formula classes.
@ -40,11 +39,11 @@ namespace formula {
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PctlStateFormula
* @see PctlPathFormula
* @see AbstractStateFormula
* @see AbstractPathFormula
* @see ProbabilisticOperator
* @see ProbabilisticIntervalOperator
* @see PctlFormula
* @see AbstractFormula
*/
template <class T>
class ProbabilisticNoBoundOperator: public NoBoundOperator<T> {
@ -61,7 +60,7 @@ public:
*
* @param pathFormula The child node.
*/
ProbabilisticNoBoundOperator(PctlPathFormula<T>* pathFormula) : NoBoundOperator<T>(pathFormula) {
ProbabilisticNoBoundOperator(AbstractPathFormula<T>* pathFormula) : NoBoundOperator<T>(pathFormula) {
// Intentionally left empty
}
@ -77,7 +76,6 @@ public:
};
} /* namespace formula */
} /* namespace storm */
#endif /* STORM_FORMULA_PROBABILISTICNOBOUNDOPERATOR_H_ */

64
src/formula/ReachabilityReward.h

@ -8,27 +8,48 @@
#ifndef STORM_FORMULA_REACHABILITYREWARD_H_
#define STORM_FORMULA_REACHABILITYREWARD_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "src/formula/AbstractPathFormula.h"
#include "src/formula/AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
#include "src/modelChecker/AbstractModelChecker.h"
namespace storm {
namespace formula {
template <class T> class ReachabilityReward;
/*!
* @brief Interface class for model checkers that support ReachabilityReward.
*
* All model checkers that support the formula class ReachabilityReward must inherit
* this pure virtual class.
*/
template <class T>
class IReachabilityRewardModelChecker {
public:
/*!
* @brief Evaluates ReachabilityReward formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkReachabilityReward(const ReachabilityReward<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with an Reachability Reward node as root.
* Class for a Abstract (path) formula tree with an Reachability Reward node as root.
*
* Has one PCTL state formula as sub formula/tree.
* Has one Abstract state formula as sub formula/tree.
*
* The subtree is seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to nullptr before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class ReachabilityReward : public PctlPathFormula<T> {
class ReachabilityReward : public AbstractPathFormula<T> {
public:
/*!
@ -43,7 +64,7 @@ public:
*
* @param child The child node
*/
ReachabilityReward(PctlStateFormula<T>* child) {
ReachabilityReward(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -62,7 +83,7 @@ public:
/*!
* @returns the child node
*/
const PctlStateFormula<T>& getChild() const {
const AbstractStateFormula<T>& getChild() const {
return *child;
}
@ -70,7 +91,7 @@ public:
* Sets the subtree
* @param child the new child node
*/
void setChild(PctlStateFormula<T>* child) {
void setChild(AbstractStateFormula<T>* child) {
this->child = child;
}
@ -88,9 +109,9 @@ public:
*
* Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
*
* @returns a new BoundedUntil-object that is identical the called object.
* @returns a new ReachabilityReward-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
ReachabilityReward<T>* result = new ReachabilityReward<T>();
if (child != nullptr) {
result->setChild(child);
@ -107,16 +128,25 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkReachabilityReward(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IReachabilityRewardModelChecker>()->checkReachabilityReward(*this);
}
/*!
* @brief Checks if the subtree conforms to some logic.
*
* @param checker Formula checker object.
* @return true iff the subtree conforms to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->child);
}
private:
PctlStateFormula<T>* child;
AbstractStateFormula<T>* child;
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_REACHABILITYREWARD_H_ */

19
src/formula/RewardBoundOperator.h

@ -8,18 +8,17 @@
#ifndef STORM_FORMULA_REWARDBOUNDOPERATOR_H_
#define STORM_FORMULA_REWARDBOUNDOPERATOR_H_
#include "PctlStateFormula.h"
#include "PctlPathFormula.h"
#include "AbstractStateFormula.h"
#include "AbstractPathFormula.h"
#include "BoundOperator.h"
#include "utility/ConstTemplates.h"
namespace storm {
namespace formula {
/*!
* @brief
* Class for a PCTL formula tree with a R (reward) operator node over a reward interval as root.
* Class for a Abstract formula tree with a R (reward) operator node over a reward interval as root.
*
* Has a reward path formula as sub formula/tree.
*
@ -31,11 +30,11 @@ namespace formula {
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PctlStateFormula
* @see PctlPathFormula
* @see AbstractStateFormula
* @see AbstractPathFormula
* @see ProbabilisticOperator
* @see ProbabilisticNoBoundsOperator
* @see PctlFormula
* @see AbstractFormula
*/
template<class T>
class RewardBoundOperator : public BoundOperator<T> {
@ -44,6 +43,7 @@ public:
/*!
* Empty constructor
*/
//! TODO: this constructor should give a comparisontype as first argument
RewardBoundOperator() : BoundOperator<T>(storm::utility::constGetZero<T>(), storm::utility::constGetZero<T>(), nullptr) {
// Intentionally left empty
}
@ -55,7 +55,7 @@ public:
* @param upperBound The upper bound for the probability
* @param pathFormula The child node
*/
RewardBoundOperator(T lowerBound, T upperBound, PctlPathFormula<T>& pathFormula) : BoundOperator<T>(lowerBound, upperBound, pathFormula) {
RewardBoundOperator(T lowerBound, T upperBound, AbstractPathFormula<T>& pathFormula) : BoundOperator<T>(lowerBound, upperBound, pathFormula) {
// Intentionally left empty
}
@ -80,7 +80,7 @@ public:
*
* @returns a new AND-object that is identical the called object.
*/
virtual PctlStateFormula<T>* clone() const {
virtual AbstractStateFormula<T>* clone() const {
RewardBoundOperator<T>* result = new RewardBoundOperator<T>();
result->setBound(this->getLowerBound(), this->getUpperBound());
result->setPathFormula(this->getPathFormula()->clone());
@ -89,7 +89,6 @@ public:
};
} //namespace formula
} //namespace storm
#endif /* STORM_FORMULA_REWARDBOUNDOPERATOR_H_ */

20
src/formula/RewardNoBoundOperator.h

@ -8,27 +8,26 @@
#ifndef STORM_FORMULA_REWARDNOBOUNDOPERATOR_H_
#define STORM_FORMULA_REWARDNOBOUNDOPERATOR_H_
#include "PctlFormula.h"
#include "PctlPathFormula.h"
#include "AbstractFormula.h"
#include "AbstractPathFormula.h"
#include "NoBoundOperator.h"
namespace storm {
namespace formula {
/*!
* @brief
* Class for a PCTL formula tree with a R (reward) operator without declaration of reward values
* Class for a Abstract formula tree with a R (reward) operator without declaration of reward values
* as root.
*
* Checking a formula with this operator as root returns the reward for the reward path formula for
* each state
*
* Has one PCTL path formula as sub formula/tree.
* Has one Abstract path formula as sub formula/tree.
*
* @note
* This class is a hybrid of a state and path formula, and may only appear as the outermost operator.
* Hence, it is seen as neither a state nor a path formula, but is directly derived from PctlFormula.
* Hence, it is seen as neither a state nor a path formula, but is directly derived from AbstractFormula.
*
* @note
* This class does not contain a check() method like the other formula classes.
@ -40,11 +39,11 @@ namespace formula {
* (this behavior can be prevented by setting them to NULL before deletion)
*
*
* @see PctlStateFormula
* @see PctlPathFormula
* @see AbstractStateFormula
* @see AbstractPathFormula
* @see ProbabilisticOperator
* @see ProbabilisticIntervalOperator
* @see PctlFormula
* @see AbstractFormula
*/
template <class T>
class RewardNoBoundOperator: public NoBoundOperator<T> {
@ -61,7 +60,7 @@ public:
*
* @param pathFormula The child node.
*/
RewardNoBoundOperator(PctlPathFormula<T>* pathFormula) : NoBoundOperator<T>(pathFormula) {
RewardNoBoundOperator(AbstractPathFormula<T>* pathFormula) : NoBoundOperator<T>(pathFormula) {
// Intentionally left empty
}
@ -77,7 +76,6 @@ public:
};
} /* namespace formula */
} /* namespace storm */
#endif /* STORM_FORMULA_REWARDNOBOUNDOPERATOR_H_ */

66
src/formula/Until.h

@ -8,18 +8,38 @@
#ifndef STORM_FORMULA_UNTIL_H_
#define STORM_FORMULA_UNTIL_H_
#include "PctlPathFormula.h"
#include "PctlStateFormula.h"
#include "AbstractPathFormula.h"
#include "AbstractStateFormula.h"
#include "src/formula/AbstractFormulaChecker.h"
namespace storm {
namespace formula {
template <class T> class Until;
/*!
* @brief Interface class for model checkers that support Until.
*
* All model checkers that support the formula class Until must inherit
* this pure virtual class.
*/
template <class T>
class IUntilModelChecker {
public:
/*!
* @brief Evaluates Until formula within a model checker.
*
* @param obj Formula object with subformulas.
* @return Result of the formula for every node.
*/
virtual std::vector<T>* checkUntil(const Until<T>& obj) const = 0;
};
/*!
* @brief
* Class for a PCTL (path) formula tree with an Until node as root.
* Class for a Abstract (path) formula tree with an Until node as root.
*
* Has two PCTL state formulas as sub formulas/trees.
* Has two Abstract state formulas as sub formulas/trees.
*
* @par Semantics
* The formula holds iff eventually, formula \e right (the right subtree) holds, and before,
@ -28,11 +48,11 @@ namespace formula {
* The subtrees are seen as part of the object and deleted with the object
* (this behavior can be prevented by setting them to NULL before deletion)
*
* @see PctlPathFormula
* @see PctlFormula
* @see AbstractPathFormula
* @see AbstractFormula
*/
template <class T>
class Until : public PctlPathFormula<T> {
class Until : public AbstractPathFormula<T> {
public:
/*!
@ -49,7 +69,7 @@ public:
* @param left The left formula subtree
* @param right The left formula subtree
*/
Until(PctlStateFormula<T>* left, PctlStateFormula<T>* right) {
Until(AbstractStateFormula<T>* left, AbstractStateFormula<T>* right) {
this->left = left;
this->right = right;
}
@ -74,7 +94,7 @@ public:
*
* @param newLeft the new left child.
*/
void setLeft(PctlStateFormula<T>* newLeft) {
void setLeft(AbstractStateFormula<T>* newLeft) {
left = newLeft;
}
@ -83,21 +103,21 @@ public:
*
* @param newRight the new right child.
*/
void setRight(PctlStateFormula<T>* newRight) {
void setRight(AbstractStateFormula<T>* newRight) {
right = newRight;
}
/*!
* @returns a pointer to the left child node
*/
const PctlStateFormula<T>& getLeft() const {
const AbstractStateFormula<T>& getLeft() const {
return *left;
}
/*!
* @returns a pointer to the right child node
*/
const PctlStateFormula<T>& getRight() const {
const AbstractStateFormula<T>& getRight() const {
return *right;
}
@ -120,7 +140,7 @@ public:
*
* @returns a new BoundedUntil-object that is identical the called object.
*/
virtual PctlPathFormula<T>* clone() const {
virtual AbstractPathFormula<T>* clone() const {
Until<T>* result = new Until();
if (left != NULL) {
result->setLeft(left->clone());
@ -140,13 +160,23 @@ public:
*
* @returns A vector indicating the probability that the formula holds for each state.
*/
virtual std::vector<T> *check(const storm::modelChecker::DtmcPrctlModelChecker<T>& modelChecker) const {
return modelChecker.checkUntil(*this);
virtual std::vector<T> *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
return modelChecker.template as<IUntilModelChecker>()->checkUntil(*this);
}
/*!
* @brief Checks if all subtrees conform to some logic.
*
* @param checker Formula checker object.
* @return true iff all subtrees conform to some logic.
*/
virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
return checker.conforms(this->left) && checker.conforms(this->right);
}
private:
PctlStateFormula<T>* left;
PctlStateFormula<T>* right;
AbstractStateFormula<T>* left;
AbstractStateFormula<T>* right;
};
} //namespace formula

57
src/modelChecker/AbstractModelChecker.h

@ -0,0 +1,57 @@
/*
* DtmcPrctlModelChecker.h
*
* Created on: 22.10.2012
* Author: Thomas Heinemann
*/
#ifndef STORM_MODELCHECKER_ABSTRACTMODELCHECKER_H_
#define STORM_MODELCHECKER_ABSTRACTMODELCHECKER_H_
namespace storm { namespace modelChecker {
template <class Type> class AbstractModelChecker;
}}
//#include "src/formula/Formulas.h"
#include "src/formula/Or.h"
#include "src/formula/Ap.h"
#include "src/storage/BitVector.h"
#include <iostream>
namespace storm {
namespace modelChecker {
/*!
* @brief
* Interface for model checker classes.
*
* This class provides basic functions that are the same for all subclasses, but mainly only declares
* abstract methods that are to be implemented in concrete instances.
*
* @attention This class is abstract.
*/
template<class Type>
class AbstractModelChecker :
public virtual storm::formula::IOrModelChecker<Type>,
public virtual storm::formula::IApModelChecker<Type>
{
public:
template <template <class T> class Target>
const Target<Type>* as() const {
try {
const Target<Type>* target = dynamic_cast<const Target<Type>*>(this);
return target;
} catch (std::bad_cast& bc) {
std::cerr << "Bad cast: tried to cast " << typeid(*this).name() << " to " << typeid(Target<Type>).name() << std::endl;
}
return nullptr;
}
};
} //namespace modelChecker
} //namespace storm
#endif /* STORM_MODELCHECKER_DTMCPRCTLMODELCHECKER_H_ */

19
src/modelChecker/DtmcPrctlModelChecker.h

@ -23,15 +23,13 @@ class DtmcPrctlModelChecker;
}
#include "src/formula/PctlPathFormula.h"
#include "src/formula/PctlStateFormula.h"
#include "src/formula/Formulas.h"
#include "src/models/Dtmc.h"
#include "src/storage/BitVector.h"
#include "src/exceptions/InvalidPropertyException.h"
#include "src/utility/Vector.h"
#include "src/modelChecker/AbstractModelChecker.h"
#include <vector>
#include "log4cplus/logger.h"
@ -53,7 +51,12 @@ namespace modelChecker {
* @attention This class is abstract.
*/
template<class Type>
class DtmcPrctlModelChecker {
class DtmcPrctlModelChecker :
public virtual AbstractModelChecker<Type>,
public virtual storm::formula::INoBoundOperatorModelChecker<Type>,
public virtual storm::formula::IReachabilityRewardModelChecker<Type>,
public virtual storm::formula::IEventuallyModelChecker<Type>
{
public:
/*!
* Constructor
@ -100,7 +103,7 @@ public:
* states.
* @param stateFormula The formula to be checked.
*/
void check(const storm::formula::PctlStateFormula<Type>& stateFormula) const {
void check(const storm::formula::AbstractStateFormula<Type>& stateFormula) const {
std::cout << std::endl;
LOG4CPLUS_INFO(logger, "Model checking formula\t" << stateFormula.toString());
std::cout << "Model checking formula:\t" << stateFormula.toString() << std::endl;
@ -160,7 +163,7 @@ public:
* @param formula The state formula to check
* @returns The set of states satisfying the formula, represented by a bit vector
*/
storm::storage::BitVector* checkStateFormula(const storm::formula::PctlStateFormula<Type>& formula) const {
storm::storage::BitVector* checkStateFormula(const storm::formula::AbstractStateFormula<Type>& formula) const {
return formula.check(*this);
}
@ -216,7 +219,7 @@ public:
* @param formula The Or state formula to check
* @returns The set of states satisfying the formula, represented by a bit vector
*/
storm::storage::BitVector* checkOr(const storm::formula::Or<Type>& formula) const {
virtual storm::storage::BitVector* checkOr(const storm::formula::Or<Type>& formula) const {
storm::storage::BitVector* result = checkStateFormula(formula.getLeft());
storm::storage::BitVector* right = checkStateFormula(formula.getRight());
(*result) |= (*right);
@ -269,7 +272,7 @@ public:
* @param formula The path formula to check
* @returns for each state the probability that the path formula holds.
*/
std::vector<Type>* checkPathFormula(const storm::formula::PctlPathFormula<Type>& formula) const {
std::vector<Type>* checkPathFormula(const storm::formula::AbstractPathFormula<Type>& formula) const {
return formula.check(*this);
}

2
src/parser/NonDeterministicSparseTransitionParser.h

@ -13,6 +13,8 @@
namespace storm {
namespace parser {
typedef boost::bimap<uint_fast64_t, std::pair<uint_fast64_t,std::string>> RowStateMapping;
/*!
* @brief Load a nondeterministic transition system from file and create a
* sparse adjacency matrix whose entries represent the weights of the edges

6
src/parser/PrctlParser.cpp

@ -58,7 +58,7 @@ namespace
/*!
* @brief Resulting formula.
*/
storm::formula::PctlFormula<double>* result;
//storm::formula::PctlFormula<double>* result;
struct dump
{
@ -141,7 +141,7 @@ storm::parser::PrctlParser::PrctlParser(const char* filename)
std::cout << "File was parsed" << std::endl;
std::string rest(data, file.dataend);
std::cout << "Rest: " << rest << std::endl;
this->formula = p.result;
//this->formula = p.result;
}
else this->formula = NULL;
//else this->formula = NULL;
}

5
src/parser/PrctlParser.h

@ -1,7 +1,7 @@
#ifndef STORM_PARSER_PRCTLPARSER_H_
#define STORM_PARSER_PRCTLPARSER_H_
#include "src/formula/PctlFormula.h"
// #include "src/formula/PctlFormula.h"
#include "src/parser/Parser.h"
namespace storm {
@ -18,13 +18,14 @@ class PrctlParser : Parser
/*!
* @brief return formula object parsed from file.
*/
storm::formula::PctlFormula<double>* getFormula()
/* storm::formula::PctlFormula<double>* getFormula()
{
return this->formula;
}
private:
storm::formula::PctlFormula<double>* formula;
*/
};
} // namespace parser
Loading…
Cancel
Save