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.

152 lines
3.4 KiB

  1. /*
  2. * Not.h
  3. *
  4. * Created on: 19.10.2012
  5. * Author: Thomas Heinemann
  6. */
  7. #ifndef STORM_FORMULA_NOT_H_
  8. #define STORM_FORMULA_NOT_H_
  9. #include "AbstractStateFormula.h"
  10. #include "src/formula/AbstractFormulaChecker.h"
  11. #include "src/modelchecker/ForwardDeclarations.h"
  12. namespace storm {
  13. namespace formula {
  14. template <class T> class Not;
  15. /*!
  16. * @brief Interface class for model checkers that support Not.
  17. *
  18. * All model checkers that support the formula class Not must inherit
  19. * this pure virtual class.
  20. */
  21. template <class T>
  22. class INotModelChecker {
  23. public:
  24. /*!
  25. * @brief Evaluates Not formula within a model checker.
  26. *
  27. * @param obj Formula object with subformulas.
  28. * @return Result of the formula for every node.
  29. */
  30. virtual storm::storage::BitVector* checkNot(const Not<T>& obj) const = 0;
  31. };
  32. /*!
  33. * @brief
  34. * Class for a Abstract formula tree with NOT node as root.
  35. *
  36. * Has one Abstract state formula as sub formula/tree.
  37. *
  38. * The subtree is seen as part of the object and deleted with the object
  39. * (this behavior can be prevented by setting them to NULL before deletion)
  40. *
  41. * @see AbstractStateFormula
  42. * @see AbstractFormula
  43. */
  44. template <class T>
  45. class Not : public AbstractStateFormula<T> {
  46. public:
  47. /*!
  48. * Empty constructor
  49. */
  50. Not() {
  51. this->child = NULL;
  52. }
  53. /*!
  54. * Constructor
  55. * @param child The child node
  56. */
  57. Not(AbstractStateFormula<T>* child) {
  58. this->child = child;
  59. }
  60. /*!
  61. * Destructor
  62. *
  63. * Also deletes the subtree
  64. * (this behavior can be prevented by setting them to NULL before deletion)
  65. */
  66. virtual ~Not() {
  67. if (child != NULL) {
  68. delete child;
  69. }
  70. }
  71. /*!
  72. * @returns The child node
  73. */
  74. const AbstractStateFormula<T>& getChild() const {
  75. return *child;
  76. }
  77. /*!
  78. * Sets the subtree
  79. * @param child the new child node
  80. */
  81. void setChild(AbstractStateFormula<T>* child) {
  82. this->child = child;
  83. }
  84. /*!
  85. * @returns a string representation of the formula
  86. */
  87. virtual std::string toString() const {
  88. std::string result = "!";
  89. result += child->toString();
  90. return result;
  91. }
  92. /*!
  93. * Clones the called object.
  94. *
  95. * Performs a "deep copy", i.e. the subtrees of the new object are clones of the original ones
  96. *
  97. * @returns a new AND-object that is identical the called object.
  98. */
  99. virtual AbstractStateFormula<T>* clone() const {
  100. Not<T>* result = new Not<T>();
  101. if (child != NULL) {
  102. result->setChild(child);
  103. }
  104. return result;
  105. }
  106. /*!
  107. * Calls the model checker to check this formula.
  108. * Needed to infer the correct type of formula class.
  109. *
  110. * @note This function should only be called in a generic check function of a model checker class. For other uses,
  111. * the methods of the model checker should be used.
  112. *
  113. * @returns A bit vector indicating all states that satisfy the formula represented by the called object.
  114. */
  115. virtual storm::storage::BitVector *check(const storm::modelChecker::AbstractModelChecker<T>& modelChecker) const {
  116. return modelChecker.template as<INotModelChecker>()->checkNot(*this);
  117. }
  118. /*!
  119. * @brief Checks if the subtree conforms to some logic.
  120. *
  121. * @param checker Formula checker object.
  122. * @return true iff the subtree conforms to some logic.
  123. */
  124. virtual bool conforms(const AbstractFormulaChecker<T>& checker) const {
  125. return checker.conforms(this->child);
  126. }
  127. private:
  128. AbstractStateFormula<T>* child;
  129. };
  130. } //namespace formula
  131. } //namespace storm
  132. #endif /* STORM_FORMULA_NOT_H_ */