From d6c6b9b8d51761781b7fdb07172f2cfa486322f7 Mon Sep 17 00:00:00 2001 From: tomjanson Date: Tue, 27 Oct 2015 02:14:36 +0100 Subject: [PATCH] path printing print path ammendment: off-by-one Former-commit-id: cdeb58711b7f062ee274b2fadb0427b3a82a5087 [formerly abd5a8777f8feb17877b085be0ad8e2e756a5c68] Former-commit-id: 506ce7fc90d65dfe1ab2c429621678be0b901c24 --- src/utility/shortestPaths.cpp | 20 ++++++++++++++++++++ src/utility/shortestPaths.h | 8 ++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) 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); }; } }