Browse Source

Fixed up the CslParser.

Next Up: Making the parsers static classes.


Former-commit-id: 247a105078
tempestpy_adaptions
masawei 11 years ago
parent
commit
185c2197cb
  1. 54
      src/formula/Csl/CslFilter.h
  2. 27
      src/formula/Ltl/LtlFilter.h
  3. 2
      src/modelchecker/csl/AbstractModelChecker.h
  4. 1184
      src/modelchecker/csl/SparseMarkovAutomatonCslModelChecker.h
  5. 82
      src/parser/CslParser.cpp
  6. 3
      src/parser/CslParser.h

54
src/formula/Csl/CslFilter.h

@ -12,13 +12,15 @@
#include "src/formula/Csl/AbstractCslFormula.h"
#include "src/formula/Csl/AbstractPathFormula.h"
#include "src/formula/Csl/AbstractStateFormula.h"
#include "src/modelchecker/csl/AbstractModelChecker.h"
#include "src/formula/Actions/MinMaxAction.h"
namespace storm {
namespace property {
namespace csl {
template <class T>
class CslFilter : storm::property::AbstractFilter<T> {
class CslFilter : public storm::property::AbstractFilter<T> {
public:
@ -26,24 +28,28 @@ public:
// Intentionally left empty.
}
CslFilter(AbstractCslFormula* child) : child(child) {
CslFilter(AbstractCslFormula<T>* child) : child(child) {
// Intentionally left empty.
}
CslFilter(AbstractCslFormula* child, action::Action<T>* action) : child(child) {
actions.push_back(action);
CslFilter(AbstractCslFormula<T>* child, bool minimize) : child(child) {
this->actions.push_back(new storm::property::action::MinMaxAction<T>(minimize));
}
CslFilter(AbstractCslFormula* child, std::vector<action::Action<T>*> actions) : child(child), actions(actions) {
CslFilter(AbstractCslFormula<T>* child, action::AbstractAction<T>* action) : child(child) {
this->actions.push_back(action);
}
CslFilter(AbstractCslFormula<T>* child, std::vector<action::AbstractAction<T>*> actions) : AbstractFilter<T>(actions), child(child) {
// Intentionally left empty.
}
virtual ~CslFilter() {
actions.clear();
this->actions.clear();
delete child;
}
void check(AbstractModelChecker const & modelchecker) const {
void check(storm::modelchecker::csl::AbstractModelChecker<T> const & modelchecker) const {
// Write out the formula to be checked.
std::cout << std::endl;
@ -68,13 +74,13 @@ public:
// Now write out the result.
if(actions.empty()) {
if(this->actions.empty()) {
// There is no filter action given. So provide legacy support:
// Return the results for all states labeled with "init".
LOG4CPLUS_INFO(logger, "Result for initial states:");
std::cout << "Result for initial states:" << std::endl;
for (auto initialState : modelchecker.getModel<storm::models::AbstractModel<T>>().getInitialStates()) {
for (auto initialState : modelchecker.getModel().getInitialStates()) {
LOG4CPLUS_INFO(logger, "\t" << initialState << ": " << (result.get(initialState) ? "satisfied" : "not satisfied"));
std::cout << "\t" << initialState << ": " << result.get(initialState) << std::endl;
}
@ -100,13 +106,13 @@ public:
// Now write out the result.
if(actions.empty()) {
if(this->actions.empty()) {
// There is no filter action given. So provide legacy support:
// Return the results for all states labeled with "init".
LOG4CPLUS_INFO(logger, "Result for initial states:");
std::cout << "Result for initial states:" << std::endl;
for (auto initialState : modelchecker.getModel<storm::models::AbstractModel<T>>().getInitialStates()) {
for (auto initialState : modelchecker.getModel().getInitialStates()) {
LOG4CPLUS_INFO(logger, "\t" << initialState << ": " << result[initialState]);
std::cout << "\t" << initialState << ": " << result[initialState] << std::endl;
}
@ -147,61 +153,61 @@ public:
std::string toString() const {
std::string desc = "Filter: ";
desc += "\nActions:";
for(auto action : actions) {
for(auto action : this->actions) {
desc += "\n\t" + action.toString();
}
desc += "\nFormula:\n\t" + child->toString();
return desc;
}
void setChild(AbstractCslFormula* child) {
void setChild(AbstractCslFormula<T>* child) {
this->child = child;
}
AbstractFormula* getChild() const {
AbstractCslFormula<T>* getChild() const {
return child;
}
private:
BitVector evaluate(AbstractModelChecker const & modelchecker, AbstractStateFormula<T>* formula) const {
storm::storage::BitVector evaluate(storm::modelchecker::csl::AbstractModelChecker<T> const & modelchecker, AbstractStateFormula<T>* formula) const {
// First, get the model checking result.
BitVector result = modelchecker.checkMinMaxOperator(formula);
storm::storage::BitVector result = modelchecker.checkMinMaxOperator(formula);
if(getActionCount() != 0 && dynamic_cast<MinMaxAction<T>*>(getAction(0)) != nullptr) {
if(this->getActionCount() != 0 && dynamic_cast<storm::property::action::MinMaxAction<T>*>(this->getAction(0)) != nullptr) {
// If there is an action specifying that min/max probabilities should be computed, call the appropriate method of the model checker.
result = modelchecker.checkMinMaxOperator(formula, static_cast<MinMaxAction<T>*>(getAction(0))->getMinimize());
result = modelchecker.checkMinMaxOperator(formula, static_cast<storm::property::action::MinMaxAction<T>*>(this->getAction(0))->getMinimize());
} else {
result = formula->check(modelchecker);
}
// Now apply all filter actions and return the result.
for(auto action : actions) {
for(auto action : this->actions) {
result = action->evaluate(result);
}
return result;
}
std::vector<T> evaluate(AbstractModelChecker const & modelchecker, AbstractPathFormula<T>* formula) const {
std::vector<T> evaluate(storm::modelchecker::csl::AbstractModelChecker<T> const & modelchecker, AbstractPathFormula<T>* formula) const {
// First, get the model checking result.
std::vector<T> result;
if(getActionCount() != 0 && dynamic_cast<MinMaxAction<T>*>(getAction(0)) != nullptr) {
if(this->getActionCount() != 0 && dynamic_cast<storm::property::action::MinMaxAction<T>*>(this->getAction(0)) != nullptr) {
// If there is an action specifying that min/max probabilities should be computed, call the appropriate method of the model checker.
result = modelchecker.checkMinMaxOperator(formula, static_cast<MinMaxAction<T>*>(getAction(0))->getMinimize());
result = modelchecker.checkMinMaxOperator(formula, static_cast<storm::property::action::MinMaxAction<T>*>(this->getAction(0))->getMinimize());
} else {
result = formula->check(modelchecker, false);
}
// Now apply all filter actions and return the result.
for(auto action : actions) {
for(auto action : this->actions) {
result = action->evaluate(result);
}
return result;
}
AbstractCslFormula* child;
AbstractCslFormula<T>* child;
};
} //namespace csl

27
src/formula/Ltl/LtlFilter.h

@ -8,12 +8,15 @@
#ifndef STORM_FORMULA_LTL_LTLFILTER_H_
#define STORM_FORMULA_LTL_LTLFILTER_H_
#include "src/formula/AbstractFilter.h"
#include "src/modelchecker/ltl/AbstractModelChecker.h"
namespace storm {
namespace property {
namespace ltl {
template <class T>
class LtlFilter : storm::property::AbstractFilter<T> {
class LtlFilter : public storm::property::AbstractFilter<T> {
public:
@ -26,15 +29,15 @@ public:
}
LtlFilter(AbstractLtlFormula* child, action::Action<T>* action) : child(child) {
actions.push_back(action);
this->actions.push_back(action);
}
LtlFilter(AbstractLtlFormula* child, std::vector<action::Action<T>*> actions) : child(child), actions(actions) {
LtlFilter(AbstractLtlFormula* child, std::vector<action::Action<T>*> actions) : AbstractFilter<T>(actions), child(child) {
// Intentionally left empty.
}
virtual ~LtlFilter() {
actions.clear();
this->actions.clear();
delete child;
}
@ -45,7 +48,7 @@ public:
*
* @param stateFormula The formula to be checked.
*/
void check(AbstractModelChecker const & modelchecker) const {
void check(storm::modelchecker::ltl::AbstractModelChecker<T> const & modelchecker) const {
// Write out the formula to be checked.
std::cout << std::endl;
@ -68,7 +71,7 @@ public:
// Now write out the result.
if(actions.empty()) {
if(this->actions.empty()) {
// There is no filter action given. So provide legacy support:
// Return the results for all states labeled with "init".
@ -99,35 +102,35 @@ public:
std::string toString() const {
std::string desc = "Filter: ";
desc += "\nActions:";
for(auto action : actions) {
for(auto action : this->actions) {
desc += "\n\t" + action.toString();
}
desc += "\nFormula:\n\t" + child->toString();
return desc;
}
void setChild(AbstractLtlFormula* child) {
void setChild(AbstractLtlFormula<T>* child) {
this->child = child;
}
AbstractFormula* getChild() const {
AbstractLtlFormula<T>* getChild() const {
return child;
}
private:
storm::storage::BitVector evaluate(AbstractModelChecker const & modelchecker, AbstractLtlFormula<T>* formula) const {
storm::storage::BitVector evaluate(storm::modelchecker::ltl::AbstractModelChecker<T> const & modelchecker, AbstractLtlFormula<T>* formula) const {
// First, get the model checking result.
storm::storage::BitVector result = formula->check(modelchecker);
// Now apply all filter actions and return the result.
for(auto action : actions) {
for(auto action : this->actions) {
result = action->evaluate(result);
}
return result;
}
AbstractLtlFormula* child;
AbstractLtlFormula<T>* child;
};

2
src/modelchecker/csl/AbstractModelChecker.h

@ -172,7 +172,7 @@ public:
* @param formula The formula to check.
* @returns The set of states satisfying the formula represented by a bit vector.
*/
storm::storage::BitVector checkProbabilisticBoundOperator(storm::property::csl::ProbabilisticBoundOperator<Type> const& formula) const {
virtual storm::storage::BitVector checkProbabilisticBoundOperator(storm::property::csl::ProbabilisticBoundOperator<Type> const& formula) const {
// First, we need to compute the probability for satisfying the path formula for each state.
std::vector<Type> quantitativeResult = formula.getPathFormula().check(*this, false);

1184
src/modelchecker/csl/SparseMarkovAutomatonCslModelChecker.h
File diff suppressed because it is too large
View File

82
src/parser/CslParser.cpp

@ -9,6 +9,11 @@
#include "src/utility/OsDetection.h"
#include "src/utility/constants.h"
// The action class headers.
#include "src/formula/Actions/AbstractAction.h"
#include "src/formula/Actions/MinMaxAction.h"
#include "src/formula/Actions/RangeAction.h"
// If the parser fails due to ill-formed data, this exception is thrown.
#include "src/exceptions/WrongFormatException.h"
@ -38,7 +43,7 @@ namespace storm {
namespace parser {
template<typename Iterator, typename Skipper>
struct CslGrammar : qi::grammar<Iterator, storm::property::csl::AbstractCslFormula<double>*(), Skipper > {
struct CslGrammar : qi::grammar<Iterator, storm::property::csl::CslFilter<double>*(), Skipper > {
CslGrammar() : CslGrammar::base_type(start) {
//This block contains helper rules that may be used several times
freeIdentifierName = qi::lexeme[qi::alpha >> *(qi::alnum | qi::char_('_'))];
@ -81,16 +86,6 @@ struct CslGrammar : qi::grammar<Iterator, storm::property::csl::AbstractCslFormu
);
steadyStateBoundOperator.name("state formula");
//This block defines rules for parsing formulas with noBoundOperators
noBoundOperator = (probabilisticNoBoundOperator | steadyStateNoBoundOperator);
noBoundOperator.name("no bound operator");
probabilisticNoBoundOperator = (qi::lit("P") >> qi::lit("=") >> qi::lit("?") >> qi::lit("[") >> pathFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::property::csl::ProbabilisticNoBoundOperator<double> >(qi::_1)];
probabilisticNoBoundOperator.name("no bound operator");
steadyStateNoBoundOperator = (qi::lit("S") >> qi::lit("=") >> qi::lit("?") >> qi::lit("[") >> stateFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::property::csl::SteadyStateNoBoundOperator<double> >(qi::_1)];
steadyStateNoBoundOperator.name("no bound operator");
//This block defines rules for parsing probabilistic path formulas
pathFormula = (timeBoundedEventually | eventually | globally | next | timeBoundedUntil | until);
pathFormula.name("path formula");
@ -125,16 +120,61 @@ struct CslGrammar : qi::grammar<Iterator, storm::property::csl::AbstractCslFormu
phoenix::new_<storm::property::csl::Until<double>>(phoenix::bind(&storm::property::csl::AbstractStateFormula<double>::clone, phoenix::bind(&std::shared_ptr<storm::property::csl::AbstractStateFormula<double>>::get, qi::_a)), qi::_2)];
until.name("path formula (for probabilistic operator)");
formula = (noBoundOperator | stateFormula);
formula = (pathFormula | stateFormula);
formula.name("CSL formula");
start = (((formula) > (comment | qi::eps))[qi::_val = qi::_1] |
comment
) > qi::eoi;
start.name("CSL formula");
//This block defines rules for parsing formulas with noBoundOperators
noBoundOperator = (probabilisticNoBoundOperator | steadyStateNoBoundOperator);
noBoundOperator.name("no bound operator");
probabilisticNoBoundOperator =
(qi::lit("P") >> qi::lit("min") >> qi::lit("=") >> qi::lit("?") >> qi::lit("[") >> pathFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::property::csl::CslFilter<double>>(qi::_1, true)];
(qi::lit("P") >> qi::lit("max") >> qi::lit("=") >> qi::lit("?") >> qi::lit("[") >> pathFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::property::csl::CslFilter<double>>(qi::_1, false)];
(qi::lit("P") >> qi::lit("=") >> qi::lit("?") >> qi::lit("[") >> pathFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::property::csl::CslFilter<double>>(qi::_1)];
probabilisticNoBoundOperator.name("no bound operator");
steadyStateNoBoundOperator = (qi::lit("S") >> qi::lit("=") >> qi::lit("?") >> qi::lit("[") >> stateFormula >> qi::lit("]"))[qi::_val =
phoenix::new_<storm::property::csl::CslFilter<double>>(qi::_1)];
steadyStateNoBoundOperator.name("no bound operator");
minMaxAction = qi::lit("minmax") >> qi::lit(",") >> (
qi::lit("min")[qi::_val =
phoenix::new_<storm::property::action::MinMaxAction<double>>(true)] |
qi::lit("min")[qi::_val =
phoenix::new_<storm::property::action::MinMaxAction<double>>(false)]);
minMaxAction.name("minmax action for the formula filter");
rangeAction = (qi::lit("range") >> qi::lit(",") >> qi::uint_ >> qi::lit(",") >> qi::uint_)[qi::_val =
phoenix::new_<storm::property::action::RangeAction<double>>(qi::_1, qi::_2)];
rangeAction.name("range action for the formula filter");
abstractAction = (rangeAction | minMaxAction) >> (qi::eps | qi::lit(","));
abstractAction.name("filter action");
filter = (qi::lit("filter") >> qi::lit("[") >> +abstractAction >> qi::lit("]") >> qi::lit("(") >> formula >> qi::lit(")"))[qi::_val =
phoenix::new_<storm::property::csl::CslFilter<double>>(qi::_2, qi::_1)] |
(formula)[qi::_val =
phoenix::new_<storm::property::csl::CslFilter<double>>(qi::_1)] |
(noBoundOperator)[qi::_val =
qi::_1];
filter.name("PRCTL formula filter");
start = (((filter) > (comment | qi::eps))[qi::_val = qi::_1] | comment ) > qi::eoi;
start.name("CSL formula filter");
}
qi::rule<Iterator, storm::property::csl::AbstractCslFormula<double>*(), Skipper> start;
qi::rule<Iterator, storm::property::csl::CslFilter<double>*(), Skipper> start;
qi::rule<Iterator, storm::property::csl::CslFilter<double>*(), Skipper> filter;
qi::rule<Iterator, storm::property::csl::CslFilter<double>*(), Skipper> noBoundOperator;
qi::rule<Iterator, storm::property::csl::CslFilter<double>*(), Skipper> probabilisticNoBoundOperator;
qi::rule<Iterator, storm::property::csl::CslFilter<double>*(), Skipper> steadyStateNoBoundOperator;
qi::rule<Iterator, storm::property::action::AbstractAction<double>*(), Skipper> abstractAction;
qi::rule<Iterator, storm::property::action::RangeAction<double>*(), Skipper> rangeAction;
qi::rule<Iterator, storm::property::action::MinMaxAction<double>*(), Skipper> minMaxAction;
qi::rule<Iterator, storm::property::csl::AbstractCslFormula<double>*(), Skipper> formula;
qi::rule<Iterator, storm::property::csl::AbstractCslFormula<double>*(), Skipper> comment;
@ -148,10 +188,6 @@ struct CslGrammar : qi::grammar<Iterator, storm::property::csl::AbstractCslFormu
qi::rule<Iterator, storm::property::csl::ProbabilisticBoundOperator<double>*(), Skipper> probabilisticBoundOperator;
qi::rule<Iterator, storm::property::csl::SteadyStateBoundOperator<double>*(), Skipper> steadyStateBoundOperator;
qi::rule<Iterator, storm::property::csl::AbstractNoBoundOperator<double>*(), Skipper> noBoundOperator;
qi::rule<Iterator, storm::property::csl::AbstractNoBoundOperator<double>*(), Skipper> probabilisticNoBoundOperator;
qi::rule<Iterator, storm::property::csl::AbstractNoBoundOperator<double>*(), Skipper> steadyStateNoBoundOperator;
qi::rule<Iterator, storm::property::csl::AbstractPathFormula<double>*(), Skipper> pathFormula;
qi::rule<Iterator, storm::property::csl::TimeBoundedEventually<double>*(), Skipper> timeBoundedEventually;
qi::rule<Iterator, storm::property::csl::Eventually<double>*(), Skipper> eventually;
@ -166,7 +202,7 @@ struct CslGrammar : qi::grammar<Iterator, storm::property::csl::AbstractCslFormu
};
storm::property::csl::AbstractCslFormula<double>* CslParser(std::string formulaString) {
storm::property::csl::CslFilter<double>* CslParser(std::string formulaString) {
// Prepare iterators to input.
BaseIteratorType stringIteratorBegin = formulaString.begin();
BaseIteratorType stringIteratorEnd = formulaString.end();
@ -175,7 +211,7 @@ storm::property::csl::AbstractCslFormula<double>* CslParser(std::string formulaS
// Prepare resulting intermediate representation of input.
storm::property::csl::AbstractCslFormula<double>* result_pointer = nullptr;
storm::property::csl::CslFilter<double>* result_pointer = nullptr;
CslGrammar<PositionIteratorType, BOOST_TYPEOF(boost::spirit::ascii::space)> grammar;

3
src/parser/CslParser.h

@ -9,6 +9,7 @@
#define STORM_PARSER_CSLPARSER_H_
#include "src/formula/Csl.h"
#include "src/formula/Csl/CslFilter.h"
#include <functional>
namespace storm {
@ -23,7 +24,7 @@ namespace parser {
* @param formulaString The string representation of the formula
* @throw wrongFormatException If the input could not be parsed successfully
*/
storm::property::csl::AbstractCslFormula<double>* CslParser(std::string formulaString);
storm::property::csl::CslFilter<double>* CslParser(std::string formulaString);
/*!
* Struct for the CSL grammar, that Boost::Spirit uses to parse the formulas.

Loading…
Cancel
Save