Browse Source

documentation / cleanup

Former-commit-id: e7798a5669 [formerly 43dd865fbc]
Former-commit-id: 6fb69a017c
tempestpy_adaptions
tomjanson 9 years ago
committed by Tom Janson
parent
commit
38d22093a3
  1. 65
      src/test/utility/GraphTest.cpp
  2. 13
      src/utility/shortestPaths.cpp
  3. 28
      src/utility/shortestPaths.h

65
src/test/utility/GraphTest.cpp

@ -278,68 +278,5 @@ TEST(GraphTest, kshortest) {
// TODO: actually write tests here // TODO: actually write tests here
/*
std::queue<uint_fast64_t> nodeQueue;
for (uint_fast64_t initialNode : model->getInitialStates()) {
for (uint_fast64_t succ : shortestPathSuccessors[initialNode]) {
nodeQueue.push(succ);
}
storm::storage::sparse::path<double> path;
path.tail_k = 1;
path.distance = dijkstraDistance[initialNode];
assert(path.distance == 1);
kShortestPaths[initialNode].push_back(path);
}
// Dijkstra BFS
while (!nodeQueue.empty()) {
uint_fast64_t currentNode = nodeQueue.front();
nodeQueue.pop();
for (auto succ : shortestPathSuccessors[currentNode]) {
nodeQueue.push(succ);
}
storm::storage::sparse::path<double> path;
path.tail = shortestPathPredecessor[currentNode];
path.tail_k = 1;
path.distance = dijkstraDistance[currentNode];
kShortestPaths[currentNode].push_back(path);
}
*/
// FIXME: ~~treat starting node(s) separately~~ actually, this whole thing should be done differently:
// first I need to run over the Dijkstra result and make a tree (as vector of vectors) of successors,
// then walk that tree DF/BF
/*
for (auto node : model->getInitialStates()) {
storm::storage::sparse::path<double> p = {};
p.distance = dijkstraDistance[node];
assert(p.distance == 1);
kShortestPaths[node].emplace_back(p);
}
*/
// shortest paths are stored recursively, so the predecessor must always be dealt with first
// by considering the nodes in order of distance, we should have roughly the correct order,
// but not quite: in the case s ~~~> u -1-> v, v might be listed before u, in which case it must be deferred
/*
while (!nodeQueue.empty()) {
std::pair<double, uint_fast64_t> distanceStatePair = nodeQueue.front();
nodeQueue.pop();
uint_fast64_t currentNode = distanceStatePair.second;
uint_fast64_t predecessor = shortestPathPredecessors[currentNode];
if (kShortestPaths[predecessor].empty) {
// we need to take care of the predecessor first; defer this one
nodeQueue.emplace(currentNode);
continue;
} else {
//shortestPaths[currentNode].emplace(predecessor, 1, )
}
}
*/
EXPECT_TRUE(false); EXPECT_TRUE(false);
}
}

13
src/utility/shortestPaths.cpp

@ -21,8 +21,6 @@ namespace storm {
// constructs the recursive shortest path representations // constructs the recursive shortest path representations
initializeShortestPaths(); initializeShortestPaths();
printKShortestPath(400, 1); // DEBUG
} }
template <typename T> template <typename T>
@ -31,11 +29,13 @@ namespace storm {
template <typename T> template <typename T>
void ShortestPathsGenerator<T>::computePredecessors() { void ShortestPathsGenerator<T>::computePredecessors() {
graphPredecessors.resize(numStates);
auto rowCount = transitionMatrix.getRowCount();
assert(numStates == rowCount);
assert(numStates == transitionMatrix.getRowCount());
for (state_t i = 0; i < numStates; i++) {
for (auto transition : transitionMatrix.getRowGroup(i)) {
graphPredecessors.resize(rowCount);
for (state_t i = 0; i < rowCount; i++) {
for (auto const& transition : transitionMatrix.getRowGroup(i)) {
graphPredecessors[transition.getColumn()].push_back(i); graphPredecessors[transition.getColumn()].push_back(i);
} }
} }
@ -93,7 +93,6 @@ namespace storm {
template <typename T> template <typename T>
void ShortestPathsGenerator<T>::initializeShortestPaths() { void ShortestPathsGenerator<T>::initializeShortestPaths() {
kShortestPaths.resize(numStates); kShortestPaths.resize(numStates);
candidatePaths.resize(numStates);
// BFS in Dijkstra-SP order // BFS in Dijkstra-SP order
std::queue<state_t> bfsQueue; std::queue<state_t> bfsQueue;

28
src/utility/shortestPaths.h

@ -44,7 +44,6 @@ namespace storm {
~ShortestPathsGenerator(); ~ShortestPathsGenerator();
private: private:
//storm::models::sparse::Model<T>* model;
std::shared_ptr<storm::models::sparse::Model<T>> model; std::shared_ptr<storm::models::sparse::Model<T>> model;
storm::storage::SparseMatrix<T> transitionMatrix; storm::storage::SparseMatrix<T> transitionMatrix;
state_t numStates; state_t numStates;
@ -59,19 +58,34 @@ namespace storm {
/*! /*!
* Computes list of predecessors for all nodes. * Computes list of predecessors for all nodes.
* Reachability is not considered; a predecessor is simply any node that has an edge leading to the
* node in question.
*
* @param model The model whose transitions will be examined
* @return A vector of predecessors for each node
* Reachability is not considered; a predecessor is simply any node that has an edge leading to the node in question.
* Requires `transitionMatrix`.
* Modifies `graphPredecessors`.
*/ */
void computePredecessors(); void computePredecessors();
/*!
* Computes shortest path distances and predecessors.
* Requires `model`, `numStates`, `transitionMatrix`.
* Modifies `shortestPathPredecessors` and `shortestPathDistances`.
*/
void performDijkstra(); void performDijkstra();
/*!
* Computes list of shortest path successor nodes from predecessor list.
* Requires `shortestPathPredecessors`, `numStates`.
* Modifies `shortestPathSuccessors`.
*/
void computeSPSuccessors(); void computeSPSuccessors();
/*!
* Constructs and stores the implicit shortest path representations (see `Path`) for the (1-)shortest paths.
* Requires `shortestPathPredecessors`, `shortestPathDistances`, `model`, `numStates`.
* Modifies `kShortestPaths`.
*/
void initializeShortestPaths(); void initializeShortestPaths();
/*
/*!
* Recurses over the path and prints the nodes. Intended for debugging. * Recurses over the path and prints the nodes. Intended for debugging.
*/ */
void printKShortestPath(state_t targetNode, int k, bool head=true); void printKShortestPath(state_t targetNode, int k, bool head=true);

Loading…
Cancel
Save