You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
3.0 KiB

  1. #include "gtest/gtest.h"
  2. #include "storm-config.h"
  3. #include "src/parser/PrismParser.h"
  4. #include "src/models/sparse/Dtmc.h"
  5. #include "src/builder/ExplicitPrismModelBuilder.h"
  6. #include "src/utility/graph.h"
  7. #include "src/utility/shortestPaths.cpp"
  8. // NOTE: These result values of these tests were generated by the
  9. // KSP-Generator itself and checked for gross implausibility, but no
  10. // more than that.
  11. // An independent verification of the values would be really nice ...
  12. TEST(KSPTest, dijkstra) {
  13. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  14. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program);
  15. storm::storage::sparse::state_type testState = 300;
  16. storm::utility::ksp::ShortestPathsGenerator<double> spg(model, testState);
  17. double dist = spg.computeKSP(1);
  18. EXPECT_DOUBLE_EQ(0.015859334652581887, dist);
  19. }
  20. TEST(KSPTest, singleTarget) {
  21. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  22. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program);
  23. storm::storage::sparse::state_type testState = 300;
  24. storm::utility::ksp::ShortestPathsGenerator<double> spg(model, testState);
  25. double dist = spg.computeKSP(100);
  26. EXPECT_DOUBLE_EQ(1.5231305000339649e-06, dist);
  27. }
  28. TEST(KSPTest, reentry) {
  29. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  30. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program);
  31. storm::storage::sparse::state_type testState = 300;
  32. storm::utility::ksp::ShortestPathsGenerator<double> spg(model, testState);
  33. double dist = spg.computeKSP(100);
  34. EXPECT_DOUBLE_EQ(1.5231305000339649e-06, dist);
  35. // get another distance to ensure re-entry is no problem
  36. double dist2 = spg.computeKSP(500);
  37. EXPECT_DOUBLE_EQ(3.0462610000679282e-08, dist2);
  38. }
  39. TEST(KSPTest, groupTarget) {
  40. storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm");
  41. std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program);
  42. auto spg = storm::utility::ksp::ShortestPathsGenerator<double>(model, storm::utility::ksp::state_list_t{50, 90});
  43. // this path should lead to 90
  44. double dist1 = spg.computeKSP(8);
  45. EXPECT_DOUBLE_EQ(7.3796982335999988e-06, dist1);
  46. // this one to 50
  47. double dist2 = spg.computeKSP(9);
  48. EXPECT_DOUBLE_EQ(3.92e-06, dist2);
  49. // this one to 90 again
  50. double dist3 = spg.computeKSP(12);
  51. EXPECT_DOUBLE_EQ(3.6160521344640002e-06, dist3);
  52. }