From 140597fb9060546f7652c53adbece0ad9afa4512 Mon Sep 17 00:00:00 2001 From: tomjanson Date: Wed, 28 Oct 2015 15:34:30 +0100 Subject: [PATCH] interactive debug in test Former-commit-id: 161afac16e738af2f0f076f6d3518b989e9bb35c [formerly 17962bf2008e1546a56a72cfd3afed20f1019650] Former-commit-id: 53dc4819cfedcbdd169a593b8bbae3f22cc1a97b --- src/test/utility/GraphTest.cpp | 17 ++++++++++++++--- src/utility/shortestPaths.cpp | 23 +++++++++++++---------- src/utility/shortestPaths.h | 11 ++++++++++- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/test/utility/GraphTest.cpp b/src/test/utility/GraphTest.cpp index 0d43c02ad..98359a364 100644 --- a/src/test/utility/GraphTest.cpp +++ b/src/test/utility/GraphTest.cpp @@ -268,18 +268,29 @@ TEST(GraphTest, ExplicitProb01MinMax) { TEST(GraphTest, kshortest) { storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm"); + //storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/../examples/dtmc/die/die.pm"); std::shared_ptr> model = storm::builder::ExplicitPrismModelBuilder().translateProgram(program); ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc); model->printModelInformationToStream(std::cout); + std::cout << "Initializing ShortestPathsGenerator ..." << std::endl; storm::utility::shortestPaths::ShortestPathsGenerator shortestPathsGenerator(model); - storm::storage::sparse::state_type exampleState = 50; + unsigned int k; + storm::storage::sparse::state_type state; - for (int i = 1; i < 20; i++) { - auto foo = shortestPathsGenerator.getKShortest(exampleState, i); + while (true) { + std::cout << std::endl; + std::cout << "Enter state (note: 0-based index) ... "; + std::cin >> state; + + std::cout << "Enter k ... "; + std::cin >> k; + + std::cout << "Computing " << k << "-shortest path to state " << state << std::endl; + shortestPathsGenerator.getKShortest(state, k); } // TODO: actually write tests here diff --git a/src/utility/shortestPaths.cpp b/src/utility/shortestPaths.cpp index 9a51e7c7c..cb053b5e5 100644 --- a/src/utility/shortestPaths.cpp +++ b/src/utility/shortestPaths.cpp @@ -55,7 +55,7 @@ namespace storm { // set serves as priority queue with unique membership // default comparison on pair actually works fine if distance is the first entry - std::set, std::greater_equal>> dijkstraQueue; + std::set, std::greater>> dijkstraQueue; for (state_t initialState : model->getInitialStates()) { shortestPathDistances[initialState] = zeroDistance; @@ -192,23 +192,26 @@ namespace storm { } template - Path ShortestPathsGenerator::getKShortest(state_t node, unsigned long k) { + void ShortestPathsGenerator::getKShortest(state_t node, unsigned long k) { unsigned long alreadyComputedK = kShortestPaths[node].size(); +// std::cout << std::endl << "--> DEBUG: Dijkstra SP to " << node << ":" << std::endl; +// printKShortestPath(node, 1); +// std::cout << "---------" << std::endl; + for (unsigned long nextK = alreadyComputedK + 1; nextK <= k; nextK++) { computeNextPath(node, nextK); if (kShortestPaths[node].size() < nextK) { - break; + std::cout << std::endl << "--> DEBUG: Last path: k=" << (nextK - 1) << ":" << std::endl; + printKShortestPath(node, nextK - 1); + std::cout << "---------" << "No other path exists!" << std::endl; + return; } } - if (kShortestPaths[node].size() >= k) { - printKShortestPath(node, k); // DEBUG - } else { - std::cout << "No other path exists!" << std::endl; - } - - return kShortestPaths[node][k - 1]; + std::cout << std::endl << "--> DEBUG: Finished. " << k << "-shortest path:" << std::endl; + printKShortestPath(node, k); + std::cout << "---------" << std::endl; } template diff --git a/src/utility/shortestPaths.h b/src/utility/shortestPaths.h index 6aba88434..3b65ce22a 100644 --- a/src/utility/shortestPaths.h +++ b/src/utility/shortestPaths.h @@ -7,6 +7,15 @@ #include "src/storage/sparse/StateType.h" #include "constants.h" +/* + * TODO: + * - take care of self-loops of target states + * - implement target group + * - think about how to get paths with new nodes, rather than different + * paths over the same set of states (which happens often) + */ + + namespace storm { namespace utility { namespace shortestPaths { @@ -62,7 +71,7 @@ namespace storm { ~ShortestPathsGenerator(); // TODO: think about suitable output format - Path getKShortest(state_t node, unsigned long k); + void getKShortest(state_t node, unsigned long k); private: