diff --git a/src/utility/shortestPaths.cpp b/src/utility/shortestPaths.cpp index f2170bc9f..2092bf7a5 100644 --- a/src/utility/shortestPaths.cpp +++ b/src/utility/shortestPaths.cpp @@ -21,6 +21,8 @@ namespace storm { // constructs the recursive shortest path representations initializeShortestPaths(); + + printKShortestPath(400, 1); // DEBUG } template @@ -121,6 +123,24 @@ namespace storm { }); } } + + template + void ShortestPathsGenerator::printKShortestPath(state_t targetNode, int k, bool head) { + // note the index shift! risk of off-by-one + Path 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; + } + } } } } diff --git a/src/utility/shortestPaths.h b/src/utility/shortestPaths.h index 31733c9d3..91f5c7843 100644 --- a/src/utility/shortestPaths.h +++ b/src/utility/shortestPaths.h @@ -20,7 +20,7 @@ namespace storm { * * 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 * k-shortest paths list associated with t. @@ -31,7 +31,7 @@ namespace storm { */ template struct Path { - boost::optional pathPredecessor; + boost::optional predecessorNode; unsigned int predecessorK; T distance; }; @@ -71,6 +71,10 @@ namespace storm { void computeSPSuccessors(); void initializeShortestPaths(); + /* + * Recurses over the path and prints the nodes. Intended for debugging. + */ + void printKShortestPath(state_t targetNode, int k, bool head=true); }; } }