@ -11,33 +11,33 @@ namespace storm {
namespace storage {
namespace storage {
template < typename T >
template < typename T >
SparseMatrix < T > : : rows : : rows ( std : : pair < uint_fast64_t , T > * columnAndValuePtr , uint_fast64_t entryCount ) : columnAndValuePtr ( columnAndValuePtr ) , entryCount ( entryCount ) {
SparseMatrix < T > : : rows : : rows ( iterator begin , uint_fast64_t entryCount ) : beginIterator ( begin ) , entryCount ( entryCount ) {
// Intentionally left empty.
// Intentionally left empty.
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : rows : : begin ( ) {
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : rows : : begin ( ) {
return columnAndValuePt r;
return beginIterato r;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : rows : : end ( ) {
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : rows : : end ( ) {
return columnAndValuePt r + entryCount ;
return beginIterato r + entryCount ;
}
}
template < typename T >
template < typename T >
SparseMatrix < T > : : const_rows : : const_rows ( std : : pair < uint_fast64_t , T > const * columnAndValuePtr , uint_fast64_t entryCount ) : columnAndValuePtr ( columnAndValuePtr ) , entryCount ( entryCount ) {
SparseMatrix < T > : : const_rows : : const_rows ( const_iterator begin , uint_fast64_t entryCount ) : beginIterator ( begin ) , entryCount ( entryCount ) {
// Intentionally left empty.
// Intentionally left empty.
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : const_rows : : begin ( ) const {
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : const_rows : : begin ( ) const {
return columnAndValuePt r;
return beginIterato r;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : const_rows : : end ( ) const {
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : const_rows : : end ( ) const {
return columnAndValuePt r + entryCount ;
return beginIterato r + entryCount ;
}
}
template < typename T >
template < typename T >
@ -66,7 +66,7 @@ namespace storm {
}
}
template < typename T >
template < typename T >
SparseMatrix < T > : : SparseMatrix ( uint_fast64_t columnCount , std : : vector < uint_fast64_t > const & rowIndications , std : : vector < std : : pair < uint_fast64_t , T > > const & columnsAndValues ) : rowCount ( rowIndications . size ( ) - 1 ) , columnCount ( columnCount ) , entryCount ( v alues. size ( ) ) , storagePreallocated ( true ) , columnsAndValues ( columnsAndValues ) , rowIndications ( rowIndications ) , internalStatus ( INITIALIZED ) , currentEntryCount ( 0 ) , lastRow ( 0 ) , lastColumn ( 0 ) {
SparseMatrix < T > : : SparseMatrix ( uint_fast64_t columnCount , std : : vector < uint_fast64_t > const & rowIndications , std : : vector < std : : pair < uint_fast64_t , T > > const & columnsAndValues ) : rowCount ( rowIndications . size ( ) - 1 ) , columnCount ( columnCount ) , entryCount ( columnsAndV alues. size ( ) ) , storagePreallocated ( true ) , columnsAndValues ( columnsAndValues ) , rowIndications ( rowIndications ) , internalStatus ( INITIALIZED ) , currentEntryCount ( 0 ) , lastRow ( 0 ) , lastColumn ( 0 ) {
// Intentionally left empty.
// Intentionally left empty.
}
}
@ -87,7 +87,7 @@ namespace storm {
}
}
template < typename T >
template < typename T >
SparseMatrix < T > : : SparseMatrix ( uint_fast64_t columnCount , std : : vector < uint_fast64_t > & & rowIndications , std : : vector < std : : pair < uint_fast64_t , T > > & & columnsAndValues ) : rowCount ( rowIndications . size ( ) - 1 ) , columnCount ( columnCount ) , entryCount ( v alues. size ( ) ) , storagePreallocated ( true ) , columnsAndValues ( std : : move ( columnsAndValues ) ) , rowIndications ( std : : move ( rowIndications ) ) , internalStatus ( INITIALIZED ) , currentEntryCount ( 0 ) , lastRow ( 0 ) , lastColumn ( 0 ) {
SparseMatrix < T > : : SparseMatrix ( uint_fast64_t columnCount , std : : vector < uint_fast64_t > & & rowIndications , std : : vector < std : : pair < uint_fast64_t , T > > & & columnsAndValues ) : rowCount ( rowIndications . size ( ) - 1 ) , columnCount ( columnCount ) , entryCount ( columnsAndV alues. size ( ) ) , storagePreallocated ( true ) , columnsAndValues ( std : : move ( columnsAndValues ) ) , rowIndications ( std : : move ( rowIndications ) ) , internalStatus ( INITIALIZED ) , currentEntryCount ( 0 ) , lastRow ( 0 ) , lastColumn ( 0 ) {
// Intentionally left empty.
// Intentionally left empty.
}
}
@ -359,8 +359,8 @@ namespace storm {
throw storm : : exceptions : : OutOfRangeException ( ) < < " Illegal call to SparseMatrix::makeRowAbsorbing: access to row " < < row < < " is out of bounds. " ;
throw storm : : exceptions : : OutOfRangeException ( ) < < " Illegal call to SparseMatrix::makeRowAbsorbing: access to row " < < row < < " is out of bounds. " ;
}
}
const_ iterator columnValuePtr = columnsAndValues . begin ( ) + rowIndications [ row ] ;
const_ iterator columnValuePtrEnd = columnsAndValues . begin ( ) + rowIndications [ row + 1 ] ;
iterator columnValuePtr = this - > begin ( row ) ;
iterator columnValuePtrEnd = this - > end ( row ) ;
// If the row has no elements in it, we cannot make it absorbing, because we would need to move all elements
// If the row has no elements in it, we cannot make it absorbing, because we would need to move all elements
// in the vector of nonzeros otherwise.
// in the vector of nonzeros otherwise.
@ -373,7 +373,7 @@ namespace storm {
columnValuePtr - > first = column ;
columnValuePtr - > first = column ;
columnValuePtr - > second = storm : : utility : : constantOne < T > ( ) ;
columnValuePtr - > second = storm : : utility : : constantOne < T > ( ) ;
+ + columnValuePtr ;
+ + columnValuePtr ;
for ( ; columnValuePtr ! = columnValuePtr ; + + columnValuePtr ) {
for ( ; columnValuePtr ! = columnValuePtrEnd ; + + columnValuePtr ) {
columnValuePtr - > first = 0 ;
columnValuePtr - > first = 0 ;
columnValuePtr - > second = storm : : utility : : constantZero < T > ( ) ;
columnValuePtr - > second = storm : : utility : : constantZero < T > ( ) ;
}
}
@ -383,7 +383,7 @@ namespace storm {
T SparseMatrix < T > : : getConstrainedRowSum ( uint_fast64_t row , storm : : storage : : BitVector const & constraint ) const {
T SparseMatrix < T > : : getConstrainedRowSum ( uint_fast64_t row , storm : : storage : : BitVector const & constraint ) const {
checkReady ( " getConstrainedRowSum " ) ;
checkReady ( " getConstrainedRowSum " ) ;
T result ( 0 ) ;
T result ( 0 ) ;
for ( typename std : : vector < std : : pair < uint_fast64_t , T > > : : const_iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
for ( const_iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
if ( constraint . get ( it - > first ) ) {
if ( constraint . get ( it - > first ) ) {
result + = it - > second ;
result + = it - > second ;
}
}
@ -633,7 +633,7 @@ namespace storm {
T one = storm : : utility : : constantOne < T > ( ) ;
T one = storm : : utility : : constantOne < T > ( ) ;
bool foundDiagonalElement = false ;
bool foundDiagonalElement = false ;
for ( uint_fast64_t row = 0 ; row < rowCount ; + + row ) {
for ( uint_fast64_t row = 0 ; row < rowCount ; + + row ) {
for ( const_ iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
for ( iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
if ( it - > first = = row ) {
if ( it - > first = = row ) {
it - > second = one - it - > second ;
it - > second = one - it - > second ;
foundDiagonalElement = true ;
foundDiagonalElement = true ;
@ -658,7 +658,7 @@ namespace storm {
// Iterate over all rows and negate all the elements that are not on the diagonal.
// Iterate over all rows and negate all the elements that are not on the diagonal.
for ( uint_fast64_t row = 0 ; row < rowCount ; + + row ) {
for ( uint_fast64_t row = 0 ; row < rowCount ; + + row ) {
for ( const_ iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
for ( iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
if ( it - > first ! = row ) {
if ( it - > first ! = row ) {
it - > second = - it - > second ;
it - > second = - it - > second ;
}
}
@ -677,7 +677,7 @@ namespace storm {
// Iterate over all rows and negate all the elements that are not on the diagonal.
// Iterate over all rows and negate all the elements that are not on the diagonal.
for ( uint_fast64_t row = 0 ; row < rowCount ; + + row ) {
for ( uint_fast64_t row = 0 ; row < rowCount ; + + row ) {
for ( const_ iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
for ( iterator it = this - > begin ( row ) , ite = this - > end ( row ) ; it ! = ite ; + + it ) {
if ( it - > first = = row ) {
if ( it - > first = = row ) {
it - > second = storm : : utility : : constantZero < T > ( ) ;
it - > second = storm : : utility : : constantZero < T > ( ) ;
}
}
@ -785,13 +785,13 @@ namespace storm {
template < typename T >
template < typename T >
typename SparseMatrix < T > : : const_rows SparseMatrix < T > : : getRows ( uint_fast64_t startRow , uint_fast64_t endRow ) const {
typename SparseMatrix < T > : : const_rows SparseMatrix < T > : : getRows ( uint_fast64_t startRow , uint_fast64_t endRow ) const {
checkReady ( " getRows " ) ;
checkReady ( " getRows " ) ;
return const_rows ( this - > valueStorage . data ( ) + this - > rowIndications [ startRow ] , this - > columnIndication s. data ( ) + this - > rowIndications [ startRow ] , this - > rowIndications [ endRow + 1 ] - this - > rowIndications [ startRow ] ) ;
return const_rows ( this - > columnsAndValue s. data ( ) + this - > rowIndications [ startRow ] , this - > rowIndications [ endRow + 1 ] - this - > rowIndications [ startRow ] ) ;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : rows SparseMatrix < T > : : getRows ( uint_fast64_t startRow , uint_fast64_t endRow ) {
typename SparseMatrix < T > : : rows SparseMatrix < T > : : getRows ( uint_fast64_t startRow , uint_fast64_t endRow ) {
checkReady ( " getRows " ) ;
checkReady ( " getRows " ) ;
return rows ( this - > valueStorage . data ( ) + this - > rowIndications [ startRow ] , this - > columnIndication s. data ( ) + this - > rowIndications [ startRow ] , this - > rowIndications [ endRow + 1 ] - this - > rowIndications [ startRow ] ) ;
return rows ( this - > columnsAndValue s. data ( ) + this - > rowIndications [ startRow ] , this - > rowIndications [ endRow + 1 ] - this - > rowIndications [ startRow ] ) ;
}
}
template < typename T >
template < typename T >
@ -809,37 +809,37 @@ namespace storm {
template < typename T >
template < typename T >
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : begin ( uint_fast64_t row ) const {
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : begin ( uint_fast64_t row ) const {
checkReady ( " begin " ) ;
checkReady ( " begin " ) ;
return this - > columnsAndValues . begin ( ) + this - > rowIndications [ row ] ;
return this - > columnsAndValues . data ( ) + this - > rowIndications [ row ] ;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : begin ( uint_fast64_t row ) {
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : begin ( uint_fast64_t row ) {
checkReady ( " begin " ) ;
checkReady ( " begin " ) ;
return this - > columnsAndValues . begin ( ) + this - > rowIndications [ row ] ;
return this - > columnsAndValues . data ( ) + this - > rowIndications [ row ] ;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : end ( uint_fast64_t row ) const {
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : end ( uint_fast64_t row ) const {
checkReady ( " end " ) ;
checkReady ( " end " ) ;
return this - > columnsAndValues . begin ( ) + this - > rowIndications [ row + 1 ] ;
return this - > columnsAndValues . data ( ) + this - > rowIndications [ row + 1 ] ;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : end ( uint_fast64_t row ) {
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : end ( uint_fast64_t row ) {
checkReady ( " end " ) ;
checkReady ( " end " ) ;
return this - > columnsAndValues . begin ( ) + this - > rowIndications [ row + 1 ] ;
return this - > columnsAndValues . data ( ) + this - > rowIndications [ row + 1 ] ;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : end ( ) const {
typename SparseMatrix < T > : : const_iterator SparseMatrix < T > : : end ( ) const {
checkReady ( " end " ) ;
checkReady ( " end " ) ;
return this - > columnsAndValues . begin ( ) + this - > rowIndications [ rowCount ] ;
return this - > columnsAndValues . data ( ) + this - > rowIndications [ rowCount ] ;
}
}
template < typename T >
template < typename T >
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : end ( ) {
typename SparseMatrix < T > : : iterator SparseMatrix < T > : : end ( ) {
checkReady ( " end " ) ;
checkReady ( " end " ) ;
return this - > columnsAndValues . begin ( ) + this - > rowIndications [ rowCount ] ;
return this - > columnsAndValues . data ( ) + this - > rowIndications [ rowCount ] ;
}
}
template < typename T >
template < typename T >
@ -863,12 +863,11 @@ namespace storm {
// Check the subset property for all rows individually.
// Check the subset property for all rows individually.
for ( uint_fast64_t row = 0 ; row < this - > getRowCount ( ) ; + + row ) {
for ( uint_fast64_t row = 0 ; row < this - > getRowCount ( ) ; + + row ) {
for ( const_iterator it1 = this - > begin ( row ) , ite1 = this - > end ( row ) , it2 = matrix . begin ( row ) , ite2 = matrix . end ( row ) ; it1 ! = ite1 ; + + it1 ) {
for ( const_iterator it1 = this - > begin ( row ) , ite1 = this - > end ( row ) , it2 = matrix . begin ( row ) , ite2 = matrix . end ( row ) ; it1 ! = ite1 ; + + it1 ) {
for ( uint_fast64_t elem = rowIndications [ row ] , elem2 = matrix . rowIndications [ row ] ; elem < rowIndications [ row + 1 ] ; + + elem ) {
// Skip over all entries of the other matrix that are before the current entry in the current matrix.
// Skip over all entries of the other matrix that are before the current entry in the current matrix.
while ( it2 - > first ! = ite2 & & it2 - > first < it1 - > first ) {
while ( it2 ! = ite2 & & it2 - > first < it1 - > first ) {
+ + it2 ;
+ + it2 ;
}
}
if ( it2 - > first = = ite2 | | it1 - > first ! = it2 - > first ) {
if ( it2 = = ite2 | | it1 - > first ! = it2 - > first ) {
return false ;
return false ;
}
}
}
}
@ -934,8 +933,7 @@ namespace storm {
void SparseMatrix < T > : : prepareInternalStorage ( ) {
void SparseMatrix < T > : : prepareInternalStorage ( ) {
// Only allocate the memory if the dimensions of the matrix are already known.
// Only allocate the memory if the dimensions of the matrix are already known.
if ( storagePreallocated ) {
if ( storagePreallocated ) {
valueStorage = std : : vector < T > ( entryCount , storm : : utility : : constantZero < T > ( ) ) ;
columnIndications = std : : vector < uint_fast64_t > ( entryCount , 0 ) ;
columnsAndValues = std : : vector < std : : pair < uint_fast64_t , T > > ( entryCount , std : : make_pair ( 0 , storm : : utility : : constantZero < T > ( ) ) ) ;
rowIndications = std : : vector < uint_fast64_t > ( rowCount + 1 , 0 ) ;
rowIndications = std : : vector < uint_fast64_t > ( rowCount + 1 , 0 ) ;
} else {
} else {
rowIndications . push_back ( 0 ) ;
rowIndications . push_back ( 0 ) ;
@ -950,12 +948,8 @@ namespace storm {
}
}
// Explicitly instantiate the matrix and the nested classes.
// Explicitly instantiate the matrix and the nested classes.
template class SparseMatrix < double > : : BaseIterator < double const > ;
template class SparseMatrix < double > : : BaseIterator < double > ;
template class SparseMatrix < double > ;
template class SparseMatrix < double > ;
template std : : ostream & operator < < ( std : : ostream & out , SparseMatrix < double > const & matrix ) ;
template std : : ostream & operator < < ( std : : ostream & out , SparseMatrix < double > const & matrix ) ;
template class SparseMatrix < int > : : BaseIterator < int const > ;
template class SparseMatrix < int > : : BaseIterator < int > ;
template class SparseMatrix < int > ;
template class SparseMatrix < int > ;
template std : : ostream & operator < < ( std : : ostream & out , SparseMatrix < int > const & matrix ) ;
template std : : ostream & operator < < ( std : : ostream & out , SparseMatrix < int > const & matrix ) ;