Browse Source

eliminating reward accumulations directly at parsing time

tempestpy_adaptions
TimQu 6 years ago
parent
commit
f89817da3b
  1. 6
      src/storm-parsers/api/properties.cpp
  2. 6
      src/storm-parsers/parser/JaniParser.cpp
  3. 12
      src/storm/logic/RewardAccumulationEliminationVisitor.cpp
  4. 1
      src/storm/logic/RewardAccumulationEliminationVisitor.h

6
src/storm-parsers/api/properties.cpp

@ -3,8 +3,9 @@
#include "storm-parsers/parser/FormulaParser.h"
#include "storm/api/properties.h"
#include "storm/storage/SymbolicModelDescription.h"
#include "storm/logic/RewardAccumulationEliminationVisitor.h"
#include "storm/storage/prism/Program.h"
#include "storm/storage/jani/Model.h"
#include "storm/storage/jani/Property.h"
@ -48,6 +49,9 @@ namespace storm {
std::vector <storm::jani::Property> parsePropertiesForJaniModel(std::string const &inputString, storm::jani::Model const &model, boost::optional <std::set<std::string>> const &propertyFilter) {
storm::parser::FormulaParser formulaParser(model.getManager().getSharedPointer());
auto formulas = parseProperties(formulaParser, inputString, propertyFilter);
// Eliminate reward accumulations if possible
storm::logic::RewardAccumulationEliminationVisitor v(model);
v.eliminateRewardAccumulations(formulas);
return substituteConstantsInProperties(formulas, model.getConstantsSubstitution());
}

6
src/storm-parsers/parser/JaniParser.cpp

@ -177,6 +177,10 @@ namespace storm {
STORM_LOG_THROW(parsedStructure.count("system") == 1, storm::exceptions::InvalidJaniException, "Exactly one system description must be given");
std::shared_ptr<storm::jani::Composition> composition = parseComposition(parsedStructure.at("system"));
model.setSystemComposition(composition);
model.finalize();
// Parse properties
storm::logic::RewardAccumulationEliminationVisitor rewAccEliminator(model);
STORM_LOG_THROW(parsedStructure.count("properties") <= 1, storm::exceptions::InvalidJaniException, "At most one list of properties can be given");
std::map<std::string, storm::jani::Property> properties;
if (parseProperties && parsedStructure.count("properties") == 1) {
@ -184,6 +188,8 @@ namespace storm {
for(auto const& propertyEntry : parsedStructure.at("properties")) {
try {
auto prop = this->parseProperty(propertyEntry, scope.refine("property[" + std::to_string(properties.size()) + "]"));
// Eliminate reward accumulations as much as possible
rewAccEliminator.eliminateRewardAccumulations(prop);
properties.emplace(prop.getName(), prop);
} catch (storm::exceptions::NotSupportedException const& ex) {
STORM_LOG_WARN("Cannot handle property: " << ex.what());

12
src/storm/logic/RewardAccumulationEliminationVisitor.cpp

@ -22,13 +22,17 @@ namespace storm {
void RewardAccumulationEliminationVisitor::eliminateRewardAccumulations(std::vector<storm::jani::Property>& properties) const {
for (auto& p : properties) {
auto formula = eliminateRewardAccumulations(*p.getFilter().getFormula());
auto states = eliminateRewardAccumulations(*p.getFilter().getStatesFormula());
storm::jani::FilterExpression fe(formula, p.getFilter().getFilterType(), states);
p = storm::jani::Property(p.getName(), storm::jani::FilterExpression(formula, p.getFilter().getFilterType(), states), p.getComment());
eliminateRewardAccumulations(p);
}
}
void RewardAccumulationEliminationVisitor::eliminateRewardAccumulations(storm::jani::Property& property) const {
auto formula = eliminateRewardAccumulations(*property.getFilter().getFormula());
auto states = eliminateRewardAccumulations(*property.getFilter().getStatesFormula());
storm::jani::FilterExpression fe(formula, property.getFilter().getFilterType(), states);
property = storm::jani::Property(property.getName(), storm::jani::FilterExpression(formula, property.getFilter().getFilterType(), states), property.getComment());
}
boost::any RewardAccumulationEliminationVisitor::visit(BoundedUntilFormula const& f, boost::any const& data) const {
std::vector<boost::optional<TimeBound>> lowerBounds, upperBounds;
std::vector<TimeBoundReference> timeBoundReferences;

1
src/storm/logic/RewardAccumulationEliminationVisitor.h

@ -21,6 +21,7 @@ namespace storm {
std::shared_ptr<Formula> eliminateRewardAccumulations(Formula const& f) const;
void eliminateRewardAccumulations(std::vector<storm::jani::Property>& properties) const;
void eliminateRewardAccumulations(storm::jani::Property& property) const;
virtual boost::any visit(BoundedUntilFormula const& f, boost::any const& data) const override;
virtual boost::any visit(CumulativeRewardFormula const& f, boost::any const& data) const override;

Loading…
Cancel
Save