diff --git a/docs/examples/bilevel-kkt.rst b/docs/examples/bilevel-kkt.rst index 81e9426b..f2b072b2 100644 --- a/docs/examples/bilevel-kkt.rst +++ b/docs/examples/bilevel-kkt.rst @@ -31,5 +31,5 @@ KKT Reformulation with idol In this example, we show how to model this LP-LP bilevel problem and how to derive its KKT reformulation. -.. literalinclude:: ../../examples/bilevel-optimization/kkt.example.cpp +.. literalinclude:: ../../examples/bilevel/kkt.example.cpp :language: cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 58f762f9..53979940 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,6 +7,5 @@ function(ADD_EXAMPLE NAME) endforeach() endfunction() -add_subdirectory(mixed-integer-optimization) -add_subdirectory(bilevel-optimization) -add_subdirectory(robust-optimization) +add_subdirectory(mixed-integer) +add_subdirectory(bilevel) diff --git a/examples/bilevel-optimization/CMakeLists.txt b/examples/bilevel/CMakeLists.txt similarity index 100% rename from examples/bilevel-optimization/CMakeLists.txt rename to examples/bilevel/CMakeLists.txt diff --git a/examples/bilevel-optimization/kkt.example.cpp b/examples/bilevel/kkt.example.cpp similarity index 100% rename from examples/bilevel-optimization/kkt.example.cpp rename to examples/bilevel/kkt.example.cpp diff --git a/examples/bilevel-optimization/mibs-from-file.data.aux b/examples/bilevel/mibs-from-file.data.aux similarity index 100% rename from examples/bilevel-optimization/mibs-from-file.data.aux rename to examples/bilevel/mibs-from-file.data.aux diff --git a/examples/bilevel-optimization/mibs-from-file.data.mps.gz b/examples/bilevel/mibs-from-file.data.mps.gz similarity index 100% rename from examples/bilevel-optimization/mibs-from-file.data.mps.gz rename to examples/bilevel/mibs-from-file.data.mps.gz diff --git a/examples/bilevel-optimization/mibs-from-file.example.cpp b/examples/bilevel/mibs-from-file.example.cpp similarity index 100% rename from examples/bilevel-optimization/mibs-from-file.example.cpp rename to examples/bilevel/mibs-from-file.example.cpp diff --git a/examples/bilevel-optimization/mibs.example.cpp b/examples/bilevel/mibs.example.cpp similarity index 100% rename from examples/bilevel-optimization/mibs.example.cpp rename to examples/bilevel/mibs.example.cpp diff --git a/examples/bilevel-optimization/padm.example.cpp b/examples/bilevel/padm.example.cpp similarity index 100% rename from examples/bilevel-optimization/padm.example.cpp rename to examples/bilevel/padm.example.cpp diff --git a/examples/mixed-integer-optimization/CMakeLists.txt b/examples/mixed-integer/CMakeLists.txt similarity index 100% rename from examples/mixed-integer-optimization/CMakeLists.txt rename to examples/mixed-integer/CMakeLists.txt diff --git a/examples/mixed-integer-optimization/assignment-bap.data.txt b/examples/mixed-integer/assignment-bap.data.txt similarity index 100% rename from examples/mixed-integer-optimization/assignment-bap.data.txt rename to examples/mixed-integer/assignment-bap.data.txt diff --git a/examples/mixed-integer-optimization/assignment-bap.example.cpp b/examples/mixed-integer/assignment-bap.example.cpp similarity index 100% rename from examples/mixed-integer-optimization/assignment-bap.example.cpp rename to examples/mixed-integer/assignment-bap.example.cpp diff --git a/examples/mixed-integer-optimization/assignment-penalty-bap.data.txt b/examples/mixed-integer/assignment-penalty-bap.data.txt similarity index 100% rename from examples/mixed-integer-optimization/assignment-penalty-bap.data.txt rename to examples/mixed-integer/assignment-penalty-bap.data.txt diff --git a/examples/mixed-integer-optimization/assignment-penalty-bap.example.cpp b/examples/mixed-integer/assignment-penalty-bap.example.cpp similarity index 100% rename from examples/mixed-integer-optimization/assignment-penalty-bap.example.cpp rename to examples/mixed-integer/assignment-penalty-bap.example.cpp diff --git a/examples/mixed-integer-optimization/facility.data.txt b/examples/mixed-integer/facility.data.txt similarity index 100% rename from examples/mixed-integer-optimization/facility.data.txt rename to examples/mixed-integer/facility.data.txt diff --git a/examples/mixed-integer-optimization/facility.example.cpp b/examples/mixed-integer/facility.example.cpp similarity index 100% rename from examples/mixed-integer-optimization/facility.example.cpp rename to examples/mixed-integer/facility.example.cpp diff --git a/examples/mixed-integer-optimization/knapsack.data.txt b/examples/mixed-integer/knapsack.data.txt similarity index 100% rename from examples/mixed-integer-optimization/knapsack.data.txt rename to examples/mixed-integer/knapsack.data.txt diff --git a/examples/mixed-integer-optimization/knapsack.example.cpp b/examples/mixed-integer/knapsack.example.cpp similarity index 100% rename from examples/mixed-integer-optimization/knapsack.example.cpp rename to examples/mixed-integer/knapsack.example.cpp diff --git a/examples/robust-optimization/CMakeLists.txt b/examples/robust-optimization/CMakeLists.txt deleted file mode 100644 index 72beafbc..00000000 --- a/examples/robust-optimization/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_example(robust_ccg) -add_example(robust_convexification) \ No newline at end of file diff --git a/examples/robust-optimization/robust_ccg.data.txt b/examples/robust-optimization/robust_ccg.data.txt deleted file mode 100644 index f62be9d9..00000000 --- a/examples/robust-optimization/robust_ccg.data.txt +++ /dev/null @@ -1,41 +0,0 @@ -10 20 -109.6 131.484 -169.498 103.513 -24.7946 41.8319 -150.331 156.535 -140.651 128.462 -68.8231 66.0825 -5.40097 33.6793 -123.19 113.974 -118.503 152.262 -27.5682 125.587 -36.1992 -5.60365 -10.0339 -20.1965 -17.4686 -35.8237 -14.8866 -2.75196 -36.7471 -2.76135 -12.0892 -16.2641 -11.3815 -8.96618 -32.1548 -13.7501 -0.631599 -26.9407 -36.4762 -10.0098 -0.674345 0.377274 0.60077 0.725902 0.347025 0.648906 0.635155 0.607522 0.333549 0.300607 0.416598 0.628605 0.753687 0.644812 0.405533 0.152511 0.424802 0.261078 0.50283 0.403443 -0.79483 0.0798539 0.347963 0.756363 0.654002 0.484362 0.663717 0.820894 0.220568 0.548021 0.218845 0.779403 0.804299 0.507375 0.592223 0.172742 0.63654 0.0894973 0.819295 0.712606 -0.988408 0.473435 0.741449 1.02582 0.420089 0.859221 0.932609 0.913111 0.206479 0.606641 0.592807 0.943148 1.05883 0.871605 0.719628 0.296455 0.735305 0.405338 0.70923 0.472351 -0.801213 0.930165 1.12413 0.970236 0.281743 1.11036 0.911725 0.579372 0.840547 0.467774 0.937797 0.721997 0.961574 1.08599 0.57822 0.70739 0.533045 0.812734 0.148052 0.238144 -0.033511 0.742563 0.729705 0.21527 0.807152 0.579068 0.209073 0.232984 0.91811 0.384516 0.620859 0.0675881 0.187979 0.528276 0.248045 0.699975 0.263439 0.677736 0.632054 0.831136 -0.379508 0.394834 0.402656 0.338167 0.703938 0.315728 0.243857 0.475284 0.607753 0.336413 0.270847 0.38184 0.381389 0.285442 0.271919 0.405371 0.331478 0.346229 0.681973 0.748633 -1.01954 0.586318 0.852622 1.08059 0.340762 0.955962 0.989606 0.914744 0.331927 0.616543 0.693984 0.966318 1.10785 0.963435 0.742256 0.385068 0.74801 0.505968 0.654321 0.385256 -0.124851 0.647767 0.637432 0.198938 0.766693 0.495492 0.15157 0.278676 0.831333 0.339767 0.525301 0.137635 0.200255 0.446836 0.203461 0.614955 0.238989 0.585824 0.629149 0.796432 -0.822042 0.611747 0.850139 0.920143 0.113758 0.898665 0.836445 0.683577 0.462689 0.406345 0.66767 0.759121 0.93636 0.891583 0.542633 0.376275 0.534339 0.501362 0.400407 0.172095 -0.728693 0.27883 0.523355 0.749647 0.439242 0.602651 0.655937 0.692852 0.235195 0.391798 0.348472 0.692708 0.785082 0.607712 0.47688 0.0436219 0.506139 0.16976 0.61561 0.497567 diff --git a/examples/robust-optimization/robust_ccg.example.cpp b/examples/robust-optimization/robust_ccg.example.cpp deleted file mode 100644 index 04455e56..00000000 --- a/examples/robust-optimization/robust_ccg.example.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// -// Created by henri on 20.06.24. -// -#include -#include -#include "idol/optimizers/bilevel-optimization/wrappers/MibS/MibS.h" -#include "idol/modeling/bilevel-optimization/LowerLevelDescription.h" -#include "idol/mixed-integer/optimizers/wrappers/Gurobi/Gurobi.h" -#include "idol/modeling/bilevel-optimization/read_from_file.h" -#include "idol/mixed-integer/problems/facility-location-problem/FLP_Instance.h" -#include "idol/optimizers/robust-optimization/column-and-constraint-generation/ColumnAndConstraintGeneration.h" -#include "idol/optimizers/robust-optimization/column-and-constraint-generation/separators/Bilevel.h" -#include "idol/modeling/robust-optimization/StageDescription.h" -#include "idol/optimizers/robust-optimization/column-and-constraint-generation/stabilizers/TrustRegion.h" - -using namespace idol; - -std::pair> -create_uncertainty_set(Env& t_env, - const Problems::FLP::Instance& t_instance, - double t_Gamma); - -Model create_deterministic_model(Env& t_env, - const Problems::FLP::Instance& t_instance, - const Vector& t_xi, - double t_percentage_increase); - -Robust::StageDescription create_stage_description(const Model& t_model); - -int main(int t_argc, const char** t_argv) { - - Env env; - - // Read instance - const auto instance = Problems::FLP::read_instance_1991_Cornuejols_et_al("robust_ccg.data.txt"); - const double Gamma = 3; - const double percentage_increase = .2; - - // Create models - auto [uncertainty_set, xi] = create_uncertainty_set(env, instance, Gamma); - auto model = create_deterministic_model(env, instance, xi, percentage_increase); - auto stages = create_stage_description(model); - - model.use( - Robust::ColumnAndConstraintGeneration(stages, uncertainty_set) - .with_master_optimizer(Gurobi()) - .with_separator( - Robust::CCGSeparators::Bilevel() - ) - //.with_complete_recourse(true) - //.with_stabilization(Robust::CCGStabilizers::TrustRegion().with_trust_factors()) - .with_logs(true) - ); - - model.optimize(); - - std::cout << save_primal(model) << std::endl; - - return 0; -} - - -std::pair> -create_uncertainty_set(Env& t_env, const Problems::FLP::Instance& t_instance, double t_Gamma) { - - const unsigned int n_customers = t_instance.n_customers(); - - Model uncertainty_set(t_env); - - auto xi = uncertainty_set.add_vars(Dim<1>(n_customers), 0., 1, Binary, "xi"); - uncertainty_set.add_ctr(idol_Sum(j, Range(n_customers), xi[j]) <= t_Gamma); - - return { - std::move(uncertainty_set), - std::move(xi) - }; -} - -Model -create_deterministic_model(Env& t_env, const Problems::FLP::Instance& t_instance, const Vector& t_xi, double t_percentage_increase) { - - const unsigned int n_customers = t_instance.n_customers(); - const unsigned int n_facilities = t_instance.n_facilities(); - - Model result(t_env); - - const auto x = result.add_vars(Dim<1>(n_facilities), 0., 1., Binary, "x"); - const auto y = result.add_vars(Dim<2>(n_facilities, n_customers), 0., Inf, Continuous, "y"); - - // Capacity constraints - for (unsigned int i = 0 ; i < n_facilities ; ++i) { - result.add_ctr(idol_Sum(j, Range(n_customers), y[i][j]) <= t_instance.capacity(i) * x[i]); - } - - // Demand satisfaction constraints - for (unsigned int j = 0 ; j < n_customers ; ++j) { - result.add_ctr(idol_Sum(i, Range(n_facilities), y[i][j]) == t_instance.demand(j) * (1 + t_percentage_increase * !t_xi[j])); - } - - // Objective function - result.set_obj_expr(idol_Sum(i, Range(n_facilities), - t_instance.fixed_cost(i) * x[i] - + idol_Sum(j, Range(n_customers), - t_instance.per_unit_transportation_cost(i, j) * y[i][j] - ) - ) - ); - - return std::move(result); -} - -Robust::StageDescription create_stage_description(const Model& t_model) { - - Robust::StageDescription result(t_model.env()); - - for (const auto& var : t_model.vars()) { - if (var.name().front() != 'x') { - result.set_stage(var, 2); - } - } - - for (const auto& ctr : t_model.ctrs()) { - result.set_stage(ctr, 2); - } - - return result; -} diff --git a/examples/robust-optimization/robust_convexification.data.txt b/examples/robust-optimization/robust_convexification.data.txt deleted file mode 100644 index f62be9d9..00000000 --- a/examples/robust-optimization/robust_convexification.data.txt +++ /dev/null @@ -1,41 +0,0 @@ -10 20 -109.6 131.484 -169.498 103.513 -24.7946 41.8319 -150.331 156.535 -140.651 128.462 -68.8231 66.0825 -5.40097 33.6793 -123.19 113.974 -118.503 152.262 -27.5682 125.587 -36.1992 -5.60365 -10.0339 -20.1965 -17.4686 -35.8237 -14.8866 -2.75196 -36.7471 -2.76135 -12.0892 -16.2641 -11.3815 -8.96618 -32.1548 -13.7501 -0.631599 -26.9407 -36.4762 -10.0098 -0.674345 0.377274 0.60077 0.725902 0.347025 0.648906 0.635155 0.607522 0.333549 0.300607 0.416598 0.628605 0.753687 0.644812 0.405533 0.152511 0.424802 0.261078 0.50283 0.403443 -0.79483 0.0798539 0.347963 0.756363 0.654002 0.484362 0.663717 0.820894 0.220568 0.548021 0.218845 0.779403 0.804299 0.507375 0.592223 0.172742 0.63654 0.0894973 0.819295 0.712606 -0.988408 0.473435 0.741449 1.02582 0.420089 0.859221 0.932609 0.913111 0.206479 0.606641 0.592807 0.943148 1.05883 0.871605 0.719628 0.296455 0.735305 0.405338 0.70923 0.472351 -0.801213 0.930165 1.12413 0.970236 0.281743 1.11036 0.911725 0.579372 0.840547 0.467774 0.937797 0.721997 0.961574 1.08599 0.57822 0.70739 0.533045 0.812734 0.148052 0.238144 -0.033511 0.742563 0.729705 0.21527 0.807152 0.579068 0.209073 0.232984 0.91811 0.384516 0.620859 0.0675881 0.187979 0.528276 0.248045 0.699975 0.263439 0.677736 0.632054 0.831136 -0.379508 0.394834 0.402656 0.338167 0.703938 0.315728 0.243857 0.475284 0.607753 0.336413 0.270847 0.38184 0.381389 0.285442 0.271919 0.405371 0.331478 0.346229 0.681973 0.748633 -1.01954 0.586318 0.852622 1.08059 0.340762 0.955962 0.989606 0.914744 0.331927 0.616543 0.693984 0.966318 1.10785 0.963435 0.742256 0.385068 0.74801 0.505968 0.654321 0.385256 -0.124851 0.647767 0.637432 0.198938 0.766693 0.495492 0.15157 0.278676 0.831333 0.339767 0.525301 0.137635 0.200255 0.446836 0.203461 0.614955 0.238989 0.585824 0.629149 0.796432 -0.822042 0.611747 0.850139 0.920143 0.113758 0.898665 0.836445 0.683577 0.462689 0.406345 0.66767 0.759121 0.93636 0.891583 0.542633 0.376275 0.534339 0.501362 0.400407 0.172095 -0.728693 0.27883 0.523355 0.749647 0.439242 0.602651 0.655937 0.692852 0.235195 0.391798 0.348472 0.692708 0.785082 0.607712 0.47688 0.0436219 0.506139 0.16976 0.61561 0.497567 diff --git a/examples/robust-optimization/robust_convexification.example.cpp b/examples/robust-optimization/robust_convexification.example.cpp deleted file mode 100644 index 6790c526..00000000 --- a/examples/robust-optimization/robust_convexification.example.cpp +++ /dev/null @@ -1,141 +0,0 @@ -// -// Created by henri on 28.06.24. -// -#include -#include -#include "idol/optimizers/bilevel-optimization/wrappers/MibS/MibS.h" -#include "idol/modeling/bilevel-optimization/LowerLevelDescription.h" -#include "idol/mixed-integer/optimizers/wrappers/Gurobi/Gurobi.h" -#include "idol/modeling/bilevel-optimization/read_from_file.h" -#include "idol/mixed-integer/problems/facility-location-problem/FLP_Instance.h" -#include "idol/optimizers/robust-optimization/column-and-constraint-generation/ColumnAndConstraintGeneration.h" -#include "idol/optimizers/robust-optimization/column-and-constraint-generation/separators/Bilevel.h" -#include "idol/modeling/robust-optimization/StageDescription.h" -#include "idol/optimizers/robust-optimization/column-and-constraint-generation/stabilizers/TrustRegion.h" -#include "idol/mixed-integer/optimizers/dantzig-wolfe/DantzigWolfeDecomposition.h" -#include "idol/optimizers/robust-optimization/convexification/Convexification.h" - -using namespace idol; - -std::pair> -create_uncertainty_set(Env& t_env, - const Problems::FLP::Instance& t_instance, - double t_Gamma); - -Model create_deterministic_model(Env& t_env, - const Problems::FLP::Instance& t_instance, - const Vector& t_xi, - double t_percentage_increase); - -Robust::StageDescription create_stage_description(const Model& t_model); - -int main(int t_argc, const char** t_argv) { - - // Read instance - const auto instance = Problems::FLP::read_instance_1991_Cornuejols_et_al("robust_convexification.data.txt"); - const double Gamma = 3; - const double percentage_increase = .2; - - Env env; - - // Create models - auto [uncertainty_set, xi] = create_uncertainty_set(env, instance, Gamma); - auto model = create_deterministic_model(env, instance, xi, percentage_increase); - auto stages = create_stage_description(model); - - std::cout << model << std::endl; - - model.use( - Robust::Convexification(stages, uncertainty_set) - .with_optimizer( - DantzigWolfeDecomposition() - .with_master_optimizer(Gurobi()) - .with_default_sub_problem_spec(DantzigWolfe::SubProblem().add_optimizer(Gurobi())) - .with_logs(true) - ) - .with_logs(true) - ); - - model.optimize(); - - std::cout << save_primal(model) << std::endl; - - return 0; -} - -std::pair> -create_uncertainty_set(Env& t_env, - const Problems::FLP::Instance& t_instance, - double t_Gamma) { - - const unsigned int n_facilities = t_instance.n_facilities(); - const unsigned int n_customers = t_instance.n_customers(); - - Model uncertainty_set(t_env); - - auto xi = uncertainty_set.add_vars(Dim<2>(n_facilities, n_customers), 0., 1, Binary, "xi"); - uncertainty_set.add_ctr( - idol_Sum(i, Range(n_facilities), - idol_Sum(j, Range(n_customers), xi[i][j]) - ) <= t_Gamma - ); - - return { - std::move(uncertainty_set), - std::move(xi) - }; -} - -Model create_deterministic_model(Env& t_env, - const Problems::FLP::Instance& t_instance, - const Vector& t_xi, - double t_percentage_increase) { - - const unsigned int n_customers = t_instance.n_customers(); - const unsigned int n_facilities = t_instance.n_facilities(); - - Model result(t_env); - - const auto x = result.add_vars(Dim<1>(n_facilities), 0., 1., Binary, "x"); - const auto y = result.add_vars(Dim<2>(n_facilities, n_customers), 0., Inf, Binary, "y"); - - // Capacity constraints - for (unsigned int i = 0 ; i < n_facilities ; ++i) { - result.add_ctr(idol_Sum(j, Range(n_customers), t_instance.demand(j) * y[i][j]) <= t_instance.capacity(i) * x[i]); - } - - // Demand satisfaction constraints - for (unsigned int j = 0 ; j < n_customers ; ++j) { - result.add_ctr(idol_Sum(i, Range(n_facilities), y[i][j]) == 1); - } - - // Objective function - result.set_obj_expr(idol_Sum(i, Range(n_facilities), - t_instance.fixed_cost(i) * x[i] - + idol_Sum(j, Range(n_customers), - t_instance.demand(j) * t_instance.per_unit_transportation_cost(i, j) * (1 + t_percentage_increase * !t_xi[i][j]) * y[i][j] - ) - ) - ); - - return std::move(result); -} - -Robust::StageDescription create_stage_description(const Model& t_model) { - - - Robust::StageDescription result(t_model.env()); - - for (const auto& var : t_model.vars()) { - if (var.name().front() != 'x') { - result.set_stage(var, 2); - } - } - - for (const auto& ctr : t_model.ctrs()) { - result.set_stage(ctr, 2); - } - - return result; - -} \ No newline at end of file