@ -28,7 +28,7 @@ namespace storm {
boost : : optional < std : : vector < T > > const & optionalStateRewardVector , boost : : optional < storm : : storage : : SparseMatrix < T > > const & optionalTransitionRewardMatrix ,
boost : : optional < std : : vector < storm : : storage : : VectorSet < uint_fast64_t > > > const & optionalChoiceLabeling )
: AbstractNondeterministicModel < T > ( transitionMatrix , stateLabeling , nondeterministicChoiceIndices , optionalStateRewardVector , optionalTransitionRewardMatrix , optionalChoiceLabeling ) ,
markovianStates ( markovianStates ) , exitRates ( exitRates ) , isC losed( false ) {
markovianStates ( markovianStates ) , exitRates ( exitRates ) , c losed( false ) {
if ( this - > hasTransitionRewards ( ) ) {
if ( ! this - > getTransitionRewardMatrix ( ) . isSubmatrixOf ( this - > getTransitionMatrix ( ) ) ) {
LOG4CPLUS_ERROR ( logger , " Transition reward matrix is not a submatrix of the transition matrix, i.e. there are rewards for transitions that do not exist. " ) ;
@ -45,7 +45,7 @@ namespace storm {
boost : : optional < storm : : storage : : SparseMatrix < T > > & & optionalTransitionRewardMatrix ,
boost : : optional < std : : vector < storm : : storage : : VectorSet < uint_fast64_t > > > & & optionalChoiceLabeling )
: AbstractNondeterministicModel < T > ( std : : move ( transitionMatrix ) , std : : move ( stateLabeling ) , std : : move ( nondeterministicChoiceIndices ) , std : : move ( optionalStateRewardVector ) , std : : move ( optionalTransitionRewardMatrix ) ,
std : : move ( optionalChoiceLabeling ) ) , markovianStates ( markovianStates ) , exitRates ( std : : move ( exitRates ) ) , isC losed( false ) {
std : : move ( optionalChoiceLabeling ) ) , markovianStates ( markovianStates ) , exitRates ( std : : move ( exitRates ) ) , c losed( false ) {
if ( this - > hasTransitionRewards ( ) ) {
if ( ! this - > getTransitionRewardMatrix ( ) . isSubmatrixOf ( this - > getTransitionMatrix ( ) ) ) {
LOG4CPLUS_ERROR ( logger , " Transition reward matrix is not a submatrix of the transition matrix, i.e. there are rewards for transitions that do not exist. " ) ;
@ -54,11 +54,11 @@ namespace storm {
}
}
MarkovAutomaton ( MarkovAutomaton < T > const & markovAutomaton ) : AbstractNondeterministicModel < T > ( markovAutomaton ) , markovianStates ( markovAutomaton . markovianStates ) , exitRates ( markovAutomaton . exitRates ) , isC losed( markovAutomaton . isC losed) {
MarkovAutomaton ( MarkovAutomaton < T > const & markovAutomaton ) : AbstractNondeterministicModel < T > ( markovAutomaton ) , markovianStates ( markovAutomaton . markovianStates ) , exitRates ( markovAutomaton . exitRates ) , c losed( markovAutomaton . c losed) {
/ / Intentionally left empty .
}
MarkovAutomaton ( MarkovAutomaton < T > & & markovAutomaton ) : AbstractNondeterministicModel < T > ( std : : move ( markovAutomaton ) ) , markovianStates ( std : : move ( markovAutomaton . markovianStates ) ) , exitRates ( std : : move ( markovAutomaton . exitRates ) ) , isC losed( markovAutomaton . isC losed) {
MarkovAutomaton ( MarkovAutomaton < T > & & markovAutomaton ) : AbstractNondeterministicModel < T > ( std : : move ( markovAutomaton ) ) , markovianStates ( std : : move ( markovAutomaton . markovianStates ) ) , exitRates ( std : : move ( markovAutomaton . exitRates ) ) , c losed( markovAutomaton . c losed) {
/ / Intentionally left empty .
}
@ -70,6 +70,95 @@ namespace storm {
return MA ;
}
bool isClosed ( ) const {
return closed ;
}
bool isHybridState ( uint_fast64_t state ) const {
return isMarkovianState ( state ) & & ( this - > getNondeterministicChoiceIndices ( ) [ state + 1 ] - this - > getNondeterministicChoiceIndices ( ) [ state ] > 1 ) ;
}
bool isMarkovianState ( uint_fast64_t state ) const {
return this - > markovianStates . get ( state ) ;
}
bool isProbabilisticState ( uint_fast64_t state ) const {
return ! this - > markovianStates . get ( state ) ;
}
void close ( ) {
if ( ! closed ) {
/ / First , count the number of hybrid states to know how many Markovian choices
/ / will be removed .
uint_fast64_t numberOfHybridStates = 0 ;
for ( uint_fast64_t state = 0 ; state < this - > getNumberOfStates ( ) ; + + state ) {
if ( this - > isHybridState ( state ) ) {
+ + numberOfHybridStates ;
}
}
/ / Then compute how many rows the new matrix is going to have .
uint_fast64_t newNumberOfRows = this - > getNumberOfChoices ( ) - numberOfHybridStates ;
/ / Create the matrix for the new transition relation and the corresponding nondeterministic choice vector .
storm : : storage : : SparseMatrix < T > newTransitionMatrix ( newNumberOfRows , this - > getNumberOfStates ( ) ) ;
newTransitionMatrix . initialize ( ) ;
std : : vector < uint_fast64_t > newNondeterministicChoiceIndices ( this - > getNumberOfStates ( ) + 1 ) ;
/ / Now copy over all choices that need to be kept .
uint_fast64_t currentChoice = 0 ;
for ( uint_fast64_t state = 0 ; state < this - > getNumberOfStates ( ) ; + + state ) {
/ / Record the new beginning of choices of this state .
newNondeterministicChoiceIndices [ state ] = currentChoice ;
typename storm : : storage : : SparseMatrix < T > : : ConstRowIterator rowIt = this - > transitionMatrix . begin ( this - > nondeterministicChoiceIndices [ state ] ) , rowIte = this - > transitionMatrix . end ( this - > nondeterministicChoiceIndices [ state + 1 ] - 1 ) ;
/ / If we are currently treating a hybrid state , we need to skip its first choice .
if ( this - > isHybridState ( state ) ) {
+ + rowIt ;
/ / Remove the Markovian state marking .
this - > markovianStates . set ( state , false ) ;
}
for ( ; rowIt ! = rowIte ; + + rowIt ) {
for ( typename storm : : storage : : SparseMatrix < T > : : ConstIterator succIt = rowIt . begin ( ) , succIte = rowIt . end ( ) ; succIt ! = succIte ; + + succIt ) {
newTransitionMatrix . insertNextValue ( currentChoice , succIt . column ( ) , succIt . value ( ) ) ;
}
+ + currentChoice ;
}
}
/ / Put a sentinel element at the end .
newNondeterministicChoiceIndices . back ( ) = currentChoice ;
/ / Finalize the matrix and put the new transition data in place .
newTransitionMatrix . finalize ( ) ;
this - > transitionMatrix = std : : move ( newTransitionMatrix ) ;
this - > nondeterministicChoiceIndices = std : : move ( newNondeterministicChoiceIndices ) ;
/ / Mark the automaton as closed .
closed = true ;
}
}
virtual std : : shared_ptr < AbstractModel < T > > applyScheduler ( storm : : storage : : Scheduler const & scheduler ) const override {
if ( ! closed ) {
throw storm : : exceptions : : InvalidStateException ( ) < < " Applying a scheduler to a non-closed Markov automaton is illegal; it needs to be closed first. " ;
}
storm : : storage : : SparseMatrix < T > newTransitionMatrix = storm : : utility : : matrix : : applyScheduler ( this - > getTransitionMatrix ( ) , this - > getNondeterministicChoiceIndices ( ) , scheduler ) ;
/ / Construct the new nondeterministic choice indices for the resulting matrix .
std : : vector < uint_fast64_t > nondeterministicChoiceIndices ( this - > getNumberOfStates ( ) + 1 ) ;
for ( uint_fast64_t state = 0 ; state < this - > getNumberOfStates ( ) ; + + state ) {
nondeterministicChoiceIndices [ state ] = state ;
}
nondeterministicChoiceIndices [ this - > getNumberOfStates ( ) ] = this - > getNumberOfStates ( ) ;
return std : : shared_ptr < AbstractModel < T > > ( new MarkovAutomaton ( newTransitionMatrix , this - > getStateLabeling ( ) , nondeterministicChoiceIndices , markovianStates , exitRates , this - > hasStateRewards ( ) ? this - > getStateRewardVector ( ) : boost : : optional < std : : vector < T > > ( ) , this - > hasTransitionRewards ( ) ? this - > getTransitionRewardMatrix ( ) : boost : : optional < storm : : storage : : SparseMatrix < T > > ( ) , this - > hasChoiceLabeling ( ) ? this - > getChoiceLabeling ( ) : boost : : optional < std : : vector < storm : : storage : : VectorSet < uint_fast64_t > > > ( ) ) ) ;
}
virtual void writeDotToStream ( std : : ostream & outStream , bool includeLabeling = true , storm : : storage : : BitVector const * subsystem = nullptr , std : : vector < T > const * firstValue = nullptr , std : : vector < T > const * secondValue = nullptr , std : : vector < uint_fast64_t > const * stateColoring = nullptr , std : : vector < std : : string > const * colors = nullptr , std : : vector < uint_fast64_t > * scheduler = nullptr , bool finalizeOutput = true ) const override {
AbstractModel < T > : : writeDotToStream ( outStream , includeLabeling , subsystem , firstValue , secondValue , stateColoring , colors , scheduler , false ) ;
@ -148,29 +237,11 @@ namespace storm {
outStream < < " } " < < std : : endl ;
}
}
virtual std : : shared_ptr < AbstractModel < T > > applyScheduler ( storm : : storage : : Scheduler const & scheduler ) const override {
if ( ! isClosed ) {
throw storm : : exceptions : : InvalidStateException ( ) < < " Applying a scheduler to a non-closed Markov automaton is illegal; it needs to be closed first. " ;
}
storm : : storage : : SparseMatrix < T > newTransitionMatrix = storm : : utility : : matrix : : applyScheduler ( this - > getTransitionMatrix ( ) , this - > getNondeterministicChoiceIndices ( ) , scheduler ) ;
/ / Construct the new nondeterministic choice indices for the resulting matrix .
std : : vector < uint_fast64_t > nondeterministicChoiceIndices ( this - > getNumberOfStates ( ) + 1 ) ;
for ( uint_fast64_t state = 0 ; state < this - > getNumberOfStates ( ) ; + + state ) {
nondeterministicChoiceIndices [ state ] = state ;
}
nondeterministicChoiceIndices [ this - > getNumberOfStates ( ) ] = this - > getNumberOfStates ( ) ;
return std : : shared_ptr < AbstractModel < T > > ( new MarkovAutomaton ( newTransitionMatrix , this - > getStateLabeling ( ) , nondeterministicChoiceIndices , markovianStates , exitRates , this - > hasStateRewards ( ) ? this - > getStateRewardVector ( ) : boost : : optional < std : : vector < T > > ( ) , this - > hasTransitionRewards ( ) ? this - > getTransitionRewardMatrix ( ) : boost : : optional < storm : : storage : : SparseMatrix < T > > ( ) , this - > hasChoiceLabeling ( ) ? this - > getChoiceLabeling ( ) : boost : : optional < std : : vector < storm : : storage : : VectorSet < uint_fast64_t > > > ( ) ) ) ;
}
private :
storm : : storage : : BitVector markovianStates ;
std : : vector < T > exitRates ;
bool isC losed;
bool closed ;
} ;
}