Browse Source

The columns of non-zero elements of a single row in a sparse matrix can now be iterated using an iterator. These iterator functionality is now used by the computation of the backwards transitions.

tempestpy_adaptions
dehnert 12 years ago
parent
commit
eeddadc096
  1. 28
      src/models/backward_transitions.h
  2. 27
      src/sparse/static_sparse_matrix.h

28
src/models/backward_transitions.h

@ -47,8 +47,8 @@ public:
uint_fast64_t* row_indications = transitionMatrix->getRowIndicationsPointer(); uint_fast64_t* row_indications = transitionMatrix->getRowIndicationsPointer();
uint_fast64_t* column_indications = transitionMatrix->getColumnIndicationsPointer(); uint_fast64_t* column_indications = transitionMatrix->getColumnIndicationsPointer();
for (uint_fast64_t i = 0; i <= numberOfStates; i++) { for (uint_fast64_t i = 0; i <= numberOfStates; i++) {
for (uint_fast64_t j = row_indications[i]; j < row_indications[i + 1]; j++) {
this->state_indices_list[column_indications[j] + 1]++;
for (auto rowIt = transitionMatrix->beginConstColumnNoDiagIterator(i); rowIt != transitionMatrix->endConstColumnNoDiagIterator(i); ++rowIt) {
this->state_indices_list[*rowIt + 1]++;
} }
} }
@ -70,17 +70,10 @@ public:
// Now we are ready to actually fill in the list of predecessors for // Now we are ready to actually fill in the list of predecessors for
// every state. Again, we start by considering all but the last row. // every state. Again, we start by considering all but the last row.
for (uint_fast64_t i = 0; i <= numberOfStates; i++) { for (uint_fast64_t i = 0; i <= numberOfStates; i++) {
for (uint_fast64_t j = row_indications[i]; j < row_indications[i + 1]; j++) {
this->predecessor_list[next_state_index_list[column_indications[j]]++] = i;
for (auto rowIt = transitionMatrix->beginConstColumnNoDiagIterator(i); rowIt != transitionMatrix->endConstColumnNoDiagIterator(i); ++rowIt) {
this->predecessor_list[next_state_index_list[*rowIt]++] = i;
} }
} }
for (auto it = beginStatePredecessorIterator(0); it < endStatePredecessorIterator(0); it++) {
std::cout << "state 0 pred " << *it << std::endl;
}
for (auto it = beginStatePredecessorIterator(1); it < endStatePredecessorIterator(1); it++) {
std::cout << "state 1 pred " << *it << std::endl;
}
} }
~BackwardTransitions() { ~BackwardTransitions() {
@ -92,10 +85,23 @@ public:
} }
} }
/*!
* Returns an iterator to the predecessors of the given states.
* @param state The state for which to get the predecessor iterator.
* @return An iterator to the predecessors of the given states.
*/
state_predecessor_iterator beginStatePredecessorIterator(uint_fast64_t state) const { state_predecessor_iterator beginStatePredecessorIterator(uint_fast64_t state) const {
return this->predecessor_list + this->state_indices_list[state]; return this->predecessor_list + this->state_indices_list[state];
} }
/*!
* Returns an iterator referring to the element after the predecessors of
* the given state.
* @param row The state for which to get the iterator.
* @return An iterator referring to the element after the predecessors of
* the given state.
*/
state_predecessor_iterator endStatePredecessorIterator(uint_fast64_t state) const { state_predecessor_iterator endStatePredecessorIterator(uint_fast64_t state) const {
return this->predecessor_list + this->state_indices_list[state + 1]; return this->predecessor_list + this->state_indices_list[state + 1];
} }

27
src/sparse/static_sparse_matrix.h

@ -30,6 +30,13 @@ namespace sparse {
template<class T> template<class T>
class StaticSparseMatrix { class StaticSparseMatrix {
public: public:
/*!
* If we only want to iterate over the columns of the non-zero entries of
* a row, we can simply iterate over the array (part) itself.
*/
typedef const uint_fast64_t * const constIndexIterator;
/*! /*!
* An enum representing the internal state of the Matrix. * An enum representing the internal state of the Matrix.
* After creating the Matrix using the Constructor, the Object is in state UnInitialized. After calling initialize(), that state changes to Initialized and after all entries have been entered and finalize() has been called, to ReadReady. * After creating the Matrix using the Constructor, the Object is in state UnInitialized. After calling initialize(), that state changes to Initialized and after all entries have been entered and finalize() has been called, to ReadReady.
@ -611,6 +618,26 @@ public:
return size; return size;
} }
/*!
* Returns an iterator to the columns of the non-zero entries of the given
* row that are not on the diagonal.
* @param row The row whose columns the iterator will return.
* @return An iterator to the columns of the non-zero entries of the given
* row that are not on the diagonal.
*/
constIndexIterator beginConstColumnNoDiagIterator(uint_fast64_t row) const {
return this->columnIndications + this->rowIndications[row];
}
/*!
* Returns an iterator referring to the element after the given row.
* @param row The row for which the iterator should point to the past-the-end
* element.
*/
constIndexIterator endConstColumnNoDiagIterator(uint_fast64_t row) const {
return this->columnIndications + this->rowIndications[row + 1];
}
private: private:
/*! /*!

Loading…
Cancel
Save