From eeb0ee0b31251058ca9a62ccd34b36d0f3857773 Mon Sep 17 00:00:00 2001 From: Henri Lefebvre Date: Sat, 28 Oct 2023 22:20:04 +0200 Subject: [PATCH] clean results --- examples/CMakeLists.txt | 12 +++- .../instance.txt => assignment.data.txt} | 0 .../main.cpp => assignment.example.cpp} | 33 ++-------- .../facility-location-problem/CMakeLists.txt | 6 -- .../instance.txt => facility.data.txt} | 0 .../main.cpp => facility.example.cpp} | 25 +++---- .../CMakeLists.txt | 7 -- examples/knapsack-problem/CMakeLists.txt | 7 -- examples/knapsack-problem/instance50.txt | 4 -- examples/knapsack-problem/main.cpp | 66 ------------------- .../instance.txt => knapsack.data.txt} | 0 examples/knapsack.example.cpp | 39 +++++++++++ 12 files changed, 63 insertions(+), 136 deletions(-) rename examples/{generalized-assignment-problem/instance.txt => assignment.data.txt} (100%) rename examples/{generalized-assignment-problem/main.cpp => assignment.example.cpp} (64%) delete mode 100644 examples/facility-location-problem/CMakeLists.txt rename examples/{facility-location-problem/instance.txt => facility.data.txt} (100%) rename examples/{facility-location-problem/main.cpp => facility.example.cpp} (64%) delete mode 100644 examples/generalized-assignment-problem/CMakeLists.txt delete mode 100644 examples/knapsack-problem/CMakeLists.txt delete mode 100644 examples/knapsack-problem/instance50.txt delete mode 100644 examples/knapsack-problem/main.cpp rename examples/{knapsack-problem/instance.txt => knapsack.data.txt} (100%) create mode 100644 examples/knapsack.example.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f9e1b933..90ed6746 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,9 @@ -add_subdirectory(generalized-assignment-problem) -add_subdirectory(knapsack-problem) -add_subdirectory(facility-location-problem) \ No newline at end of file +function(ADD_EXAMPLE NAME) + add_executable(example_${NAME} ${NAME}.example.cpp) + target_link_libraries(example_${NAME} PRIVATE idol) + add_custom_command(TARGET example_${NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${NAME}.data.txt $) +endfunction() + +add_example(knapsack) +add_example(facility) +add_example(assignment) diff --git a/examples/generalized-assignment-problem/instance.txt b/examples/assignment.data.txt similarity index 100% rename from examples/generalized-assignment-problem/instance.txt rename to examples/assignment.data.txt diff --git a/examples/generalized-assignment-problem/main.cpp b/examples/assignment.example.cpp similarity index 64% rename from examples/generalized-assignment-problem/main.cpp rename to examples/assignment.example.cpp index 6197a88c..d6743dfa 100644 --- a/examples/generalized-assignment-problem/main.cpp +++ b/examples/assignment.example.cpp @@ -4,24 +4,19 @@ #include #include "idol/modeling.h" #include "idol/problems/generalized-assignment-problem/GAP_Instance.h" -#include "idol/optimizers/column-generation/Optimizers_ColumnGeneration.h" -#include "idol/optimizers/column-generation/ColumnGeneration.h" #include "idol/optimizers/branch-and-bound/node-selection-rules/factories/WorstBound.h" #include "idol/optimizers/branch-and-bound/BranchAndBound.h" -#include "idol/optimizers/wrappers/GLPK/GLPK.h" #include "idol/optimizers/dantzig-wolfe/DantzigWolfeDecomposition.h" #include "idol/optimizers/column-generation/IntegerMaster.h" -#include "idol/optimizers/callbacks/RENS.h" -#include "idol/optimizers/callbacks/LocalBranching.h" #include "idol/optimizers/callbacks/SimpleRounding.h" #include "idol/optimizers/branch-and-bound/branching-rules/factories/MostInfeasible.h" -#include "idol/optimizers/wrappers/Mosek/Mosek.h" +#include "idol/optimizers/wrappers/HiGHS/HiGHS.h" -int main(int t_argc, const char** t_argv) { +using namespace idol; - using namespace idol; +int main(int t_argc, const char** t_argv) { - const auto instance = Problems::GAP::read_instance("/home/henri/Research/idol/tests/data/generalized-assignment-problem/GAP_instance0.txt"); + const auto instance = Problems::GAP::read_instance("assignment.data.txt"); const unsigned int n_agents = instance.n_agents(); const unsigned int n_jobs = instance.n_jobs(); @@ -57,8 +52,8 @@ int main(int t_argc, const char** t_argv) { model.use(BranchAndBound() .with_node_optimizer( DantzigWolfeDecomposition(decomposition) - .with_master_optimizer(Mosek::ContinuousRelaxation()) - .with_pricing_optimizer(Mosek()) + .with_master_optimizer(HiGHS::ContinuousRelaxation()) + .with_pricing_optimizer(HiGHS()) .with_log_level(Info, Yellow) .with_farkas_pricing(true) .with_artificial_variables_cost(1e+4) @@ -71,21 +66,7 @@ int main(int t_argc, const char** t_argv) { .with_node_selection_rule(WorstBound()) .with_log_level(Info, Blue) .with_log_frequency(1) - .with_callback(Heuristics::IntegerMaster().with_optimizer(Mosek())) - /* - .with_callback(Heuristics::IntegerMaster().with_optimizer(GLPK())) - .with_callback( - Heuristics::LocalBranching() - .with_optimizer( - BranchAndBound() - .with_node_optimizer(GLPK::ContinuousRelaxation()) - .with_branching_rule(MostInfeasible()) - .with_node_selection_rule(WorstBound()) - .with_callback(Heuristics::SimpleRounding()) - .with_log_level(Info, Green) - ) - ) - */ + .with_callback(Heuristics::IntegerMaster().with_optimizer(HiGHS())) ); // Solve diff --git a/examples/facility-location-problem/CMakeLists.txt b/examples/facility-location-problem/CMakeLists.txt deleted file mode 100644 index dc08fc50..00000000 --- a/examples/facility-location-problem/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -add_executable(ex_facility_location_problem main.cpp) -target_link_libraries(ex_facility_location_problem PUBLIC idol) - -add_custom_command(TARGET ex_facility_location_problem POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/instance.txt $/instance.txt -) diff --git a/examples/facility-location-problem/instance.txt b/examples/facility.data.txt similarity index 100% rename from examples/facility-location-problem/instance.txt rename to examples/facility.data.txt diff --git a/examples/facility-location-problem/main.cpp b/examples/facility.example.cpp similarity index 64% rename from examples/facility-location-problem/main.cpp rename to examples/facility.example.cpp index a17009ee..87ef9ca8 100644 --- a/examples/facility-location-problem/main.cpp +++ b/examples/facility.example.cpp @@ -5,25 +5,18 @@ #include "idol/modeling.h" #include "idol/problems/facility-location-problem/FLP_Instance.h" #include "idol/optimizers/branch-and-bound/BranchAndBound.h" -#include "idol/optimizers/wrappers/Gurobi/Gurobi.h" -#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/BestBound.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/VariableBranching.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/MostInfeasible.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/UniformlyRandom.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/StrongBranching.h" -#include "idol/optimizers/branch-and-bound/branching-rules/impls/strong-branching/StrongBranchingPhase.h" #include "idol/optimizers/branch-and-bound/branching-rules/factories/PseudoCost.h" -#include "idol/optimizers/branch-and-bound/nodes/NodeVarInfo.h" #include "idol/optimizers/branch-and-bound/node-selection-rules/factories/BestEstimate.h" +#include "idol/optimizers/wrappers/HiGHS/HiGHS.h" -int main(int t_argc, const char** t_argv) { +using namespace idol; - using namespace idol; +int main(int t_argc, const char** t_argv) { Env env; // Read instance - const auto instance = Problems::FLP::read_instance_1991_Cornuejols_et_al("instance.txt"); + const auto instance = Problems::FLP::read_instance_1991_Cornuejols_et_al("facility.data.txt"); const unsigned int n_customers = instance.n_customers(); const unsigned int n_facilities = instance.n_facilities(); @@ -55,12 +48,10 @@ int main(int t_argc, const char** t_argv) { // Set backend options model.use( BranchAndBound() - .with_node_optimizer(Gurobi::ContinuousRelaxation()) - .with_branching_rule( - PseudoCost() - ) - .with_node_selection_rule(BestEstimate()) - .with_log_level(Trace, Blue) + .with_node_optimizer(HiGHS::ContinuousRelaxation()) + .with_branching_rule(PseudoCost()) + .with_node_selection_rule(BestEstimate()) + .with_log_level(Trace, Blue) ); model.optimize(); diff --git a/examples/generalized-assignment-problem/CMakeLists.txt b/examples/generalized-assignment-problem/CMakeLists.txt deleted file mode 100644 index 96bd3423..00000000 --- a/examples/generalized-assignment-problem/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_executable(ex_generalized_assignment_problem main.cpp) -target_link_libraries(ex_generalized_assignment_problem PUBLIC idol) - - -add_custom_command(TARGET ex_generalized_assignment_problem POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/instance.txt $/instance.txt -) diff --git a/examples/knapsack-problem/CMakeLists.txt b/examples/knapsack-problem/CMakeLists.txt deleted file mode 100644 index 9f3fe512..00000000 --- a/examples/knapsack-problem/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_executable(ex_knapsack_problem main.cpp) -target_link_libraries(ex_knapsack_problem PUBLIC idol) - - -add_custom_command(TARGET ex_knapsack_problem POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/instance.txt $/instance.txt -) diff --git a/examples/knapsack-problem/instance50.txt b/examples/knapsack-problem/instance50.txt deleted file mode 100644 index 167c82b3..00000000 --- a/examples/knapsack-problem/instance50.txt +++ /dev/null @@ -1,4 +0,0 @@ -50 -845 758 421 259 512 405 784 304 477 584 909 505 282 756 619 251 910 983 811 903 311 730 899 684 473 101 435 611 914 967 478 866 261 806 549 15 720 399 825 669 2 494 868 244 326 871 192 568 239 968 -804 448 81 321 508 933 110 552 707 548 815 541 964 604 588 445 597 385 576 291 190 187 613 657 477 90 758 877 924 843 899 924 541 392 706 276 812 850 896 590 950 580 451 661 997 917 794 83 613 487 -14778 \ No newline at end of file diff --git a/examples/knapsack-problem/main.cpp b/examples/knapsack-problem/main.cpp deleted file mode 100644 index b0b2b6f7..00000000 --- a/examples/knapsack-problem/main.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Created by henri on 06/04/23. -// -#include -#include -#include "idol/problems/knapsack-problem/KP_Instance.h" -#include "idol/modeling.h" -#include "idol/optimizers/wrappers/Gurobi/Gurobi.h" -#include "idol/optimizers/branch-and-bound/BranchAndBound.h" -#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/BestBound.h" -#include "idol/optimizers/branch-and-bound/cutting-planes/CoverCuts.h" -#include "idol/optimizers/callbacks/SimpleRounding.h" -#include "idol/optimizers/callbacks/RENS.h" -#include "idol/optimizers/callbacks/LocalBranching.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/VariableBranching.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/MostInfeasible.h" -#include "idol/optimizers/wrappers/HiGHS/HiGHS.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/Diver.h" -#include "idol/optimizers/branch-and-bound/watchers/ExportBranchAndBoundTreeToCSV.h" -#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/DepthFirst.h" -#include "idol/optimizers/branch-and-bound/branching-rules/factories/PseudoCost.h" -#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/WorstBound.h" -#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/BreadthFirst.h" -#include "idol/optimizers/branch-and-bound/node-selection-rules/factories/BestEstimate.h" - -int main(int t_argc, const char** t_argv) { - - using namespace idol; - - const auto instance = Problems::KP::read_instance("instance.txt"); - //const auto instance = Problems::KP::read_instance("/home/henri/Research/idol/examples/knapsack-problem/instance50.txt"); - - const auto n_items = instance.n_items(); - - Env env; - - // Create model - Model model(env); - - auto x = model.add_vars(Dim<1>(n_items), 0, 1, Binary, "x"); - - model.add_ctr(idol_Sum(j, Range(n_items), instance.weight(j) * x[j]) <= instance.capacity()); - - model.set_obj_expr(idol_Sum(j, Range(n_items), -instance.profit(j) * x[j])); - - // Set optimizer - model.use( - BranchAndBound() - .with_node_optimizer(HiGHS::ContinuousRelaxation()) - .with_branching_rule(PseudoCost()) - .with_callback(Utils::ExportBranchAndBoundTreeToCSV("tree.csv")) - //.with_callback(Heuristics::SimpleRounding()) - .with_node_selection_rule(BestEstimate()) - .with_log_level(Info, Blue) - .with_log_frequency(1) - ); - // model.use(HiGHS()); - // Solve - model.optimize(); - - std::cout << "Objective value = " << model.get_best_obj() << std::endl; - - std::cout << save_primal(model) << std::endl; - - return 0; -} diff --git a/examples/knapsack-problem/instance.txt b/examples/knapsack.data.txt similarity index 100% rename from examples/knapsack-problem/instance.txt rename to examples/knapsack.data.txt diff --git a/examples/knapsack.example.cpp b/examples/knapsack.example.cpp new file mode 100644 index 00000000..0dff334f --- /dev/null +++ b/examples/knapsack.example.cpp @@ -0,0 +1,39 @@ +// +// Created by henri on 06/04/23. +// +#include +#include "idol/problems/knapsack-problem/KP_Instance.h" +#include "idol/modeling.h" +#include "idol/optimizers/wrappers/HiGHS/HiGHS.h" + +using namespace idol; + +int main(int t_argc, const char** t_argv) { + + const auto instance = Problems::KP::read_instance("facility.data.txt"); + + const auto n_items = instance.n_items(); + + Env env; + + // Create model + Model model(env); + + auto x = model.add_vars(Dim<1>(n_items), 0, 1, Binary, "x"); + + model.add_ctr(idol_Sum(j, Range(n_items), instance.weight(j) * x[j]) <= instance.capacity()); + + model.set_obj_expr(idol_Sum(j, Range(n_items), -instance.profit(j) * x[j])); + + // Set optimizer + model.use(HiGHS()); + + // Solve + model.optimize(); + + std::cout << "Objective value = " << model.get_best_obj() << std::endl; + + std::cout << save_primal(model) << std::endl; + + return 0; +}