-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
300 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include "knapsacksolver/subset_sum/solution.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
namespace knapsacksolver | ||
{ | ||
namespace subset_sum | ||
{ | ||
|
||
std::string get_path(const std::vector<std::string>& path); | ||
|
||
struct TestInstancePath | ||
{ | ||
std::string instance_path; | ||
std::string instance_format; | ||
std::string certificate_path; | ||
std::string certificate_format; | ||
}; | ||
|
||
std::vector<TestInstancePath> get_pthree_instance_paths( | ||
ItemId number_of_items); | ||
|
||
std::vector<TestInstancePath> get_psix_instance_paths( | ||
ItemId number_of_items); | ||
|
||
using Algorithm = std::function<const Output(const Instance&)>; | ||
|
||
struct TestParams | ||
{ | ||
Algorithm algorithm; | ||
TestInstancePath files; | ||
}; | ||
|
||
std::vector<TestParams> get_test_params( | ||
const std::vector<Algorithm>& algorithms, | ||
const std::vector<std::vector<TestInstancePath>>& instance_paths); | ||
|
||
const Instance get_instance( | ||
const TestInstancePath& files); | ||
|
||
const Solution get_solution( | ||
const Instance& instance, | ||
const TestInstancePath& files); | ||
|
||
class ExactAlgorithmTest: public testing::TestWithParam<TestParams> { }; | ||
class ExactNoSolutionAlgorithmTest: public testing::TestWithParam<TestParams> { }; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include "knapsacksolver/subset_sum/tests.hpp" | ||
|
||
#include "knapsacksolver/subset_sum/instance_builder.hpp" | ||
|
||
#include <boost/filesystem.hpp> | ||
|
||
using namespace knapsacksolver::subset_sum; | ||
|
||
namespace fs = boost::filesystem; | ||
|
||
std::string knapsacksolver::subset_sum::get_path( | ||
const std::vector<std::string>& path) | ||
{ | ||
if (path.empty()) | ||
return ""; | ||
fs::path p(path[0]); | ||
for (size_t i = 1; i < path.size(); ++i) | ||
p /= path[i]; | ||
return p.string(); | ||
} | ||
|
||
std::vector<TestInstancePath> knapsacksolver::subset_sum::get_pthree_instance_paths( | ||
ItemId number_of_items) | ||
{ | ||
std::vector<TestInstancePath> instance_paths; | ||
for (int i = 0; i < 100; ++i) { | ||
instance_paths.push_back({ | ||
get_path({"pthree", "pthree_" + std::to_string(number_of_items) + "_" + std::to_string(i)}), "standard", | ||
get_path({"pthree", "pthree_" + std::to_string(number_of_items) + "_" + std::to_string(i) + "_solution.txt"}), "standard"}); | ||
} | ||
return instance_paths; | ||
} | ||
|
||
std::vector<TestInstancePath> knapsacksolver::subset_sum::get_psix_instance_paths( | ||
ItemId number_of_items) | ||
{ | ||
std::vector<TestInstancePath> instance_paths; | ||
for (int i = 0; i < 100; ++i) { | ||
instance_paths.push_back({ | ||
get_path({"psix", "psix_" + std::to_string(number_of_items) + "_" + std::to_string(i)}), "standard", | ||
get_path({"psix", "psix_" + std::to_string(number_of_items) + "_" + std::to_string(i) + "_solution.txt"}), "standard"}); | ||
} | ||
return instance_paths; | ||
} | ||
|
||
std::vector<TestParams> knapsacksolver::subset_sum::get_test_params( | ||
const std::vector<Algorithm>& algorithms, | ||
const std::vector<std::vector<TestInstancePath>>& instance_paths) | ||
{ | ||
std::vector<TestParams> res; | ||
for (const Algorithm& algorithm: algorithms) { | ||
for (const auto& v: instance_paths) { | ||
for (const TestInstancePath& files: v) { | ||
TestParams test_params; | ||
test_params.algorithm = algorithm; | ||
test_params.files = files; | ||
res.push_back(test_params); | ||
} | ||
} | ||
} | ||
return res; | ||
} | ||
|
||
const Instance knapsacksolver::subset_sum::get_instance( | ||
const TestInstancePath& files) | ||
{ | ||
InstanceBuilder instance_builder; | ||
std::string instance_path = get_path({ | ||
std::getenv("SUBSET_SUM_DATA"), | ||
files.instance_path}); | ||
std::cout << "Instance path: " << instance_path << std::endl; | ||
instance_builder.read( | ||
instance_path, | ||
files.instance_format); | ||
return instance_builder.build(); | ||
} | ||
|
||
const Solution knapsacksolver::subset_sum::get_solution( | ||
const Instance& instance, | ||
const TestInstancePath& files) | ||
{ | ||
std::string certificate_path = get_path({ | ||
std::getenv("SUBSET_SUM_DATA"), | ||
files.certificate_path}); | ||
return Solution( | ||
instance, | ||
certificate_path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
add_executable(KnapsackSolver_subset_sum_dynamic_programming_bellman_test) | ||
target_sources(KnapsackSolver_subset_sum_dynamic_programming_bellman_test PRIVATE | ||
dynamic_programming_bellman_test.cpp) | ||
target_link_libraries(KnapsackSolver_subset_sum_dynamic_programming_bellman_test | ||
KnapsackSolver_subset_sum_dynamic_programming_bellman | ||
KnapsackSolver_subset_sum_tests | ||
GTest::gtest_main) | ||
add_test(KnapsackSolver_subset_sum_dynamic_programming_bellman_test KnapsackSolver_subset_sum_dynamic_programming_bellman_test) |
Oops, something went wrong.