Browse Source

path printing

print path ammendment: off-by-one

Former-commit-id: cdeb58711b [formerly abd5a8777f]
Former-commit-id: 506ce7fc90
tempestpy_adaptions
tomjanson 9 years ago
committed by Tom Janson
parent
commit
d6c6b9b8d5
  1. 20
      src/utility/shortestPaths.cpp
  2. 8
      src/utility/shortestPaths.h

20
src/utility/shortestPaths.cpp

@ -21,6 +21,8 @@ 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>
@ -121,6 +123,24 @@ namespace storm {
}); });
} }
} }
template <typename T>
void ShortestPathsGenerator<T>::printKShortestPath(state_t targetNode, int k, bool head) {
// note the index shift! risk of off-by-one
Path<T> p = kShortestPaths[targetNode][k - 1];
if (head) {
std::cout << "Path (reversed), dist (prob)=" << p.distance << ": [";
}
std::cout << " " << targetNode;
if (p.predecessorNode) {
printKShortestPath(p.predecessorNode.get(), p.predecessorK, false);
} else {
std::cout << " ]" << std::endl;
}
}
} }
} }
} }

8
src/utility/shortestPaths.h

@ -20,7 +20,7 @@ namespace storm {
* *
* s ~~k-shortest path~~> u --> t * s ~~k-shortest path~~> u --> t
* *
* This struct stores u (`pathPredecessor`) and k (`predecessorK`).
* This struct stores u (`predecessorNode`) and k (`predecessorK`).
* *
* t is implied by this struct's location: It is stored in the * t is implied by this struct's location: It is stored in the
* k-shortest paths list associated with t. * k-shortest paths list associated with t.
@ -31,7 +31,7 @@ namespace storm {
*/ */
template <typename T> template <typename T>
struct Path { struct Path {
boost::optional<state_t> pathPredecessor;
boost::optional<state_t> predecessorNode;
unsigned int predecessorK; unsigned int predecessorK;
T distance; T distance;
}; };
@ -71,6 +71,10 @@ namespace storm {
void computeSPSuccessors(); void computeSPSuccessors();
void initializeShortestPaths(); void initializeShortestPaths();
/*
* Recurses over the path and prints the nodes. Intended for debugging.
*/
void printKShortestPath(state_t targetNode, int k, bool head=true);
}; };
} }
} }

Loading…
Cancel
Save