@ -179,7 +179,7 @@ namespace storm {
storm : : storage : : Scheduler < typename StandardPcaaWeightVectorChecker < SparseModelType > : : ValueType > StandardPcaaWeightVectorChecker < SparseModelType > : : computeScheduler ( ) const {
storm : : storage : : Scheduler < typename StandardPcaaWeightVectorChecker < SparseModelType > : : ValueType > StandardPcaaWeightVectorChecker < SparseModelType > : : computeScheduler ( ) const {
STORM_LOG_THROW ( this - > checkHasBeenCalled , storm : : exceptions : : IllegalFunctionCallException , " Tried to retrieve results but check(..) has not been called before. " ) ;
STORM_LOG_THROW ( this - > checkHasBeenCalled , storm : : exceptions : : IllegalFunctionCallException , " Tried to retrieve results but check(..) has not been called before. " ) ;
for ( auto const & obj : this - > objectives ) {
for ( auto const & obj : this - > objectives ) {
STORM_LOG_THROW ( obj . formula - > getSubformula ( ) . isTotalRewardFormula ( ) , storm : : exceptions : : NotImplementedException , " Scheduler retrival is only implemented for objectives without time-bound. " ) ;
STORM_LOG_THROW ( obj . formula - > getSubformula ( ) . isTotalRewardFormula ( ) | | obj . formula - > getSubformula ( ) . isLongRunAverageRewardFormula ( ) , storm : : exceptions : : NotImplementedException , " Scheduler retrival is only implemented for objectives without time-bound. " ) ;
}
}
storm : : storage : : Scheduler < ValueType > result ( this - > optimalChoices . size ( ) ) ;
storm : : storage : : Scheduler < ValueType > result ( this - > optimalChoices . size ( ) ) ;
@ -291,7 +291,7 @@ namespace storm {
void StandardPcaaWeightVectorChecker < SparseModelType > : : infiniteHorizonWeightedPhase ( Environment const & env , std : : vector < ValueType > const & weightedActionRewardVector , boost : : optional < std : : vector < ValueType > > const & weightedStateRewardVector ) {
void StandardPcaaWeightVectorChecker < SparseModelType > : : infiniteHorizonWeightedPhase ( Environment const & env , std : : vector < ValueType > const & weightedActionRewardVector , boost : : optional < std : : vector < ValueType > > const & weightedStateRewardVector ) {
// Compute the optimal (weighted) lra value for each mec, keeping track of the optimal choices
// Compute the optimal (weighted) lra value for each mec, keeping track of the optimal choices
STORM_LOG_ASSERT ( lraMecDecomposition , " Mec decomposition for lra computations not initialized. " ) ;
STORM_LOG_ASSERT ( lraMecDecomposition , " Mec decomposition for lra computations not initialized. " ) ;
storm : : modelchecker : : helper : : SparseNondeterministicInfiniteHorizonHelper < ValueType > helper = createNondetInfiniteHorizonHelper ( ) ;
storm : : modelchecker : : helper : : SparseNondeterministicInfiniteHorizonHelper < ValueType > helper = createNondetInfiniteHorizonHelper ( this - > transitionMatrix ) ;
helper . provideLongRunComponentDecomposition ( lraMecDecomposition - > mecs ) ;
helper . provideLongRunComponentDecomposition ( lraMecDecomposition - > mecs ) ;
helper . setOptimizationDirection ( storm : : solver : : OptimizationDirection : : Maximize ) ;
helper . setOptimizationDirection ( storm : : solver : : OptimizationDirection : : Maximize ) ;
helper . setProduceScheduler ( true ) ;
helper . setProduceScheduler ( true ) ;
@ -392,11 +392,14 @@ namespace storm {
}
}
}
}
} else {
} else {
storm : : storage : : SparseMatrix < ValueType > deterministicMatrix = transitionMatrix . selectRowsFromRowGroups ( this - > optimalChoices , true ) ;
storm : : storage : : SparseMatrix < ValueType > deterministicMatrix = transitionMatrix . selectRowsFromRowGroups ( this - > optimalChoices , true ) ; // TODO: why diagonal entries?
storm : : storage : : SparseMatrix < ValueType > deterministicBackwardTransitions = deterministicMatrix . transpose ( ) ;
storm : : storage : : SparseMatrix < ValueType > deterministicBackwardTransitions = deterministicMatrix . transpose ( ) ;
std : : vector < ValueType > deterministicStateRewards ( deterministicMatrix . getRowCount ( ) ) ;
std : : vector < ValueType > deterministicStateRewards ( deterministicMatrix . getRowCount ( ) ) ; // allocate here
storm : : solver : : GeneralLinearEquationSolverFactory < ValueType > linearEquationSolverFactory ;
storm : : solver : : GeneralLinearEquationSolverFactory < ValueType > linearEquationSolverFactory ;
auto infiniteHorizonHelper = createDetInfiniteHorizonHelper ( deterministicMatrix ) ;
infiniteHorizonHelper . provideBackwardTransitions ( deterministicBackwardTransitions ) ;
// We compute an estimate for the results of the individual objectives which is obtained from the weighted result and the result of the objectives computed so far.
// We compute an estimate for the results of the individual objectives which is obtained from the weighted result and the result of the objectives computed so far.
// Note that weightedResult = Sum_{i=1}^{n} w_i * objectiveResult_i.
// Note that weightedResult = Sum_{i=1}^{n} w_i * objectiveResult_i.
std : : vector < ValueType > weightedSumOfUncheckedObjectives = weightedResult ;
std : : vector < ValueType > weightedSumOfUncheckedObjectives = weightedResult ;
@ -407,6 +410,16 @@ namespace storm {
if ( objectivesWithNoUpperTimeBound . get ( objIndex ) ) {
if ( objectivesWithNoUpperTimeBound . get ( objIndex ) ) {
offsetsToUnderApproximation [ objIndex ] = storm : : utility : : zero < ValueType > ( ) ;
offsetsToUnderApproximation [ objIndex ] = storm : : utility : : zero < ValueType > ( ) ;
offsetsToOverApproximation [ objIndex ] = storm : : utility : : zero < ValueType > ( ) ;
offsetsToOverApproximation [ objIndex ] = storm : : utility : : zero < ValueType > ( ) ;
if ( lraObjectives . get ( objIndex ) ) {
auto actionValueGetter = [ & ] ( uint64_t const & a ) { return actionRewards [ objIndex ] [ transitionMatrix . getRowGroupIndices ( ) [ a ] + this - > optimalChoices [ a ] ] ; } ;
typename storm : : modelchecker : : helper : : SparseNondeterministicInfiniteHorizonHelper < ValueType > : : ValueGetter stateValueGetter ;
if ( stateRewards [ objIndex ] . empty ( ) ) {
stateValueGetter = [ ] ( uint64_t const & ) { return storm : : utility : : zero < ValueType > ( ) ; } ;
} else {
stateValueGetter = [ & ] ( uint64_t const & s ) { return stateRewards [ objIndex ] [ s ] ; } ;
}
objectiveResults [ objIndex ] = infiniteHorizonHelper . computeLongRunAverageValues ( env , stateValueGetter , actionValueGetter ) ;
} else { // i.e. a total reward objective
storm : : utility : : vector : : selectVectorValues ( deterministicStateRewards , this - > optimalChoices , transitionMatrix . getRowGroupIndices ( ) , actionRewards [ objIndex ] ) ;
storm : : utility : : vector : : selectVectorValues ( deterministicStateRewards , this - > optimalChoices , transitionMatrix . getRowGroupIndices ( ) , actionRewards [ objIndex ] ) ;
storm : : storage : : BitVector statesWithRewards = ~ storm : : utility : : vector : : filterZero ( deterministicStateRewards ) ;
storm : : storage : : BitVector statesWithRewards = ~ storm : : utility : : vector : : filterZero ( deterministicStateRewards ) ;
// As maybestates we pick the states from which a state with reward is reachable
// As maybestates we pick the states from which a state with reward is reachable
@ -458,7 +471,7 @@ namespace storm {
storm : : utility : : vector : : setVectorValues < ValueType > ( objectiveResults [ objIndex ] , maybeStates , x ) ;
storm : : utility : : vector : : setVectorValues < ValueType > ( objectiveResults [ objIndex ] , maybeStates , x ) ;
}
}
storm : : utility : : vector : : setVectorValues < ValueType > ( objectiveResults [ objIndex ] , ~ maybeStates , storm : : utility : : zero < ValueType > ( ) ) ;
storm : : utility : : vector : : setVectorValues < ValueType > ( objectiveResults [ objIndex ] , ~ maybeStates , storm : : utility : : zero < ValueType > ( ) ) ;
}
// Update the estimate for the next objectives.
// Update the estimate for the next objectives.
if ( ! storm : : utility : : isZero ( weightVector [ objIndex ] ) ) {
if ( ! storm : : utility : : isZero ( weightVector [ objIndex ] ) ) {
storm : : utility : : vector : : addScaledVector ( weightedSumOfUncheckedObjectives , objectiveResults [ objIndex ] , - weightVector [ objIndex ] ) ;
storm : : utility : : vector : : addScaledVector ( weightedSumOfUncheckedObjectives , objectiveResults [ objIndex ] , - weightVector [ objIndex ] ) ;