Browse Source

added functionality to sparse MDP helper to compute until probabilities just for maybe states (and produce the corresponding scheduler)

Former-commit-id: 79aae02a13
tempestpy_adaptions
dehnert 9 years ago
parent
commit
3727018ef4
  1. 6
      src/modelchecker/prctl/SparseMdpPrctlModelChecker.cpp
  2. 34
      src/modelchecker/prctl/helper/SparseMdpPrctlHelper.cpp
  3. 2
      src/modelchecker/prctl/helper/SparseMdpPrctlHelper.h
  4. 8
      src/solver/MinMaxLinearEquationSolver.cpp
  5. 7
      src/solver/MinMaxLinearEquationSolver.h
  6. 26
      test/functional/modelchecker/GmmxxMdpPrctlModelCheckerTest.cpp

6
src/modelchecker/prctl/SparseMdpPrctlModelChecker.cpp

@ -88,7 +88,11 @@ namespace storm {
ExplicitQualitativeCheckResult const& leftResult = leftResultPointer->asExplicitQualitativeCheckResult();
ExplicitQualitativeCheckResult const& rightResult = rightResultPointer->asExplicitQualitativeCheckResult();
auto ret = storm::modelchecker::helper::SparseMdpPrctlHelper<ValueType>::computeUntilProbabilities(checkTask.getOptimizationDirection(), this->getModel().getTransitionMatrix(), this->getModel().getBackwardTransitions(), leftResult.getTruthValuesVector(), rightResult.getTruthValuesVector(), checkTask.isQualitativeSet(), checkTask.isProduceSchedulersSet(), *minMaxLinearEquationSolverFactory);
return std::unique_ptr<CheckResult>(new ExplicitQuantitativeCheckResult<ValueType>(std::move(ret.values)));
std::unique_ptr<CheckResult> result(new ExplicitQuantitativeCheckResult<ValueType>(std::move(ret.values)));
if (checkTask.isProduceSchedulersSet() && ret.scheduler) {
result->asExplicitQuantitativeCheckResult<ValueType>().setScheduler(std::move(ret.scheduler));
}
return result;
}
template<typename SparseMdpModelType>

34
src/modelchecker/prctl/helper/SparseMdpPrctlHelper.cpp

