Browse Source
better check whether transition rewards can be scaled and lifted to action rewards
tempestpy_adaptions
better check whether transition rewards can be scaled and lifted to action rewards
tempestpy_adaptions
TimQu
6 years ago
5 changed files with 193 additions and 13 deletions
-
2src/storm/api/builder.h
-
16src/storm/builder/BuilderOptions.cpp
-
7src/storm/builder/BuilderOptions.h
-
133src/storm/logic/LiftableTransitionRewardsVisitor.cpp
-
48src/storm/logic/LiftableTransitionRewardsVisitor.h
@ -0,0 +1,133 @@ |
|||
#include "storm/logic/LiftableTransitionRewardsVisitor.h"
|
|||
|
|||
#include "storm/logic/Formulas.h"
|
|||
#include "storm/storage/jani/traverser/RewardModelInformation.h"
|
|||
|
|||
namespace storm { |
|||
namespace logic { |
|||
|
|||
LiftableTransitionRewardsVisitor::LiftableTransitionRewardsVisitor(storm::storage::SymbolicModelDescription const& symbolicModelDescription) : symbolicModelDescription(symbolicModelDescription) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
bool LiftableTransitionRewardsVisitor::areTransitionRewardsLiftable(Formula const& f) const { |
|||
return boost::any_cast<bool>(f.accept(*this, boost::any())); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(AtomicExpressionFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(AtomicLabelFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(BinaryBooleanStateFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(BooleanLiteralFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(BoundedUntilFormula const& f, boost::any const& data) const { |
|||
for (unsigned i = 0; i < f.getDimension(); ++i) { |
|||
if (f.getTimeBoundReference(i).isRewardBound() && rewardModelHasTransitionRewards(f.getTimeBoundReference(i).getRewardName())) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
bool result = true; |
|||
if (f.hasMultiDimensionalSubformulas()) { |
|||
for (unsigned i = 0; i < f.getDimension(); ++i) { |
|||
result = result && boost::any_cast<bool>(f.getLeftSubformula(i).accept(*this, data)); |
|||
result = result && boost::any_cast<bool>(f.getRightSubformula(i).accept(*this, data)); |
|||
} |
|||
} else { |
|||
result = result && boost::any_cast<bool>(f.getLeftSubformula().accept(*this, data)); |
|||
result = result && boost::any_cast<bool>(f.getRightSubformula().accept(*this, data)); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(ConditionalFormula const& f, boost::any const& data) const { |
|||
return !f.isConditionalRewardFormula() && boost::any_cast<bool>(f.getSubformula().accept(*this, data)) && boost::any_cast<bool>(f.getConditionFormula().accept(*this, data)); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(CumulativeRewardFormula const& f, boost::any const&) const { |
|||
for (unsigned i = 0; i < f.getDimension(); ++i) { |
|||
if (f.getTimeBoundReference(i).isRewardBound() && rewardModelHasTransitionRewards(f.getTimeBoundReference(i).getRewardName())) { |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(EventuallyFormula const& f, boost::any const& data) const { |
|||
return f.getSubformula().accept(*this, data); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(TimeOperatorFormula const& f, boost::any const& data) const { |
|||
return f.getSubformula().accept(*this, data); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(GloballyFormula const& f, boost::any const& data) const { |
|||
return f.getSubformula().accept(*this, data); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(InstantaneousRewardFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(LongRunAverageOperatorFormula const& f, boost::any const& data) const { |
|||
return f.getSubformula().accept(*this, data); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(LongRunAverageRewardFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(MultiObjectiveFormula const& f, boost::any const& data) const { |
|||
bool result = true; |
|||
for (auto const& subF : f.getSubformulas()){ |
|||
result = result && boost::any_cast<bool>(subF->accept(*this, data)); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(NextFormula const& f, boost::any const& data) const { |
|||
return boost::any_cast<bool>(f.getSubformula().accept(*this, data)); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(ProbabilityOperatorFormula const& f, boost::any const& data) const { |
|||
return f.getSubformula().accept(*this, data); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(RewardOperatorFormula const& f, boost::any const& data) const { |
|||
return boost::any_cast<bool>(f.getSubformula().accept(*this, data)); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(TotalRewardFormula const&, boost::any const&) const { |
|||
return true; |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(UnaryBooleanStateFormula const& f, boost::any const& data) const { |
|||
return f.getSubformula().accept(*this, data); |
|||
} |
|||
|
|||
boost::any LiftableTransitionRewardsVisitor::visit(UntilFormula const& f, boost::any const& data) const { |
|||
return boost::any_cast<bool>(f.getLeftSubformula().accept(*this, data)) && boost::any_cast<bool>(f.getRightSubformula().accept(*this)); |
|||
} |
|||
|
|||
bool LiftableTransitionRewardsVisitor::rewardModelHasTransitionRewards(std::string const& rewardModelName) const { |
|||
if (symbolicModelDescription.isJaniModel()) { |
|||
return storm::jani::RewardModelInformation(symbolicModelDescription.asJaniModel(), rewardModelName).hasTransitionRewards(); |
|||
} else if (symbolicModelDescription.isPrismProgram()) { |
|||
return symbolicModelDescription.asPrismProgram().getRewardModel(rewardModelName).hasTransitionRewards(); |
|||
} else { |
|||
// No model given
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
#pragma once |
|||
|
|||
#include "storm/logic/FormulaVisitor.h" |
|||
#include "storm/logic/FormulaInformation.h" |
|||
#include "storm/storage/SymbolicModelDescription.h" |
|||
|
|||
namespace storm { |
|||
|
|||
namespace logic { |
|||
|
|||
class LiftableTransitionRewardsVisitor : public FormulaVisitor { |
|||
public: |
|||
|
|||
LiftableTransitionRewardsVisitor(storm::storage::SymbolicModelDescription const& symbolicModelDescription = storm::storage::SymbolicModelDescription()); |
|||
|
|||
/*! |
|||
* Returns true, when lifting transition rewards to action rewards (by scaling with the transition probability) preserves the given formula |
|||
*/ |
|||
bool areTransitionRewardsLiftable(Formula const& f) const; |
|||
|
|||
virtual boost::any visit(AtomicExpressionFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(AtomicLabelFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(BinaryBooleanStateFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(BooleanLiteralFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(BoundedUntilFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(ConditionalFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(CumulativeRewardFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(EventuallyFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(TimeOperatorFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(GloballyFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(InstantaneousRewardFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(LongRunAverageOperatorFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(LongRunAverageRewardFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(MultiObjectiveFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(NextFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(ProbabilityOperatorFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(RewardOperatorFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(TotalRewardFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(UnaryBooleanStateFormula const& f, boost::any const& data) const override; |
|||
virtual boost::any visit(UntilFormula const& f, boost::any const& data) const override; |
|||
|
|||
private: |
|||
storm::storage::SymbolicModelDescription const& symbolicModelDescription; |
|||
bool rewardModelHasTransitionRewards(std::string const& rewardModelName) const; |
|||
}; |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue