Browse Source

fixed issue in JANI abstraction

tempestpy_adaptions
dehnert 8 years ago
parent
commit
5b4db6f002
  1. 3
      src/storm/abstraction/MenuGameRefiner.cpp
  2. 6
      src/storm/abstraction/jani/EdgeAbstractor.cpp
  3. 2
      src/storm/cli/entrypoints.h
  4. 3
      src/storm/modelchecker/abstraction/GameBasedMdpModelChecker.cpp
  5. 79
      src/storm/storage/expressions/LinearityCheckVisitor.cpp
  6. 3
      src/storm/storage/expressions/LinearityCheckVisitor.h
  7. 2
      src/storm/storage/jani/Assignment.cpp
  8. 2
      src/storm/storage/jani/Model.cpp
  9. 2
      src/storm/storage/jani/TemplateEdge.cpp

3
src/storm/abstraction/MenuGameRefiner.cpp

@ -706,6 +706,9 @@ namespace storm {
void MenuGameRefiner<Type, ValueType>::performRefinement(std::vector<RefinementCommand> const& refinementCommands) const {
for (auto const& command : refinementCommands) {
STORM_LOG_TRACE("Refining with " << command.getPredicates().size() << " predicates.");
for (auto const& predicate : command.getPredicates()) {
STORM_LOG_TRACE(predicate);
}
abstractor.get().refine(command);
}

6
src/storm/abstraction/jani/EdgeAbstractor.cpp

@ -662,10 +662,11 @@ namespace storm {
storm::dd::Add<DdType, ValueType> EdgeAbstractor<DdType, ValueType>::getEdgeDecoratorAdd(boost::optional<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& locationVariables) const {
storm::dd::Add<DdType, ValueType> result = this->getAbstractionInformation().getDdManager().template getAddZero<ValueType>();
for (uint_fast64_t destinationIndex = 0; destinationIndex < edge.get().getNumberOfDestinations(); ++destinationIndex) {
result += this->getAbstractionInformation().encodeAux(destinationIndex, 0, this->getAbstractionInformation().getAuxVariableCount()).template toAdd<ValueType>() * this->getAbstractionInformation().getDdManager().getConstant(evaluator.asRational(edge.get().getDestination(destinationIndex).getProbability()));
storm::dd::Add<DdType, ValueType> tmp = this->getAbstractionInformation().encodeAux(destinationIndex, 0, this->getAbstractionInformation().getAuxVariableCount()).template toAdd<ValueType>() * this->getAbstractionInformation().getDdManager().getConstant(evaluator.asRational(edge.get().getDestination(destinationIndex).getProbability()));
if (locationVariables) {
result *= this->getAbstractionInformation().encodeLocation(locationVariables.get().second, edge.get().getDestination(destinationIndex).getLocationIndex()).template toAdd<ValueType>();
tmp *= this->getAbstractionInformation().encodeLocation(locationVariables.get().second, edge.get().getDestination(destinationIndex).getLocationIndex()).template toAdd<ValueType>();
}
result += tmp;
}
storm::dd::Add<DdType, ValueType> tmp = this->getAbstractionInformation().getDdManager().template getAddOne<ValueType>();
@ -675,6 +676,7 @@ namespace storm {
tmp *= this->getAbstractionInformation().encodePlayer1Choice(edgeId, this->getAbstractionInformation().getPlayer1VariableCount()).template toAdd<ValueType>();
result *= tmp;
return result;
}

2
src/storm/cli/entrypoints.h

@ -129,7 +129,7 @@ namespace storm {
modelCheckingWatch.stop();
if (result) {
STORM_PRINT_AND_LOG("Result (initial states): ");
STORM_PRINT_AND_LOG(*result);
STORM_PRINT_AND_LOG(*result << std::endl);
STORM_PRINT_AND_LOG("Time for model checking: " << modelCheckingWatch << "." << std::endl);
} else {
STORM_PRINT_AND_LOG(" skipped, because the modelling formalism is currently unsupported." << std::endl);

3
src/storm/modelchecker/abstraction/GameBasedMdpModelChecker.cpp

@ -342,7 +342,6 @@ namespace storm {
storm::dd::Bdd<Type> globalConstraintStates = abstractor->getStates(constraintExpression);
storm::dd::Bdd<Type> globalTargetStates = abstractor->getStates(targetStateExpression);
// globalTargetStates.template toAdd<ValueType>().exportToDot("target.dot");
// Enter the main-loop of abstraction refinement.
boost::optional<QualitativeResultMinMax<Type>> previousQualitativeResult = boost::none;
@ -368,7 +367,9 @@ namespace storm {
}
// #ifdef LOCAL_DEBUG
// targetStates.template toAdd<ValueType>().exportToDot("target.dot");
// abstractor->exportToDot("game" + std::to_string(iterations) + ".dot", targetStates, game.getManager().getBddOne());
// game.getReachableStates().template toAdd<ValueType>().exportToDot("reach.dot");
// #endif
// (3) compute all states with probability 0/1 wrt. to the two different player 2 goals (min/max).

79
src/storm/storage/expressions/LinearityCheckVisitor.cpp

@ -12,19 +12,44 @@ namespace storm {
// Intentionally left empty.
}
bool LinearityCheckVisitor::check(Expression const& expression) {
LinearityStatus result = boost::any_cast<LinearityStatus>(expression.getBaseExpression().accept(*this, boost::none));
bool LinearityCheckVisitor::check(Expression const& expression, bool booleanIsLinear) {
LinearityStatus result = boost::any_cast<LinearityStatus>(expression.getBaseExpression().accept(*this, booleanIsLinear));
return result == LinearityStatus::LinearWithoutVariables || result == LinearityStatus::LinearContainsVariables;
}
boost::any LinearityCheckVisitor::visit(IfThenElseExpression const&, boost::any const&) {
// An if-then-else expression is never linear.
return LinearityStatus::NonLinear;
boost::any LinearityCheckVisitor::visit(IfThenElseExpression const& expression, boost::any const& data) {
bool booleanIsLinear = boost::any_cast<bool>(data);
if (booleanIsLinear) {
auto conditionResult = boost::any_cast<LinearityStatus>(expression.getCondition()->accept(*this, booleanIsLinear));
auto thenResult = boost::any_cast<LinearityStatus>(expression.getThenExpression()->accept(*this, booleanIsLinear));
auto elseResult = boost::any_cast<LinearityStatus>(expression.getElseExpression()->accept(*this, booleanIsLinear));
if (conditionResult != LinearityStatus::NonLinear && thenResult != LinearityStatus::NonLinear && elseResult != LinearityStatus::NonLinear) {
return LinearityStatus::LinearContainsVariables;
} else {
return LinearityStatus::NonLinear;
}
} else {
return LinearityStatus::NonLinear;
}
}
boost::any LinearityCheckVisitor::visit(BinaryBooleanFunctionExpression const&, boost::any const&) {
// Boolean function applications are not allowed in linear expressions.
return LinearityStatus::NonLinear;
boost::any LinearityCheckVisitor::visit(BinaryBooleanFunctionExpression const& expression, boost::any const& data) {
bool booleanIsLinear = boost::any_cast<bool>(data);
if (booleanIsLinear) {
auto leftResult = boost::any_cast<LinearityStatus>(expression.getFirstOperand()->accept(*this, booleanIsLinear));
auto rightResult = boost::any_cast<LinearityStatus>(expression.getSecondOperand()->accept(*this, booleanIsLinear));
if (leftResult != LinearityStatus::NonLinear && rightResult != LinearityStatus::NonLinear) {
return LinearityStatus::LinearContainsVariables;
} else {
return LinearityStatus::NonLinear;
}
} else {
return LinearityStatus::NonLinear;
}
}
boost::any LinearityCheckVisitor::visit(BinaryNumericalFunctionExpression const& expression, boost::any const& data) {
@ -56,15 +81,37 @@ namespace storm {
STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Illegal binary numerical expression operator.");
}
boost::any LinearityCheckVisitor::visit(BinaryRelationExpression const&, boost::any const&) {
return LinearityStatus::NonLinear;
boost::any LinearityCheckVisitor::visit(BinaryRelationExpression const& expression, boost::any const& data) {
bool booleanIsLinear = boost::any_cast<bool>(data);
if (booleanIsLinear) {
auto leftResult = boost::any_cast<LinearityStatus>(expression.getFirstOperand()->accept(*this, booleanIsLinear));
auto rightResult = boost::any_cast<LinearityStatus>(expression.getSecondOperand()->accept(*this, booleanIsLinear));
if (leftResult != LinearityStatus::NonLinear && rightResult != LinearityStatus::NonLinear) {
return LinearityStatus::LinearContainsVariables;
} else {
return LinearityStatus::NonLinear;
}
} else {
return LinearityStatus::NonLinear;
}
}
boost::any LinearityCheckVisitor::visit(VariableExpression const&, boost::any const&) {
return LinearityStatus::LinearContainsVariables;
}
boost::any LinearityCheckVisitor::visit(UnaryBooleanFunctionExpression const&, boost::any const&) {
boost::any LinearityCheckVisitor::visit(UnaryBooleanFunctionExpression const& expression, boost::any const& data) {
bool booleanIsLinear = boost::any_cast<bool>(data);
if (booleanIsLinear) {
return boost::any_cast<LinearityStatus>(expression.getOperand()->accept(*this, booleanIsLinear));
} else {
return LinearityStatus::NonLinear;
}
// Boolean function applications are not allowed in linear expressions.
return LinearityStatus::NonLinear;
}
@ -78,8 +125,14 @@ namespace storm {
STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException, "Illegal unary numerical expression operator.");
}
boost::any LinearityCheckVisitor::visit(BooleanLiteralExpression const&, boost::any const&) {
return LinearityStatus::NonLinear;
boost::any LinearityCheckVisitor::visit(BooleanLiteralExpression const& expression, boost::any const& data) {
bool booleanIsLinear = boost::any_cast<bool>(data);
if (booleanIsLinear) {
return LinearityStatus::LinearWithoutVariables;
} else {
return LinearityStatus::NonLinear;
}
}
boost::any LinearityCheckVisitor::visit(IntegerLiteralExpression const&, boost::any const&) {

3
src/storm/storage/expressions/LinearityCheckVisitor.h

@ -17,8 +17,9 @@ namespace storm {
* Checks that the given expression is linear.
*
* @param expression The expression to check for linearity.
* @param booleanIsLinear A flag indicating whether boolean components are considered linear.
*/
bool check(Expression const& expression);
bool check(Expression const& expression, bool booleanIsLinear = false);
virtual boost::any visit(IfThenElseExpression const& expression, boost::any const& data) override;
virtual boost::any visit(BinaryBooleanFunctionExpression const& expression, boost::any const& data) override;

2
src/storm/storage/jani/Assignment.cpp

@ -46,7 +46,7 @@ namespace storm {
bool Assignment::isLinear() const {
storm::expressions::LinearityCheckVisitor linearityChecker;
return linearityChecker.check(this->getAssignedExpression());
return linearityChecker.check(this->getAssignedExpression(), true);
}
std::ostream& operator<<(std::ostream& stream, Assignment const& assignment) {

2
src/storm/storage/jani/Model.cpp

@ -1124,7 +1124,7 @@ namespace storm {
bool result = true;
storm::expressions::LinearityCheckVisitor linearityChecker;
result &= linearityChecker.check(this->getInitialStatesExpression());
result &= linearityChecker.check(this->getInitialStatesExpression(), true);
for (auto const& automaton : this->getAutomata()) {
result &= automaton.isLinear();

2
src/storm/storage/jani/TemplateEdge.cpp

@ -139,7 +139,7 @@ namespace storm {
bool TemplateEdge::isLinear() const {
storm::expressions::LinearityCheckVisitor linearityChecker;
bool result = linearityChecker.check(this->getGuard());
bool result = linearityChecker.check(this->getGuard(), true);
for (auto const& destination : destinations) {
result &= destination.isLinear();
}

Loading…
Cancel
Save