Browse Source

bug fix bounded globally

tempestpy_adaptions
Lukas Posch 4 years ago
parent
commit
64861445fe
  1. 17
      src/storm/modelchecker/rpatl/helper/SparseSmgRpatlHelper.cpp
  2. 30
      src/storm/modelchecker/rpatl/helper/internal/BoundedGloballyGameViHelper.cpp
  3. 4
      src/storm/modelchecker/rpatl/helper/internal/BoundedGloballyGameViHelper.h

17
src/storm/modelchecker/rpatl/helper/SparseSmgRpatlHelper.cpp

@ -111,14 +111,15 @@ namespace storm {
auto solverEnv = env; auto solverEnv = env;
solverEnv.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration, false); solverEnv.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration, false);
// Initialize the solution vector.
std::vector<ValueType> x = std::vector<ValueType>(transitionMatrix.getRowGroupCount() - psiStates.getNumberOfSetBits(), storm::utility::zero<ValueType>());
// Relevant states are safe states - the psiStates. // Relevant states are safe states - the psiStates.
storm::storage::BitVector relevantStates = psiStates; storm::storage::BitVector relevantStates = psiStates;
std::vector<ValueType> b = transitionMatrix.getConstrainedRowGroupSumVector(relevantStates, relevantStates);
// Initialize the solution vector.
//std::vector<ValueType> x = std::vector<ValueType>(transitionMatrix.getRowGroupCount() - psiStates.getNumberOfSetBits(), storm::utility::zero<ValueType>());
std::vector<ValueType> x = std::vector<ValueType>(relevantStates.getNumberOfSetBits(), storm::utility::one<ValueType>());
//std::vector<ValueType> b = transitionMatrix.getConstrainedRowGroupSumVector(relevantStates, relevantStates);
std::vector<ValueType> b = std::vector<ValueType>(relevantStates.getNumberOfSetBits(), storm::utility::zero<ValueType>());
// Reduce the matrix to relevant states // Reduce the matrix to relevant states
storm::storage::SparseMatrix<ValueType> submatrix = transitionMatrix.getSubmatrix(true, relevantStates, relevantStates, false); storm::storage::SparseMatrix<ValueType> submatrix = transitionMatrix.getSubmatrix(true, relevantStates, relevantStates, false);
@ -142,10 +143,12 @@ namespace storm {
STORM_LOG_DEBUG("upperBound = " << upperBound); STORM_LOG_DEBUG("upperBound = " << upperBound);
// in case of 'G<1' or 'G<=0' the states with are initially 'safe' are filled with ones // in case of 'G<1' or 'G<=0' the states with are initially 'safe' are filled with ones
if(upperBound == 0)
if(upperBound > 0)
{ {
x = std::vector<ValueType>(relevantStates.size(), storm::utility::one<ValueType>());
} else {
/* x = std::vector<ValueType>(relevantStates.size(), storm::utility::one<ValueType>());
} else {*/
STORM_LOG_DEBUG("b = " << b);
STORM_LOG_DEBUG("x = " << x);
viHelper.performValueIteration(env, x, b, goal.direction(), upperBound); viHelper.performValueIteration(env, x, b, goal.direction(), upperBound);
} }

30
src/storm/modelchecker/rpatl/helper/internal/BoundedGloballyGameViHelper.cpp

@ -19,16 +19,25 @@ namespace storm {
template <typename ValueType> template <typename ValueType>
void BoundedGloballyGameViHelper<ValueType>::prepareSolversAndMultipliersReachability(const Environment& env) { void BoundedGloballyGameViHelper<ValueType>::prepareSolversAndMultipliersReachability(const Environment& env) {
_multiplier = storm::solver::MultiplierFactory<ValueType>().create(env, _transitionMatrix); _multiplier = storm::solver::MultiplierFactory<ValueType>().create(env, _transitionMatrix);
/*
_x1IsCurrent = false; _x1IsCurrent = false;
*/
} }
template <typename ValueType> template <typename ValueType>
void BoundedGloballyGameViHelper<ValueType>::performValueIteration(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> b, storm::solver::OptimizationDirection const dir, uint64_t upperBound) { void BoundedGloballyGameViHelper<ValueType>::performValueIteration(Environment const& env, std::vector<ValueType>& x, std::vector<ValueType> b, storm::solver::OptimizationDirection const dir, uint64_t upperBound) {
prepareSolversAndMultipliersReachability(env); prepareSolversAndMultipliersReachability(env);
_b = b; _b = b;
/*
_x1.assign(_transitionMatrix.getRowGroupCount(), storm::utility::zero<ValueType>()); _x1.assign(_transitionMatrix.getRowGroupCount(), storm::utility::zero<ValueType>());
*/
_x1 = x;
_x2 = _x1; _x2 = _x1;
/* STORM_LOG_DEBUG("_b = " << _b);
STORM_LOG_DEBUG("_x1 = " << _x1);
STORM_LOG_DEBUG("_x2 = " << _x2);*/
if (this->isProduceSchedulerSet()) { if (this->isProduceSchedulerSet()) {
if (!this->_producedOptimalChoices.is_initialized()) { if (!this->_producedOptimalChoices.is_initialized()) {
this->_producedOptimalChoices.emplace(); this->_producedOptimalChoices.emplace();
@ -37,15 +46,20 @@ namespace storm {
} }
for (uint64_t iter = 0; iter < upperBound; iter++) { for (uint64_t iter = 0; iter < upperBound; iter++) {
performIterationStep(env, dir); performIterationStep(env, dir);
/* STORM_LOG_DEBUG("After iteration " << iter << ":");
STORM_LOG_DEBUG("_x1 = " << _x1);
STORM_LOG_DEBUG("_x2 = " << _x2);*/
/* if (storm::utility::resources::isTerminate()) { /* if (storm::utility::resources::isTerminate()) {
break; break;
}*/ }*/
} }
/*
x = xNew(); x = xNew();
*/
x = _x1;
/* if (isProduceSchedulerSet()) { /* if (isProduceSchedulerSet()) {
// We will be doing one more iteration step and track scheduler choices this time. // We will be doing one more iteration step and track scheduler choices this time.
@ -58,18 +72,18 @@ namespace storm {
if (!_multiplier) { if (!_multiplier) {
prepareSolversAndMultipliersReachability(env); prepareSolversAndMultipliersReachability(env);
} }
_x1IsCurrent = !_x1IsCurrent;
/* _x1IsCurrent = !_x1IsCurrent;*/
// multiplyandreducegaussseidel // multiplyandreducegaussseidel
// Ax + b // Ax + b
if (choices == nullptr) { if (choices == nullptr) {
_multiplier->multiplyAndReduce(env, dir, xOld(), &_b, xNew(), nullptr, &_statesOfCoalition);
_multiplier->multiplyAndReduce(env, dir, _x1, &_b, _x1, nullptr, &_statesOfCoalition);
} else { } else {
// Also keep track of the choices made. // Also keep track of the choices made.
_multiplier->multiplyAndReduce(env, dir, xOld(), &_b, xNew(), choices, &_statesOfCoalition);
_multiplier->multiplyAndReduce(env, dir, _x1, &_b, _x1, choices, &_statesOfCoalition);
} }
// compare applyPointwise
/* // compare applyPointwise
storm::utility::vector::applyPointwise<ValueType, ValueType, ValueType>(xOld(), xNew(), xNew(), [&dir] (ValueType const& a, ValueType const& b) -> ValueType { storm::utility::vector::applyPointwise<ValueType, ValueType, ValueType>(xOld(), xNew(), xNew(), [&dir] (ValueType const& a, ValueType const& b) -> ValueType {
if(storm::solver::maximize(dir)) { if(storm::solver::maximize(dir)) {
if(a > b) return a; if(a > b) return a;
@ -78,7 +92,7 @@ namespace storm {
if(a > b) return a; if(a > b) return a;
else return b; else return b;
} }
});
});*/
} }
template <typename ValueType> template <typename ValueType>
@ -129,7 +143,7 @@ namespace storm {
return scheduler; return scheduler;
} }
template <typename ValueType>
/* template <typename ValueType>
std::vector<ValueType>& BoundedGloballyGameViHelper<ValueType>::xNew() { std::vector<ValueType>& BoundedGloballyGameViHelper<ValueType>::xNew() {
return _x1IsCurrent ? _x1 : _x2; return _x1IsCurrent ? _x1 : _x2;
} }
@ -147,7 +161,7 @@ namespace storm {
template <typename ValueType> template <typename ValueType>
std::vector<ValueType> const& BoundedGloballyGameViHelper<ValueType>::xOld() const { std::vector<ValueType> const& BoundedGloballyGameViHelper<ValueType>::xOld() const {
return _x1IsCurrent ? _x2 : _x1; return _x1IsCurrent ? _x2 : _x1;
}
}*/
template class BoundedGloballyGameViHelper<double>; template class BoundedGloballyGameViHelper<double>;
#ifdef STORM_HAVE_CARL #ifdef STORM_HAVE_CARL

4
src/storm/modelchecker/rpatl/helper/internal/BoundedGloballyGameViHelper.h

@ -45,12 +45,12 @@ namespace storm {
private: private:
void performIterationStep(Environment const& env, storm::solver::OptimizationDirection const dir, std::vector<uint64_t>* choices = nullptr); void performIterationStep(Environment const& env, storm::solver::OptimizationDirection const dir, std::vector<uint64_t>* choices = nullptr);
std::vector<ValueType>& xNew();
/* std::vector<ValueType>& xNew();
std::vector<ValueType> const& xNew() const; std::vector<ValueType> const& xNew() const;
std::vector<ValueType>& xOld(); std::vector<ValueType>& xOld();
std::vector<ValueType> const& xOld() const; std::vector<ValueType> const& xOld() const;
bool _x1IsCurrent;
bool _x1IsCurrent;*/
/*! /*!
* @pre before calling this, a computation call should have been performed during which scheduler production was enabled. * @pre before calling this, a computation call should have been performed during which scheduler production was enabled.

Loading…
Cancel
Save