Browse Source
Added some filter actions.
Added some filter actions.
- Also major cleanup of the filter.
- Implementation clompleted for pctl.
Next up: Wrap up the Csl and Ltl filter and then testing.
Former-commit-id: 8189f8462c
main
10 changed files with 742 additions and 217 deletions
-
1src/formula/AbstractFilter.h
-
61src/formula/Actions/AbstractAction.h
-
167src/formula/Actions/BoundAction.h
-
80src/formula/Actions/InvertAction.h
-
80src/formula/Actions/RangeAction.h
-
174src/formula/Actions/SortAction.h
-
18src/formula/Csl/CslFilter.h
-
257src/formula/Prctl/PrctlFilter.h
-
47src/parser/CslParser.cpp
-
74src/parser/PrctlParser.cpp
@ -0,0 +1,167 @@ |
|||
/* |
|||
* BoundAction.h |
|||
* |
|||
* Created on: Jun 22, 2014 |
|||
* Author: Manuel Sascha Weiand |
|||
*/ |
|||
|
|||
#ifndef STORM_FORMULA_ACTION_BOUNDACTION_H_ |
|||
#define STORM_FORMULA_ACTION_BOUNDACTION_H_ |
|||
|
|||
#include "src/formula/Actions/AbstractAction.h" |
|||
#include "src/formula/ComparisonType.h" |
|||
|
|||
namespace storm { |
|||
namespace property { |
|||
namespace action { |
|||
|
|||
template <class T> |
|||
class BoundAction : public AbstractAction<T> { |
|||
|
|||
typedef typename AbstractAction<T>::Result Result; |
|||
|
|||
public: |
|||
|
|||
BoundAction() : comparisonOperator(storm::property::GREATER_EQUAL), bound(0) { |
|||
//Intentionally left empty. |
|||
} |
|||
|
|||
BoundAction(storm::property::ComparisonType comparisonOperator, T bound) : comparisonOperator(comparisonOperator), bound(bound) { |
|||
//Intentionally left empty. |
|||
} |
|||
|
|||
/*! |
|||
* Virtual destructor |
|||
* To ensure that the right destructor is called |
|||
*/ |
|||
virtual ~BoundAction() { |
|||
//Intentionally left empty |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::prctl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::csl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::ltl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual std::string toString() const override { |
|||
std::string out = "bound("; |
|||
switch (comparisonOperator) { |
|||
case LESS: |
|||
out += "<"; |
|||
break; |
|||
case LESS_EQUAL: |
|||
out += "<="; |
|||
break; |
|||
case GREATER: |
|||
out += ">"; |
|||
break; |
|||
case GREATER_EQUAL: |
|||
out += ">="; |
|||
break; |
|||
default: |
|||
LOG4CPLUS_INFO(logger, "Unknown comparison operator of value " << comparisonOperator << "."); |
|||
std::cout << "Unknown comparison operator of value " << comparisonOperator << "." << std::endl; |
|||
break; |
|||
} |
|||
out += ", "; |
|||
out += std::to_string(bound); |
|||
out += ")"; |
|||
return out; |
|||
} |
|||
|
|||
private: |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result) const { |
|||
|
|||
//Initialize the new selection vector. |
|||
storm::storage::BitVector out(result.selection.size()); |
|||
|
|||
if(result.pathResult.size() != 0) { |
|||
|
|||
//Fill the selction by comapring the values for all previously selected states with theegiven bound using the comparison operator. |
|||
for(uint_fast64_t i = 0; i < result.stateMap.size(); i++) { |
|||
if(result.selection[result.stateMap[i]]) { |
|||
switch(comparisonOperator) { |
|||
case storm::property::GREATER_EQUAL: |
|||
out.set(result.pathResult[result.stateMap[i]] >= bound); |
|||
break; |
|||
case storm::property::GREATER: |
|||
out.set(result.pathResult[result.stateMap[i]] > bound); |
|||
break; |
|||
case storm::property::LESS_EQUAL: |
|||
out.set(result.pathResult[result.stateMap[i]] <= bound); |
|||
break; |
|||
case storm::property::LESS: |
|||
out.set(result.pathResult[result.stateMap[i]] < bound); |
|||
break; |
|||
default: |
|||
LOG4CPLUS_INFO(logger, "Unknown comparison operator of value " << comparisonOperator << "."); |
|||
std::cout << "Unknown comparison operator of value " << comparisonOperator << "." << std::endl; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} else { |
|||
|
|||
//Fill the selction by comapring the values for all previously selected states with theegiven bound using the comparison operator. |
|||
for(uint_fast64_t i = 0; i < result.stateMap.size(); i++) { |
|||
if(result.selection[result.stateMap[i]]) { |
|||
switch(comparisonOperator) { |
|||
case storm::property::GREATER_EQUAL: |
|||
out.set(result.stateResult[result.stateMap[i]] >= bound); |
|||
break; |
|||
case storm::property::GREATER: |
|||
out.set(result.stateResult[result.stateMap[i]] > bound); |
|||
break; |
|||
case storm::property::LESS_EQUAL: |
|||
out.set(result.stateResult[result.stateMap[i]] <= bound); |
|||
break; |
|||
case storm::property::LESS: |
|||
out.set(result.stateResult[result.stateMap[i]] < bound); |
|||
break; |
|||
default: |
|||
LOG4CPLUS_INFO(logger, "Unknown comparison operator of value " << comparisonOperator << "."); |
|||
std::cout << "Unknown comparison operator of value " << comparisonOperator << "." << std::endl; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
return Result(out, result.stateMap, result.pathResult, result.stateResult); |
|||
} |
|||
|
|||
storm::property::ComparisonType comparisonOperator; |
|||
T bound; |
|||
|
|||
}; |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
#endif /* STORM_FORMULA_ACTION_BOUNDACTION_H_ */ |
@ -0,0 +1,80 @@ |
|||
/* |
|||
* InvertAction.h |
|||
* |
|||
* Created on: Jun 22, 2014 |
|||
* Author: Manuel Sascha Weiand |
|||
*/ |
|||
|
|||
#ifndef STORM_FORMULA_ACTION_INVERTACTION_H_ |
|||
#define STORM_FORMULA_ACTION_INVERTACTION_H_ |
|||
|
|||
#include "src/formula/Actions/AbstractAction.h" |
|||
|
|||
namespace storm { |
|||
namespace property { |
|||
namespace action { |
|||
|
|||
template <class T> |
|||
class InvertAction : public AbstractAction<T> { |
|||
|
|||
typedef typename AbstractAction<T>::Result Result; |
|||
|
|||
public: |
|||
|
|||
InvertAction() { |
|||
//Intentionally left empty. |
|||
} |
|||
|
|||
/*! |
|||
* Virtual destructor |
|||
* To ensure that the right destructor is called |
|||
*/ |
|||
virtual ~InvertAction() { |
|||
//Intentionally left empty |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::prctl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::csl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::ltl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual std::string toString() const override { |
|||
return "invert"; |
|||
} |
|||
|
|||
private: |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result) const { |
|||
storm::storage::BitVector out(result.selection); |
|||
return Result(~out, result.stateMap, result.pathResult, result.stateResult); |
|||
} |
|||
}; |
|||
|
|||
} //namespace action |
|||
} //namespace property |
|||
} //namespace storm |
|||
|
|||
|
|||
#endif /* STORM_FORMULA_ACTION_INVERTACTION_H_ */ |
@ -0,0 +1,174 @@ |
|||
/* |
|||
* SortAction.h |
|||
* |
|||
* Created on: Jun 22, 2014 |
|||
* Author: Manuel Sascha Weiand |
|||
*/ |
|||
|
|||
#ifndef STORM_FORMULA_ACTION_SORTACTION_H_ |
|||
#define STORM_FORMULA_ACTION_SORTACTION_H_ |
|||
|
|||
#include "src/formula/Actions/AbstractAction.h" |
|||
#include <cctype> |
|||
|
|||
namespace storm { |
|||
namespace property { |
|||
namespace action { |
|||
|
|||
template <class T> |
|||
class SortAction : public AbstractAction<T> { |
|||
|
|||
typedef typename AbstractAction<T>::Result Result; |
|||
|
|||
public: |
|||
|
|||
enum SortingCategory {INDEX, VALUE}; |
|||
|
|||
SortAction() : category(INDEX), ascending(true) { |
|||
//Intentionally left empty. |
|||
} |
|||
|
|||
SortAction(SortingCategory category, bool ascending = true) : category(category), ascending(ascending) { |
|||
//Intentionally left empty. |
|||
} |
|||
|
|||
/*! |
|||
* Virtual destructor |
|||
* To ensure that the right destructor is called |
|||
*/ |
|||
virtual ~SortAction() { |
|||
//Intentionally left empty |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::prctl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::csl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual Result evaluate(Result const & result, storm::modelchecker::ltl::AbstractModelChecker<T> const & mc) const override { |
|||
return evaluate(result); |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
virtual std::string toString() const override { |
|||
std::string out = "sort, "; |
|||
switch (category) { |
|||
case INDEX: |
|||
out += "index"; |
|||
break; |
|||
case VALUE: |
|||
out += "value"; |
|||
break; |
|||
default: |
|||
LOG4CPLUS_INFO(logger, "Unknown sorting category of value " << category << "."); |
|||
std::cout << "Unknown sorting category of value " << category << "." << std::endl; |
|||
break; |
|||
} |
|||
out += ", "; |
|||
out += ascending ? "ascending" : "descending"; |
|||
return out; |
|||
} |
|||
|
|||
|
|||
private: |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
Result evaluate(Result const & result) const { |
|||
|
|||
if(category == VALUE) { |
|||
//TODO |
|||
|
|||
if(result.pathResult.size() != 0) { |
|||
return Result(result.selection, sort(result.stateMap, result.pathResult), result.pathResult, result.stateResult); |
|||
} else { |
|||
return Result(result.selection, sort(result.stateMap, result.stateResult), result.pathResult, result.stateResult); |
|||
} |
|||
|
|||
} else { |
|||
return Result(result.selection, sort(result.stateMap.size()), result.pathResult, result.stateResult); |
|||
} |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
std::vector<uint_fast64_t> sort(uint_fast64_t length) const { |
|||
|
|||
// Project the vector down to its first component. |
|||
std::vector<uint_fast64_t> outMap(length); |
|||
|
|||
// Sort the combined vector. |
|||
if(ascending) { |
|||
for(uint_fast64_t i = 0; i < length; i++) { |
|||
outMap[i] = i; |
|||
} |
|||
} else { |
|||
for(uint_fast64_t i = 0; i < length; i++) { |
|||
outMap[i] = length - i - 1; |
|||
} |
|||
} |
|||
|
|||
return outMap; |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
std::vector<uint_fast64_t> sort(std::vector<uint_fast64_t> const & stateMap, std::vector<T> const & values) const { |
|||
|
|||
// Prepare the new state map. |
|||
std::vector<uint_fast64_t> outMap(stateMap); |
|||
|
|||
// Sort the state map. |
|||
if(ascending) { |
|||
std::sort(outMap.begin(), outMap.end(), [&] (uint_fast64_t a, uint_fast64_t b) -> bool { return values[a] <= values[b]; }); |
|||
} else { |
|||
std::sort(outMap.begin(), outMap.end(), [&] (uint_fast64_t a, uint_fast64_t b) -> bool { return values[a] >= values[b]; }); |
|||
} |
|||
|
|||
return outMap; |
|||
} |
|||
|
|||
/*! |
|||
* |
|||
*/ |
|||
std::vector<uint_fast64_t> sort(std::vector<uint_fast64_t> const & stateMap, storm::storage::BitVector const & values) const { |
|||
|
|||
// Prepare the new state map. |
|||
std::vector<uint_fast64_t> outMap(stateMap); |
|||
|
|||
// Sort the state map. |
|||
if(ascending) { |
|||
std::sort(outMap.begin(), outMap.end(), [&] (uint_fast64_t a, uint_fast64_t b) -> bool { return values[a] <= values[b]; }); |
|||
} else { |
|||
std::sort(outMap.begin(), outMap.end(), [&] (uint_fast64_t a, uint_fast64_t b) -> bool { return values[a] >= values[b]; }); |
|||
} |
|||
|
|||
return outMap; |
|||
} |
|||
|
|||
SortingCategory category; |
|||
bool ascending; |
|||
}; |
|||
|
|||
} //namespace action |
|||
} //namespace property |
|||
} //namespace storm |
|||
|
|||
#endif /* STORM_FORMULA_ACTION_SORTACTION_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue