Skip to content

Commit 980ed6e

Browse files
committed
Add fill solution file executable
1 parent 07d7644 commit 980ed6e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/irregular/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ if(PACKINGSOLVER_BUILD_MAIN)
3535
Boost::program_options)
3636
set_target_properties(PackingSolver_irregular_main PROPERTIES OUTPUT_NAME "packingsolver_irregular")
3737
install(TARGETS PackingSolver_irregular_main)
38+
39+
add_executable(PackingSolver_irregular_fill_solution_file)
40+
target_sources(PackingSolver_irregular_fill_solution_file PRIVATE
41+
fill_solution_file_main.cpp)
42+
target_link_libraries(PackingSolver_irregular_fill_solution_file PUBLIC
43+
PackingSolver_irregular
44+
Boost::program_options)
45+
set_target_properties(PackingSolver_irregular_fill_solution_file PROPERTIES OUTPUT_NAME "fill_solution_file")
46+
install(TARGETS PackingSolver_irregular_fill_solution_file)
3847
endif()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "packingsolver/irregular/instance_builder.hpp"
2+
#include "packingsolver/irregular/solution.hpp"
3+
4+
#include <boost/program_options.hpp>
5+
6+
using namespace packingsolver;
7+
using namespace packingsolver::irregular;
8+
namespace po = boost::program_options;
9+
10+
int main(int argc, char *argv[])
11+
{
12+
po::options_description desc("Allowed options");
13+
desc.add_options()
14+
(",h", "Produce help message")
15+
("instance,i", po::value<std::string>()->required(), "Instance path")
16+
("solution,s", po::value<std::string>()->required(), "Solution path")
17+
;
18+
po::positional_options_description pod;
19+
pod.add("instance", 1);
20+
pod.add("solution", 1);
21+
22+
po::variables_map vm;
23+
po::store(po::command_line_parser(argc, argv).options(desc).positional(pod).run(), vm);
24+
if (vm.count("help")) {
25+
std::cout << desc << std::endl;
26+
return 1;
27+
}
28+
try {
29+
po::notify(vm);
30+
} catch (const po::required_option& e) {
31+
std::cout << desc << std::endl;
32+
return 1;
33+
}
34+
35+
InstanceBuilder instance_builder;
36+
instance_builder.read(vm["instance"].as<std::string>());
37+
Instance instance = instance_builder.build();
38+
39+
const std::string solution_path = vm["solution"].as<std::string>();
40+
Solution solution(instance, solution_path);
41+
solution.write(solution_path);
42+
43+
return 0;
44+
}

0 commit comments

Comments
 (0)