Browse Source

added bounded globally formulas to other classes

tempestpy_adaptions
Lukas Posch 4 years ago
parent
commit
023e067c59
  1. 4
      src/storm-parsers/parser/FormulaParser.cpp
  2. 28
      src/storm/logic/CloneVisitor.cpp
  3. 1
      src/storm/logic/CloneVisitor.h
  4. 1
      src/storm/logic/Formula.cpp
  5. 1
      src/storm/logic/Formulas.h
  6. 18
      src/storm/logic/LiftableTransitionRewardsVisitor.cpp
  7. 1
      src/storm/logic/LiftableTransitionRewardsVisitor.h
  8. 4
      src/storm/logic/ToExpressionVisitor.cpp
  9. 1
      src/storm/logic/ToExpressionVisitor.h
  10. 48
      src/storm/storage/jani/JSONExporter.cpp
  11. 1
      src/storm/storage/jani/JSONExporter.h

4
src/storm-parsers/parser/FormulaParser.cpp

@ -60,7 +60,7 @@ namespace storm {
storm::utility::openFile(filename, inputFileStream);
std::vector<storm::jani::Property> properties;
// Now try to parse the contents of the file.
try {
std::string fileContent((std::istreambuf_iterator<char>(inputFileStream)), (std::istreambuf_iterator<char>()));
@ -70,7 +70,7 @@ namespace storm {
storm::utility::closeFile(inputFileStream);
throw e;
}
// Close the stream in case everything went smoothly and return result.
storm::utility::closeFile(inputFileStream);
return properties;

28
src/storm/logic/CloneVisitor.cpp

@ -28,6 +28,34 @@ namespace storm {
return std::static_pointer_cast<Formula>(std::make_shared<BooleanLiteralFormula>(f));
}
boost::any CloneVisitor::visit(BoundedGloballyFormula const& f, boost::any const& data) const {
std::vector<boost::optional<TimeBound>> lowerBounds, upperBounds;
std::vector<TimeBoundReference> timeBoundReferences;
for (uint64_t i = 0; i < f.getDimension(); ++i) {
if (f.hasLowerBound(i)) {
lowerBounds.emplace_back(TimeBound(f.isLowerBoundStrict(i), f.getLowerBound(i)));
} else {
lowerBounds.emplace_back();
}
if (f.hasUpperBound(i)) {
upperBounds.emplace_back(TimeBound(f.isUpperBoundStrict(i), f.getUpperBound(i)));
} else {
upperBounds.emplace_back();
}
timeBoundReferences.push_back(f.getTimeBoundReference(i));
}
if (f.hasMultiDimensionalSubformulas()) {
std::vector<std::shared_ptr<Formula const>> subformulas;
for (uint64_t i = 0; i < f.getDimension(); ++i) {
subformulas.push_back(boost::any_cast<std::shared_ptr<Formula>>(f.getSubformula(i).accept(*this, data)));
}
return std::static_pointer_cast<Formula>(std::make_shared<BoundedGloballyFormula>(subformulas, lowerBounds, upperBounds, timeBoundReferences));
} else {
std::shared_ptr<Formula> subformula = boost::any_cast<std::shared_ptr<Formula>>(f.getSubformula().accept(*this, data));
return std::static_pointer_cast<Formula>(std::make_shared<BoundedGloballyFormula>(subformula, lowerBounds, upperBounds, timeBoundReferences));
}
}
boost::any CloneVisitor::visit(BoundedUntilFormula const& f, boost::any const& data) const {
std::vector<boost::optional<TimeBound>> lowerBounds, upperBounds;
std::vector<TimeBoundReference> timeBoundReferences;

1
src/storm/logic/CloneVisitor.h

@ -16,6 +16,7 @@ namespace storm {
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(BoundedGloballyFormula 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;

1
src/storm/logic/Formula.cpp

@ -377,7 +377,6 @@ namespace storm {
return dynamic_cast<NextFormula const&>(*this);
}
// TODO: find out why these casts are not valid
BoundedGloballyFormula& Formula::asBoundedGloballyFormula() {
return dynamic_cast<BoundedGloballyFormula&>(*this);
}

1
src/storm/logic/Formulas.h

@ -5,6 +5,7 @@
#include "storm/logic/BinaryPathFormula.h"
#include "storm/logic/BinaryStateFormula.h"
#include "storm/logic/BooleanLiteralFormula.h"
#include "storm/logic/BoundedGloballyFormula.h"
#include "storm/logic/BoundedUntilFormula.h"
#include "storm/logic/CumulativeRewardFormula.h"
#include "storm/logic/EventuallyFormula.h"

18
src/storm/logic/LiftableTransitionRewardsVisitor.cpp

@ -30,6 +30,24 @@ namespace storm {
return true;
}
boost::any LiftableTransitionRewardsVisitor::visit(BoundedGloballyFormula 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.getSubformula(i).accept(*this, data));
}
} else {
result = result && boost::any_cast<bool>(f.getSubformula().accept(*this, data));
}
return result;
}
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())) {

1
src/storm/logic/LiftableTransitionRewardsVisitor.h

@ -22,6 +22,7 @@ namespace storm {
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(BoundedGloballyFormula 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;

4
src/storm/logic/ToExpressionVisitor.cpp

@ -47,6 +47,10 @@ namespace storm {
return result;
}
boost::any ToExpressionVisitor::visit(BoundedGloballyFormula const&, boost::any const&) const {
STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Cannot assemble expression from formula that contains illegal elements.");
}
boost::any ToExpressionVisitor::visit(BoundedUntilFormula const&, boost::any const&) const {
STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Cannot assemble expression from formula that contains illegal elements.");
}

1
src/storm/logic/ToExpressionVisitor.h

@ -16,6 +16,7 @@ namespace storm {
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(BoundedGloballyFormula 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;

48
src/storm/storage/jani/JSONExporter.cpp

@ -212,6 +212,54 @@ namespace storm {
ExportJsonType opDecl(f.isTrueFormula() ? true : false);
return opDecl;
}
boost::any FormulaToJaniJson::visit(storm::logic::BoundedGloballyFormula const& f, boost::any const& data) const {
STORM_LOG_THROW(!f.hasMultiDimensionalSubformulas(), storm::exceptions::NotSupportedException, "Jani export of multi-dimensional bounded globally formulas is not supported.");
ExportJsonType opDecl;
opDecl["op"] = "G";
opDecl["exp"] = anyToJson(f.getSubformula().accept(*this, data));
bool hasStepBounds(false), hasTimeBounds(false);
std::vector<ExportJsonType> rewardBounds;
for (uint64_t i = 0; i < f.getDimension(); ++i) {
boost::optional<storm::expressions::Expression> lower, upper;
boost::optional<bool> lowerExclusive, upperExclusive;
if (f.hasLowerBound(i)) {
lower = f.getLowerBound(i);
lowerExclusive = f.isLowerBoundStrict(i);
}
if (f.hasUpperBound(i)) {
upper = f.getUpperBound(i);
upperExclusive = f.isUpperBoundStrict(i);
}
ExportJsonType propertyInterval = constructPropertyInterval(lower, lowerExclusive, upper, upperExclusive);
auto tbr = f.getTimeBoundReference(i);
if (tbr.isStepBound() || (model.isDiscreteTimeModel() && tbr.isTimeBound())) {
STORM_LOG_THROW(!hasStepBounds, storm::exceptions::NotSupportedException, "Jani export of until formulas with multiple step bounds is not supported.");
hasStepBounds = true;
opDecl["step-bounds"] = propertyInterval;
} else if(tbr.isRewardBound()) {
ExportJsonType rewbound;
rewbound["exp"] = buildExpression(model.getRewardModelExpression(tbr.getRewardName()), model.getConstants(), model.getGlobalVariables());
if (tbr.hasRewardAccumulation()) {
rewbound["accumulate"] = constructRewardAccumulation(tbr.getRewardAccumulation(), tbr.getRewardName());
} else {
rewbound["accumulate"] = constructStandardRewardAccumulation(tbr.getRewardName());
}
rewbound["bounds"] = propertyInterval;
rewardBounds.push_back(std::move(rewbound));
} else {
STORM_LOG_THROW(!hasTimeBounds, storm::exceptions::NotSupportedException, "Jani export of globally formulas with multiple time bounds is not supported.");
hasTimeBounds = true;
opDecl["time-bounds"] = propertyInterval;
}
}
if (!rewardBounds.empty()) {
opDecl["reward-bounds"] = ExportJsonType(rewardBounds);
}
return opDecl;
}
boost::any FormulaToJaniJson::visit(storm::logic::BoundedUntilFormula const& f, boost::any const& data) const {
STORM_LOG_THROW(!f.hasMultiDimensionalSubformulas(), storm::exceptions::NotSupportedException, "Jani export of multi-dimensional bounded until formulas is not supported.");
ExportJsonType opDecl;

1
src/storm/storage/jani/JSONExporter.h

@ -52,6 +52,7 @@ namespace storm {
virtual boost::any visit(storm::logic::AtomicLabelFormula const& f, boost::any const& data) const;
virtual boost::any visit(storm::logic::BinaryBooleanStateFormula const& f, boost::any const& data) const;
virtual boost::any visit(storm::logic::BooleanLiteralFormula const& f, boost::any const& data) const;
virtual boost::any visit(storm::logic::BoundedGloballyFormula const& f, boost::any const& data) const;
virtual boost::any visit(storm::logic::BoundedUntilFormula const& f, boost::any const& data) const;
virtual boost::any visit(storm::logic::ConditionalFormula const& f, boost::any const& data) const;
virtual boost::any visit(storm::logic::CumulativeRewardFormula const& f, boost::any const& data) const;

Loading…
Cancel
Save