Browse Source

actual test for single-target non-disjoint KSP

Former-commit-id: abb27b9078 [formerly 8492e75c07]
Former-commit-id: c60c829826
tempestpy_adaptions
tomjanson 9 years ago
committed by Tom Janson
parent
commit
d8f2eec9af
  1. 32
      src/test/utility/GraphTest.cpp
  2. 9
      src/utility/shortestPaths.cpp
  3. 4
      src/utility/shortestPaths.h

32
src/test/utility/GraphTest.cpp

@ -268,32 +268,26 @@ 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<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program);
ASSERT_TRUE(model->getType() == storm::models::ModelType::Dtmc);
model->printModelInformationToStream(std::cout);
storm::storage::sparse::state_type testState = 300;
std::cout << "Initializing ShortestPathsGenerator ..." << std::endl;
storm::utility::shortestPaths::ShortestPathsGenerator<double> shortestPathsGenerator(model);
unsigned int k;
storm::storage::sparse::state_type state;
// the 1-shortest path is computed as a preprocessing step via Dijkstra;
// since there were some bugs here in the past, let's test it separately
double dijkstraSPDistance = shortestPathsGenerator.getKShortest(testState, 1);
std::cout << "Res: " << dijkstraSPDistance << std::endl;
//EXPECT_NEAR(0.0158593, dijkstraSPDistance, 0.0000001);
EXPECT_DOUBLE_EQ(0.015859334652581887, dijkstraSPDistance);
while (true) {
std::cout << std::endl;
std::cout << "Enter state (note: 0-based index) ... ";
std::cin >> state;
// main test
double kSPDistance1 = shortestPathsGenerator.getKShortest(testState, 100);
EXPECT_DOUBLE_EQ(1.5231305000339649e-06, kSPDistance1);
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
EXPECT_TRUE(false);
// let's test again to ensure re-entry is no problem
double kSPDistance2 = shortestPathsGenerator.getKShortest(testState, 500);
EXPECT_DOUBLE_EQ(3.0462610000679282e-08, kSPDistance2);
}

9
src/utility/shortestPaths.cpp

@ -192,26 +192,23 @@ namespace storm {
}
template <typename T>
void ShortestPathsGenerator<T>::getKShortest(state_t node, unsigned long k) {
T ShortestPathsGenerator<T>::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) {
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;
return storm::utility::zero<T>(); // TODO: throw exception or something
}
}
std::cout << std::endl << "--> DEBUG: Finished. " << k << "-shortest path:" << std::endl;
printKShortestPath(node, k);
std::cout << "---------" << std::endl;
return kShortestPaths[node][k - 1].distance;
}
template <typename T>

4
src/utility/shortestPaths.h

@ -71,7 +71,9 @@ namespace storm {
~ShortestPathsGenerator();
// TODO: think about suitable output format
void getKShortest(state_t node, unsigned long k);
T getKShortest(state_t node, unsigned long k);
// TODO: allow three kinds of target arguments: single state, BitVector, Label
private:

Loading…
Cancel
Save