From 43eebf8e056c3d4eb1e53ef29a8ac235fc37d761 Mon Sep 17 00:00:00 2001 From: Jip Spel Date: Fri, 31 Aug 2018 12:35:14 +0200 Subject: [PATCH] Return tuple and add assumptions --- src/storm-pars-cli/storm-pars.cpp | 22 ++++++++++++++++----- src/storm-pars/analysis/Lattice.h | 3 --- src/storm-pars/analysis/LatticeExtender.cpp | 17 +++++++--------- src/storm-pars/analysis/LatticeExtender.h | 6 +++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/storm-pars-cli/storm-pars.cpp b/src/storm-pars-cli/storm-pars.cpp index b14285761..06f5a18c9 100644 --- a/src/storm-pars-cli/storm-pars.cpp +++ b/src/storm-pars-cli/storm-pars.cpp @@ -612,15 +612,27 @@ namespace storm { // Transform to Lattice storm::utility::Stopwatch latticeWatch(true); storm::analysis::LatticeExtender> extender = storm::analysis::LatticeExtender>(sparseModel); - storm::analysis::Lattice* lattice = extender.toLattice(formulas); + std::tuple criticalPair = extender.toLattice(formulas); // Declare variables for all states std::shared_ptr expressionManager(new storm::expressions::ExpressionManager()); - for (uint_fast64_t i = 0; i < sparseModel.get()->getNumberOfStates(); ++i) { + for (uint_fast64_t i = 0; i < sparseModel->getNumberOfStates(); ++i) { expressionManager->declareFreshIntegerVariable(); } -// std::set assumptions; -// extender.extendLattice(lattice, expressionManager, assumptions); + + // Make assumptions + std::set assumptions; + while (std::get<1>(criticalPair) != sparseModel->getNumberOfStates()) { + storm::expressions::Variable var1 = expressionManager->getVariable("_x" + std::to_string(std::get<1>(criticalPair))); + storm::expressions::Variable var2 = expressionManager->getVariable("_x" + std::to_string(std::get<2>(criticalPair))); + auto assumption = new storm::expressions::BinaryRelationExpression(*expressionManager, var1.getType(), + var1.getExpression().getBaseExpressionPointer(), var2.getExpression().getBaseExpressionPointer(), + storm::expressions::BinaryRelationExpression::RelationType::Greater); + assumptions.insert(assumption); + criticalPair = extender.extendLattice(std::get<0>(criticalPair), expressionManager, assumptions); + } + auto lattice = std::get<0>(criticalPair); + latticeWatch.stop(); STORM_PRINT(std::endl << "Time for lattice creation: " << latticeWatch << "." << std::endl << std::endl); @@ -631,7 +643,7 @@ namespace storm { myfile.close(); // Monotonicity? - auto matrix = sparseModel.get()->getTransitionMatrix(); + auto matrix = sparseModel->getTransitionMatrix(); storm::utility::Stopwatch monotonicityWatch(true); std::map> varsMonotone = analyseMonotonicity(lattice, matrix); monotonicityWatch.stop(); diff --git a/src/storm-pars/analysis/Lattice.h b/src/storm-pars/analysis/Lattice.h index 57fc43e13..dcfa8c552 100644 --- a/src/storm-pars/analysis/Lattice.h +++ b/src/storm-pars/analysis/Lattice.h @@ -11,9 +11,6 @@ #include "storm/storage/BitVector.h" - - - namespace storm { namespace analysis { class Lattice { diff --git a/src/storm-pars/analysis/LatticeExtender.cpp b/src/storm-pars/analysis/LatticeExtender.cpp index 921e66d42..fdb4471a8 100644 --- a/src/storm-pars/analysis/LatticeExtender.cpp +++ b/src/storm-pars/analysis/LatticeExtender.cpp @@ -30,7 +30,7 @@ namespace storm { } template - storm::analysis::Lattice* LatticeExtender::toLattice(std::vector> formulas) { + std::tuple LatticeExtender::toLattice(std::vector> formulas) { STORM_LOG_THROW((++formulas.begin()) == formulas.end(), storm::exceptions::NotSupportedException, "Only one formula allowed for monotonicity analysis"); STORM_LOG_THROW((*(formulas[0])).isProbabilityOperatorFormula() && ((*(formulas[0])).asProbabilityOperatorFormula().getSubformula().isUntilFormula() @@ -77,14 +77,15 @@ namespace storm { } template - storm::analysis::Lattice* LatticeExtender::extendLattice(storm::analysis::Lattice* lattice) { + std::tuple LatticeExtender::extendLattice(storm::analysis::Lattice* lattice) { std::shared_ptr expressionManager(new storm::expressions::ExpressionManager()); std::set assumptions; return this->extendLattice(lattice, expressionManager, assumptions); } template - storm::analysis::Lattice* LatticeExtender::extendLattice(storm::analysis::Lattice* lattice, std::shared_ptr expressionManager, std::set assumptions) { + std::tuple LatticeExtender::extendLattice(storm::analysis::Lattice* lattice, std::shared_ptr expressionManager, std::set assumptions) { + auto numberOfStates = this->model->getNumberOfStates(); // First handle assumptions for (auto itr = assumptions.begin(); itr != assumptions.end(); ++itr) { storm::expressions::BinaryRelationExpression expr = *(*itr); @@ -114,8 +115,6 @@ namespace storm { // Create a copy of the states already present in the lattice. storm::storage::BitVector seenStates = (lattice->getAddedStates()); - - auto numberOfStates = this->model->getNumberOfStates(); storm::storage::BitVector oldStates(numberOfStates); while (oldStates != seenStates) { @@ -155,17 +154,15 @@ namespace storm { // the successors are at the same level lattice->addToNode(stateNumber, lattice->getNode(successor1)); } else { - // TODO: create critical pair + return std::make_tuple(lattice, successor1, successor2); } seenStates.set(stateNumber); } } } - // TODO allow returning critical pair - return lattice; + return std::make_tuple(lattice, numberOfStates, numberOfStates); } template class LatticeExtender>; -// template class LatticeExtender>; } -} \ No newline at end of file +} diff --git a/src/storm-pars/analysis/LatticeExtender.h b/src/storm-pars/analysis/LatticeExtender.h index 37c39dc2a..9c854b4f5 100644 --- a/src/storm-pars/analysis/LatticeExtender.h +++ b/src/storm-pars/analysis/LatticeExtender.h @@ -23,16 +23,16 @@ namespace storm { public: LatticeExtender(std::shared_ptr model); - storm::analysis::Lattice* toLattice(std::vector> formulas); + std::tuple toLattice(std::vector> formulas); - storm::analysis::Lattice* extendLattice(storm::analysis::Lattice* lattice, std::shared_ptr expressionManager, std::set assumptions); + std::tuple extendLattice(storm::analysis::Lattice* lattice, std::shared_ptr expressionManager, std::set assumptions); private: std::shared_ptr model; std::map stateMap; - storm::analysis::Lattice* extendLattice(storm::analysis::Lattice* lattice); + std::tuple extendLattice(storm::analysis::Lattice* lattice); }; }