Browse Source
(LTL) Refactor unary/boolean state formulas to allow path formulas as well
(LTL) Refactor unary/boolean state formulas to allow path formulas as well
Previously, the formula parser only supported AND, OR and NOT over state formulas. For LTL, we need those over path formulas. We tweak the grammar, the AST types and visitors, to also handle UnaryBooleanPathFormula and BinaryBooleanPathformula. During parsing, we determine on-demand whether to generate the path or state formula variant by looking at the subformulas - if they are state formulas, the boolean operator will be a state formula as well. Conflicts: src/storm-parsers/parser/FormulaParserGrammar.cpp src/storm-parsers/parser/FormulaParserGrammar.h src/storm/logic/CloneVisitor.cpp src/storm/logic/Formula.cpp src/storm/logic/Formula.h src/storm/logic/FragmentChecker.cpp src/storm/logic/FragmentSpecification.cpp src/storm/logic/FragmentSpecification.h src/storm/logic/LiftableTransitionRewardsVisitor.cpp src/storm/storage/jani/JSONExporter.cppmain
29 changed files with 351 additions and 27 deletions
-
52src/storm-parsers/parser/FormulaParserGrammar.cpp
-
16src/storm-parsers/parser/FormulaParserGrammar.h
-
7src/storm/logic/BinaryBooleanOperatorType.h
-
47src/storm/logic/BinaryBooleanPathFormula.cpp
-
38src/storm/logic/BinaryBooleanPathFormula.h
-
3src/storm/logic/BinaryBooleanStateFormula.h
-
11src/storm/logic/CloneVisitor.cpp
-
2src/storm/logic/CloneVisitor.h
-
8src/storm/logic/Formula.cpp
-
3src/storm/logic/Formula.h
-
12src/storm/logic/FormulaInformationVisitor.cpp
-
2src/storm/logic/FormulaInformationVisitor.h
-
2src/storm/logic/FormulaVisitor.h
-
2src/storm/logic/Formulas.h
-
2src/storm/logic/FormulasForwardDeclarations.h
-
15src/storm/logic/FragmentChecker.cpp
-
2src/storm/logic/FragmentChecker.h
-
19src/storm/logic/FragmentSpecification.cpp
-
8src/storm/logic/FragmentSpecification.h
-
10src/storm/logic/LiftableTransitionRewardsVisitor.cpp
-
2src/storm/logic/LiftableTransitionRewardsVisitor.h
-
10src/storm/logic/ToExpressionVisitor.cpp
-
2src/storm/logic/ToExpressionVisitor.h
-
7src/storm/logic/UnaryBooleanOperatorType.h
-
39src/storm/logic/UnaryBooleanPathFormula.cpp
-
35src/storm/logic/UnaryBooleanPathFormula.h
-
3src/storm/logic/UnaryBooleanStateFormula.h
-
17src/storm/storage/jani/JSONExporter.cpp
-
2src/storm/storage/jani/JSONExporter.h
@ -0,0 +1,7 @@ |
|||
#pragma once |
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
enum class BinaryBooleanOperatorType {And, Or}; |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
#include "storm/logic/BinaryBooleanPathFormula.h"
|
|||
|
|||
#include "storm/logic/FormulaVisitor.h"
|
|||
|
|||
#include "storm/utility/macros.h"
|
|||
#include "storm/exceptions/InvalidPropertyException.h"
|
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
BinaryBooleanPathFormula::BinaryBooleanPathFormula(OperatorType operatorType, std::shared_ptr<Formula const> const& leftSubformula, std::shared_ptr<Formula const> const& rightSubformula) : BinaryPathFormula(leftSubformula, rightSubformula), operatorType(operatorType) { |
|||
STORM_LOG_THROW(this->getLeftSubformula().isStateFormula() || this->getLeftSubformula().isPathFormula(), storm::exceptions::InvalidPropertyException, "Boolean path formula must have either path or state subformulas"); |
|||
STORM_LOG_THROW(this->getRightSubformula().isStateFormula() || this->getRightSubformula().isPathFormula(), storm::exceptions::InvalidPropertyException, "Boolean path formula must have either path or state subformulas"); |
|||
} |
|||
|
|||
bool BinaryBooleanPathFormula::isBinaryBooleanPathFormula() const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any BinaryBooleanPathFormula::accept(FormulaVisitor const& visitor, boost::any const& data) const { |
|||
return visitor.visit(*this, data); |
|||
} |
|||
|
|||
BinaryBooleanPathFormula::OperatorType BinaryBooleanPathFormula::getOperator() const { |
|||
return operatorType; |
|||
} |
|||
|
|||
bool BinaryBooleanPathFormula::isAnd() const { |
|||
return this->getOperator() == OperatorType::And; |
|||
} |
|||
|
|||
bool BinaryBooleanPathFormula::isOr() const { |
|||
return this->getOperator() == OperatorType::Or; |
|||
} |
|||
|
|||
std::ostream& BinaryBooleanPathFormula::writeToStream(std::ostream& out) const { |
|||
out << "("; |
|||
this->getLeftSubformula().writeToStream(out); |
|||
switch (operatorType) { |
|||
case OperatorType::And: out << " & "; break; |
|||
case OperatorType::Or: out << " | "; break; |
|||
} |
|||
this->getRightSubformula().writeToStream(out); |
|||
out << ")"; |
|||
return out; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,38 @@ |
|||
#ifndef STORM_LOGIC_BINARYBOOLEANPATHFORMULA_H_ |
|||
#define STORM_LOGIC_BINARYBOOLEANPATHFORMULA_H_ |
|||
|
|||
#include <map> |
|||
|
|||
#include "storm/logic/BinaryPathFormula.h" |
|||
#include "storm/logic/BinaryBooleanOperatorType.h" |
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
class BinaryBooleanPathFormula : public BinaryPathFormula { |
|||
public: |
|||
typedef storm::logic::BinaryBooleanOperatorType OperatorType; |
|||
|
|||
BinaryBooleanPathFormula(OperatorType operatorType, std::shared_ptr<Formula const> const& leftSubformula, std::shared_ptr<Formula const> const& rightSubformula); |
|||
|
|||
virtual ~BinaryBooleanPathFormula() { |
|||
// Intentionally left empty. |
|||
}; |
|||
|
|||
virtual bool isBinaryBooleanPathFormula() const override; |
|||
|
|||
virtual boost::any accept(FormulaVisitor const& visitor, boost::any const& data) const override; |
|||
|
|||
OperatorType getOperator() const; |
|||
|
|||
virtual bool isAnd() const; |
|||
virtual bool isOr() const; |
|||
|
|||
virtual std::ostream& writeToStream(std::ostream& out) const override; |
|||
|
|||
private: |
|||
OperatorType operatorType; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_LOGIC_BINARYBOOLEANPATHFORMULA_H_ */ |
@ -0,0 +1,7 @@ |
|||
#pragma once |
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
enum class UnaryBooleanOperatorType {Not}; |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
#include "storm/logic/UnaryBooleanPathFormula.h"
|
|||
|
|||
#include "storm/logic/FormulaVisitor.h"
|
|||
|
|||
#include "storm/utility/macros.h"
|
|||
#include "storm/exceptions/InvalidPropertyException.h"
|
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
UnaryBooleanPathFormula::UnaryBooleanPathFormula(OperatorType operatorType, std::shared_ptr<Formula const> const& subformula) : UnaryPathFormula(subformula), operatorType(operatorType) { |
|||
STORM_LOG_THROW(this->getSubformula().isStateFormula() || this->getSubformula().isPathFormula(), storm::exceptions::InvalidPropertyException, "Boolean path formula must have either path or state subformulas"); |
|||
} |
|||
|
|||
bool UnaryBooleanPathFormula::isUnaryBooleanPathFormula() const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any UnaryBooleanPathFormula::accept(FormulaVisitor const& visitor, boost::any const& data) const { |
|||
return visitor.visit(*this, data); |
|||
} |
|||
|
|||
UnaryBooleanPathFormula::OperatorType UnaryBooleanPathFormula::getOperator() const { |
|||
return operatorType; |
|||
} |
|||
|
|||
bool UnaryBooleanPathFormula::isNot() const { |
|||
return this->getOperator() == OperatorType::Not; |
|||
} |
|||
|
|||
std::ostream& UnaryBooleanPathFormula::writeToStream(std::ostream& out) const { |
|||
switch (operatorType) { |
|||
case OperatorType::Not: out << "!("; break; |
|||
} |
|||
this->getSubformula().writeToStream(out); |
|||
out << ")"; |
|||
return out; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
#ifndef STORM_LOGIC_UNARYBOOLEANPATHFORMULA_H_ |
|||
#define STORM_LOGIC_UNARYBOOLEANPATHFORMULA_H_ |
|||
|
|||
#include "storm/logic/UnaryPathFormula.h" |
|||
#include "storm/logic/UnaryBooleanOperatorType.h" |
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
class UnaryBooleanPathFormula : public UnaryPathFormula { |
|||
public: |
|||
typedef storm::logic::UnaryBooleanOperatorType OperatorType; |
|||
|
|||
UnaryBooleanPathFormula(OperatorType operatorType, std::shared_ptr<Formula const> const& subformula); |
|||
|
|||
virtual ~UnaryBooleanPathFormula() { |
|||
// Intentionally left empty. |
|||
}; |
|||
|
|||
virtual bool isUnaryBooleanPathFormula() const override; |
|||
|
|||
virtual boost::any accept(FormulaVisitor const& visitor, boost::any const& data) const override; |
|||
|
|||
OperatorType getOperator() const; |
|||
|
|||
virtual bool isNot() const; |
|||
|
|||
virtual std::ostream& writeToStream(std::ostream& out) const override; |
|||
|
|||
private: |
|||
OperatorType operatorType; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_LOGIC_UNARYBOOLEANPATHFORMULA_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue