You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.6 KiB

  1. /*
  2. * BoundOperator.h
  3. *
  4. * Created on: 27.12.2012
  5. * Author: Christian Dehnert
  6. */
  7. #ifndef STORM_FORMULA_BOUNDOPERATOR_H_
  8. #define STORM_FORMULA_BOUNDOPERATOR_H_
  9. #include "src/formula/AbstractStateFormula.h"
  10. #include "src/formula/AbstractPathFormula.h"
  11. #include "src/formula/AbstractFormulaChecker.h"
  12. #include "src/modelChecker/AbstractModelChecker.h"
  13. #include "src/utility/ConstTemplates.h"
  14. namespace storm {
  15. namespace formula {
  16. template <class T> class BoundUntil;
  17. template <class T>
  18. class IBoundUntilModelChecker {
  19. public:
  20. virtual storm::storage::BitVector* checkBoundUntil(const BoundUntil<T>& obj) const = 0;
  21. };
  22. /*!
  23. * @brief
  24. * Class for a Abstract formula tree with a P (probablistic) operator node over a probability interval
  25. * as root.
  26. *
  27. * Has one Abstract path formula as sub formula/tree.
  28. *
  29. * @par Semantics
  30. * The formula holds iff the probability that the path formula holds is inside the bounds
  31. * specified in this operator
  32. *
  33. * The subtree is seen as part of the object and deleted with it
  34. * (this behavior can be prevented by setting them to NULL before deletion)
  35. *
  36. *
  37. * @see AbstractStateFormula
  38. * @see AbstractPathFormula
  39. * @see ProbabilisticOperator
  40. * @see ProbabilisticNoBoundsOperator
  41. * @see AbstractFormula
  42. */
  43. template<class T>
  44. class BoundOperator : public AbstractStateFormula<T> {
  45. public:
  46. enum ComparisonType { LESS, LESS_EQUAL, GREATER, GREATER_EQUAL };
  47. /*!
  48. * Constructor
  49. *
  50. * @param lowerBound The lower bound for the probability
  51. * @param upperBound The upper bound for the probability
  52. * @param pathFormula The child node
  53. */
  54. BoundOperator(ComparisonType comparisonOperator, T bound, AbstractPathFormula<T>* pathFormula)
  55. : comparisonOperator(comparisonOperator), bound(bound), pathFormula(pathFormula) {
  56. // Intentionally left empty
  57. }
  58. /*!
  59. * Destructor
  60. *
  61. * The subtree is deleted with the object
  62. * (this behavior can be prevented by setting them to NULL before deletion)
  63. */
  64. virtual ~BoundOperator() {
  65. if (pathFormula != nullptr) {
  66. delete pathFormula;
  67. }
  68. }
  69. /*!
  70. * @returns the child node (representation of a Abstract path formula)
  71. */
  72. const AbstractPathFormula<T>& getPathFormula () const {
  73. return *pathFormula;
  74. }
  75. /*!
  76. * Sets the child node
  77. *
  78. * @param pathFormula the path formula that becomes the new child node
  79. */
  80. void setPathFormula(AbstractPathFormula<T>* pathFormula) {
  81. this->pathFormula = pathFormula;
  82. }
  83. /*!
  84. * @returns the bound for the measure
  85. */
  86. const T& getBound() const {
  87. return bound;
  88. }
  89. /*!
  90. * Sets the interval in which the probability that the path formula holds may lie in.
  91. *
  92. * @param bound The bound for the measure
  93. */
  94. void setBound(T bound) {
  95. this->bound = bound;
  96. }
  97. /*!
  98. * @returns a string representation of the formula
  99. */
  100. virtual std::string toString() const {
  101. std::string result = "P ";
  102. switch (comparisonOperator) {
  103. case LESS: result += "<"; break;
  104. case LESS_EQUAL: result += "<="; break;
  105. case GREATER: result += ">"; break;
  106. case GREATER_EQUAL: result += ">="; break;
  107. }
  108. result += std::to_string(bound);
  109. result += " [";
  110. result += pathFormula->toString();
  111. result += "]";
  112. return result;
  113. }
  114. bool meetsBound(T value) {
  115. switch (comparisonOperator) {
  116. case LESS: return value < bound; break;
  117. case LESS_EQUAL: return value <= bound; break;
  118. case GREATER: return value > bound; break;
  119. case GREATER_EQUAL: return value >= bound; break;
  120. default: return false;
  121. }
  122. }
  123. /*!
  124. * Clones the called object.
  125. *
  126. * Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
  127. *
  128. * @returns a new AND-object that is identical the called object.
  129. */
  130. virtual AbstractStateFormula<T>* clone() const = 0;
  131. /*!
  132. * Calls the model checker to check this formula.
  133. * Needed to infer the correct type of formula class.
  134. *
  135. * @note This function should only be called in a generic check function of a model checker class. For other uses,
  136. * the methods of the model checker should be used.
  137. *
  138. * @returns A bit vector indicating all states that satisfy the formula represented by the called object.
  139. */
  140. virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
  141. return modelChecker.template as<IBoundUntilModelChecker>()->checkBoundOperator(*this);
  142. }
  143. virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
  144. return checker.conforms(this->pathFormula);
  145. }
  146. private:
  147. ComparisonType comparisonOperator;
  148. T bound;
  149. AbstractPathFormula<T>* pathFormula;
  150. };
  151. } //namespace formula
  152. } //namespace storm
  153. #endif /* STORM_FORMULA_BOUNDOPERATOR_H_ */