@ -120,19 +120,13 @@ namespace storm {
// the accumulated probability of going from state i to some 'yes' state.
std::vector<ValueType> b = transitionMatrix.getConstrainedRowGroupSumVector(maybeStates, statesWithProbability1);
// Create vector for results for maybe states.
std::vector<ValueType> x(maybeStates.getNumberOfSetBits());
// Solve the corresponding system of equations.
std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType>> solver = storm::solver::configureMinMaxLinearEquationSolver(goal, minMaxLinearEquationSolverFactory, submatrix);
solver->setTrackScheduler(produceScheduler);
solver->solveEquationSystem(x, b);
MDPSparseModelCheckingHelperReturnType<ValueType> resultForMaybeStates = computeUntilProbabilitiesOnlyMaybeStates(goal, submatrix, b, produceScheduler, minMaxLinearEquationSolverFactory);
// Set values of resulting vector according to result.
storm::utility::vector::setVectorValues<ValueType>(result, maybeStates, x);
storm::utility::vector::setVectorValues<ValueType>(result, maybeStates, resultForMaybeStates.values);
if (produceScheduler) {
storm::storage::Scheduler const& subscheduler = solver->getScheduler();
storm::storage::Scheduler const& subscheduler = *resultForMaybeStates.scheduler;
uint_fast64_t currentSubState = 0;
for (auto maybeState : maybeStates) {
scheduler->setChoice(maybeState, subscheduler.getChoice(currentSubState));
@ -158,6 +152,26 @@ namespace storm {
return MDPSparseModelCheckingHelperReturnType<ValueType>(std::move(result), std::move(scheduler));
}
template<typename ValueType>
MDPSparseModelCheckingHelperReturnType<ValueType> SparseMdpPrctlHelper<ValueType>::computeUntilProbabilitiesOnlyMaybeStates(storm::solver::SolveGoal const& goal, storm::storage::SparseMatrix<ValueType> const& submatrix, std::vector<ValueType> const& b, bool produceScheduler, storm::utility::solver::MinMaxLinearEquationSolverFactory<ValueType> const& minMaxLinearEquationSolverFactory) {
// If requested, we will produce a scheduler.
std::unique_ptr<storm::storage::TotalScheduler> scheduler;
// Create vector for results for maybe states.
std::vector<ValueType> x(submatrix.getRowGroupCount());
// Solve the corresponding system of equations.
std::unique_ptr<storm::solver::MinMaxLinearEquationSolver<ValueType>> solver = storm::solver::configureMinMaxLinearEquationSolver(goal, minMaxLinearEquationSolverFactory, submatrix);
solver->setTrackScheduler(produceScheduler);
solver->solveEquationSystem(x, b);
if (produceScheduler) {
scheduler = std::make_unique<storm::storage::TotalScheduler>(std::move(solver->getScheduler()));
}
return MDPSparseModelCheckingHelperReturnType<ValueType>(std::move(x), std::move(scheduler));
}
template<typename ValueType>
MDPSparseModelCheckingHelperReturnType<ValueType> SparseMdpPrctlHelper<ValueType>::computeUntilProbabilities(OptimizationDirection dir, storm::storage::SparseMatrix<ValueType> const& transitionMatrix, storm::storage::SparseMatrix<ValueType> const& backwardTransitions, storm::storage::BitVector const& phiStates, storm::storage::BitVector const& psiStates, bool qualitative, bool produceScheduler, storm::utility::solver::MinMaxLinearEquationSolverFactory<ValueType> const& minMaxLinearEquationSolverFactory) {

2
src/modelchecker/prctl/helper/SparseMdpPrctlHelper.h

@ -37,6 +37,8 @@ namespace storm {
static std::vector<ValueType> computeNextProbabilities(OptimizationDirection dir, storm::storage::SparseMatrix<ValueType> const& transitionMatrix, storm::storage::BitVector const& nextStates, storm::utility::solver::MinMaxLinearEquationSolverFactory<ValueType> const& minMaxLinearEquationSolverFactory);
static MDPSparseModelCheckingHelperReturnType<ValueType> computeUntilProbabilities(OptimizationDirection dir, storm::storage::SparseMatrix<ValueType> const& transitionMatrix, storm::storage::SparseMatrix<ValueType> const& backwardTransitions, storm::storage::BitVector const& phiStates, storm::storage::BitVector const& psiStates, bool qualitative, bool produceScheduler, storm::utility::solver::MinMaxLinearEquationSolverFactory<ValueType> const& minMaxLinearEquationSolverFactory);
static MDPSparseModelCheckingHelperReturnType<ValueType> computeUntilProbabilitiesOnlyMaybeStates(storm::solver::SolveGoal const& goal, storm::storage::SparseMatrix<ValueType> const& submatrix, std::vector<ValueType> const& b, bool produceScheduler, storm::utility::solver::MinMaxLinearEquationSolverFactory<ValueType> const& minMaxLinearEquationSolverFactory);
static MDPSparseModelCheckingHelperReturnType<ValueType> computeUntilProbabilities(storm::solver::SolveGoal const& goal, storm::storage::SparseMatrix<ValueType> const& transitionMatrix, storm::storage::SparseMatrix<ValueType> const& backwardTransitions, storm::storage::BitVector const& phiStates, storm::storage::BitVector const& psiStates, bool qualitative, bool produceScheduler, storm::utility::solver::MinMaxLinearEquationSolverFactory<ValueType> const& minMaxLinearEquationSolverFactory);

8
src/solver/MinMaxLinearEquationSolver.cpp

@ -34,7 +34,13 @@ namespace storm {
}
template<typename ValueType>
storm::storage::Scheduler const& AbstractMinMaxLinearEquationSolver<ValueType>::getScheduler() const {
storm::storage::TotalScheduler const& AbstractMinMaxLinearEquationSolver<ValueType>::getScheduler() const {
STORM_LOG_THROW(scheduler, storm::exceptions::InvalidSettingsException, "Cannot retrieve scheduler, because none was generated.");
return *scheduler.get();
}
template<typename ValueType>
storm::storage::TotalScheduler& AbstractMinMaxLinearEquationSolver<ValueType>::getScheduler() {
STORM_LOG_THROW(scheduler, storm::exceptions::InvalidSettingsException, "Cannot retrieve scheduler, because none was generated.");
return *scheduler.get();
}

7
src/solver/MinMaxLinearEquationSolver.h

@ -10,7 +10,7 @@
#include "src/solver/AbstractEquationSolver.h"
#include "src/solver/SolverSelectionOptions.h"
#include "src/storage/sparse/StateType.h"
#include "src/storage/Scheduler.h"
#include "src/storage/TotalScheduler.h"
#include "src/solver/OptimizationDirection.h"
#include "src/exceptions/InvalidSettingsException.h"
@ -32,7 +32,8 @@ namespace storm {
bool isTrackSchedulerSet() const;
bool hasScheduler() const;
storm::storage::Scheduler const& getScheduler() const;
storm::storage::TotalScheduler const& getScheduler() const;
storm::storage::TotalScheduler& getScheduler();
void setOptimizationDirection(OptimizationDirection d);
void resetOptimizationDirection();
@ -59,7 +60,7 @@ namespace storm {
bool trackScheduler;
// The scheduler (if it could be successfully generated).
mutable boost::optional<std::unique_ptr<storm::storage::Scheduler>> scheduler;
mutable boost::optional<std::unique_ptr<storm::storage::TotalScheduler>> scheduler;
};
/*!

26
test/functional/modelchecker/GmmxxMdpPrctlModelCheckerTest.cpp

@ -193,7 +193,7 @@ TEST(GmmxxMdpPrctlModelCheckerTest, AsynchronousLeader) {
TEST(GmmxxMdpPrctlModelCheckerTest, SchedulerGeneration) {
storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/modelchecker/scheduler_generation.nm");
// A parser that we use for conveniently constructing the formulas.
storm::parser::FormulaParser formulaParser;
@ -206,7 +206,7 @@ TEST(GmmxxMdpPrctlModelCheckerTest, SchedulerGeneration) {
std::shared_ptr<storm::models::sparse::Mdp<double>> mdp = model->as<storm::models::sparse::Mdp<double>>();
EXPECT_EQ(7ul, mdp->getNumberOfChoices());
auto solverFactory = std::make_unique<storm::utility::solver::MinMaxLinearEquationSolverFactory<double>>(storm::solver::EquationSolverTypeSelection::Gmmxx);
solverFactory->setPreferredTechnique(storm::solver::MinMaxTechniqueSelection::PolicyIteration);
storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<double>> checker(*mdp, std::move(solverFactory));
@ -218,9 +218,25 @@ TEST(GmmxxMdpPrctlModelCheckerTest, SchedulerGeneration) {
std::unique_ptr<storm::modelchecker::CheckResult> result = checker.check(checkTask);
ASSERT_TRUE(result->isExplicitQuantitativeCheckResult());
ASSERT_TRUE(result->asExplicitQuantitativeCheckResult<double>().hasScheduler());
storm::storage::Scheduler const& scheduler = result->asExplicitQuantitativeCheckResult<double>().getScheduler();
EXPECT_EQ(0, scheduler.getChoice(0));
EXPECT_EQ(1, scheduler.getChoice(1));
EXPECT_EQ(0, scheduler.getChoice(2));
EXPECT_EQ(0, scheduler.getChoice(3));
formula = formulaParser.parseSingleFormulaFromString("Pmax=? [F \"target\"]");
checkTask.replaceFormula(*formula);
result = checker.check(checkTask);
checkTask = storm::modelchecker::CheckTask<storm::logic::Formula>(*formula);
checkTask.setProduceSchedulers(true);
result = checker.check(checkTask);
ASSERT_TRUE(result->isExplicitQuantitativeCheckResult());
ASSERT_TRUE(result->asExplicitQuantitativeCheckResult<double>().hasScheduler());
storm::storage::Scheduler const& scheduler2 = result->asExplicitQuantitativeCheckResult<double>().getScheduler();
EXPECT_EQ(1, scheduler2.getChoice(0));
EXPECT_EQ(2, scheduler2.getChoice(1));
EXPECT_EQ(0, scheduler2.getChoice(2));
EXPECT_EQ(0, scheduler2.getChoice(3));
}
Loading…
Cancel
Save