Browse Source
			
			
			group targets & minimal paths
			
				
		group targets & minimal paths
	
		
	
			
				Note that this is a major, API-breaking change. Also bunched into this commit: - rename namespace `shortestPaths` to `ksp` - omit unneeded namespace qualifiers - move tests from `GraphTest` to `KSPTest` and wrote more - path representation explanation in .md file Former-commit-id:mainf395c3df40[formerly7fa07d1c8f] Former-commit-id:f50dd3ce7c
							committed by
							
								
								Tom Janson
							
						
					
				
				 5 changed files with 254 additions and 113 deletions
			
			
		- 
					27src/test/utility/GraphTest.cpp
 - 
					150src/utility/shortestPaths.cpp
 - 
					79src/utility/shortestPaths.h
 - 
					42src/utility/shortestPaths.md
 - 
					69test/functional/utility/KSPTest.cpp
 
@ -0,0 +1,69 @@ | 
				
			|||
#include "gtest/gtest.h"
 | 
				
			|||
#include "storm-config.h"
 | 
				
			|||
 | 
				
			|||
#include "src/parser/PrismParser.h"
 | 
				
			|||
#include "src/models/sparse/Dtmc.h"
 | 
				
			|||
#include "src/builder/ExplicitPrismModelBuilder.h"
 | 
				
			|||
#include "src/utility/graph.h"
 | 
				
			|||
#include "src/utility/shortestPaths.cpp"
 | 
				
			|||
 | 
				
			|||
// NOTE: These result values of these tests were generated by the
 | 
				
			|||
//       KSP-Generator itself and checked for gross implausibility, but no
 | 
				
			|||
//       more than that.
 | 
				
			|||
//       An independent verification of the values would be really nice ...
 | 
				
			|||
 | 
				
			|||
TEST(KSPTest, dijkstra) { | 
				
			|||
    storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm"); | 
				
			|||
    std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program); | 
				
			|||
 | 
				
			|||
    storm::storage::sparse::state_type testState = 300; | 
				
			|||
    storm::utility::ksp::ShortestPathsGenerator<double> spg(model, testState); | 
				
			|||
 | 
				
			|||
    double dist = spg.computeKSP(1); | 
				
			|||
    EXPECT_DOUBLE_EQ(0.015859334652581887, dist); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
TEST(KSPTest, singleTarget) { | 
				
			|||
    storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm"); | 
				
			|||
    std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program); | 
				
			|||
 | 
				
			|||
    storm::storage::sparse::state_type testState = 300; | 
				
			|||
    storm::utility::ksp::ShortestPathsGenerator<double> spg(model, testState); | 
				
			|||
 | 
				
			|||
    double dist = spg.computeKSP(100); | 
				
			|||
    EXPECT_DOUBLE_EQ(1.5231305000339649e-06, dist); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
TEST(KSPTest, reentry) { | 
				
			|||
    storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm"); | 
				
			|||
    std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program); | 
				
			|||
 | 
				
			|||
    storm::storage::sparse::state_type testState = 300; | 
				
			|||
    storm::utility::ksp::ShortestPathsGenerator<double> spg(model, testState); | 
				
			|||
 | 
				
			|||
    double dist = spg.computeKSP(100); | 
				
			|||
    EXPECT_DOUBLE_EQ(1.5231305000339649e-06, dist); | 
				
			|||
 | 
				
			|||
    // get another distance to ensure re-entry is no problem
 | 
				
			|||
    double dist2 = spg.computeKSP(500); | 
				
			|||
    EXPECT_DOUBLE_EQ(3.0462610000679282e-08, dist2); | 
				
			|||
} | 
				
			|||
 | 
				
			|||
TEST(KSPTest, groupTarget) { | 
				
			|||
    storm::prism::Program program = storm::parser::PrismParser::parse(STORM_CPP_TESTS_BASE_PATH "/functional/builder/brp-16-2.pm"); | 
				
			|||
    std::shared_ptr<storm::models::sparse::Model<double>> model = storm::builder::ExplicitPrismModelBuilder<double>().translateProgram(program); | 
				
			|||
 | 
				
			|||
    auto spg = storm::utility::ksp::ShortestPathsGenerator<double>(model, storm::utility::ksp::state_list_t{50, 90}); | 
				
			|||
 | 
				
			|||
    // this path should lead to 90
 | 
				
			|||
    double dist1 = spg.computeKSP(8); | 
				
			|||
    EXPECT_DOUBLE_EQ(7.3796982335999988e-06, dist1); | 
				
			|||
 | 
				
			|||
    // this one to 50
 | 
				
			|||
    double dist2 = spg.computeKSP(9); | 
				
			|||
    EXPECT_DOUBLE_EQ(3.92e-06, dist2); | 
				
			|||
 | 
				
			|||
    // this one to 90 again
 | 
				
			|||
    double dist3 = spg.computeKSP(12); | 
				
			|||
    EXPECT_DOUBLE_EQ(3.6160521344640002e-06, dist3); | 
				
			|||
} | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue