Skip to content

Commit

Permalink
add column pool clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
hlefebvr committed Nov 1, 2023
1 parent 5c4d4ba commit fad0587
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 26 deletions.
20 changes: 10 additions & 10 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ add_library(idol STATIC
src/optimizers/wrappers/MinKnap/MinKnap.cpp
src/optimizers/wrappers/MinKnap/Optimizers_MinKnap.cpp
include/idol/optimizers/dantzig-wolfe/DantzigWolfeDecomposition.h
src/optimizers/column-generation/DantzigWolfeDecomposition.cpp
include/idol/optimizers/dantzig-wolfe/DantzigWolfeSubProblem.h
src/optimizers/column-generation/DantzigWolfeSubProblem.cpp
include/idol/optimizers/dantzig-wolfe/DantzigWolfeFormulation.h
src/optimizers/column-generation/DantzigWolfeFormulation.cpp
src/optimizers/dantzig-wolfe/DantzigWolfeDecomposition.cpp
include/idol/optimizers/dantzig-wolfe/SubProblem.h
src/optimizers/dantzig-wolfe/SubProblem.cpp
include/idol/optimizers/dantzig-wolfe/Formulation.h
src/optimizers/dantzig-wolfe/Formulation.cpp
include/idol/optimizers/dantzig-wolfe/Optimizers_DantzigWolfeDecomposition.h
src/optimizers/column-generation/Optimizers_DantzigWolfeDecomposition.cpp
src/optimizers/dantzig-wolfe/Optimizers_DantzigWolfeDecomposition.cpp
include/idol/optimizers/dantzig-wolfe/infeasibility-strategies/DantzigWolfeInfeasibilityStrategy.h
include/idol/optimizers/dantzig-wolfe/column-generation/ColumnGeneration.h
src/optimizers/column-generation/column-generation/ColumnGeneration.cpp
include/idol/optimizers/dantzig-wolfe/ColumnGeneration.h
src/optimizers/dantzig-wolfe/ColumnGeneration.cpp
include/idol/optimizers/dantzig-wolfe/infeasibility-strategies/FarkasPricing.h
src/optimizers/column-generation/infeasibility-strategies/FarkasPricing.cpp
src/optimizers/column-generation/infeasibility-strategies/DantzigWolfeInfeasibilityStrategy.cpp
src/optimizers/dantzig-wolfe/infeasibility-strategies/FarkasPricing.cpp
src/optimizers/dantzig-wolfe/infeasibility-strategies/DantzigWolfeInfeasibilityStrategy.cpp
include/idol/optimizers/dantzig-wolfe/stabilization/DualPriceSmoothingStabilization.h
include/idol/optimizers/dantzig-wolfe/stabilization/Neame.h
include/idol/optimizers/dantzig-wolfe/stabilization/Wentges.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef IDOL_COLUMNGENERATION_H
#define IDOL_COLUMNGENERATION_H

#include "../Optimizers_DantzigWolfeDecomposition.h"
#include "Optimizers_DantzigWolfeDecomposition.h"

class idol::Optimizers::DantzigWolfeDecomposition::ColumnGeneration {
DantzigWolfeDecomposition& m_parent;
Expand Down Expand Up @@ -33,6 +33,7 @@ class idol::Optimizers::DantzigWolfeDecomposition::ColumnGeneration {
void solve_sub_problems_in_parallel();
void analyze_sub_problems();
void enrich_master();
void pool_clean_up();
public:
ColumnGeneration(DantzigWolfeDecomposition& t_parent, bool t_use_farkas_for_infeasibility);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "idol/optimizers/OptimizerFactory.h"
#include "idol/modeling/annotations/Annotation.h"
#include "DantzigWolfeSubProblem.h"
#include "SubProblem.h"
#include "idol/containers/Map.h"
#include "DantzigWolfeFormulation.h"
#include "Formulation.h"
#include "idol/optimizers/dantzig-wolfe/infeasibility-strategies/DantzigWolfeInfeasibilityStrategy.h"
#include "idol/optimizers/dantzig-wolfe/stabilization/DualPriceSmoothingStabilization.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by henri on 31.10.23.
//

#ifndef IDOL_DANTZIGWOLFEFORMULATION_H
#define IDOL_DANTZIGWOLFEFORMULATION_H
#ifndef IDOL_FORMULATION_H
#define IDOL_FORMULATION_H

#include "idol/modeling/models/Model.h"
#include "idol/containers/GeneratorPool.h"
Expand Down Expand Up @@ -61,6 +61,8 @@ class idol::DantzigWolfe::Formulation {
Model& get_model(const Ctr& t_ctr);
const Model& get_model(const Ctr& t_ctr) const;

const GeneratorPool<Var>& column_pool(unsigned int t_sub_problem_id) const { return m_pools[t_sub_problem_id]; }

unsigned int n_sub_problems() const { return m_sub_problems.size(); }

void add_aggregation_constraint(unsigned int t_sub_problem_id, double t_lower_multiplicity, double t_upper_multiplicity);
Expand All @@ -80,6 +82,8 @@ class idol::DantzigWolfe::Formulation {
void remove_column_if(unsigned int t_sub_problem_id, const std::function<bool(const Var &, const Solution::Primal &)> &t_indicator_for_removal);

void update_obj(const Expr<Var, Var>& t_expr);

void clean_up(unsigned int t_sub_problem_id, double t_ratio);
};

#endif //IDOL_DANTZIGWOLFEFORMULATION_H
#endif //IDOL_FORMULATION_H
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define IDOL_OPTIMIZERS_DANTZIGWOLFEDECOMPOSITION_H

#include "idol/optimizers/Algorithm.h"
#include "DantzigWolfeFormulation.h"
#include "DantzigWolfeSubProblem.h"
#include "Formulation.h"
#include "SubProblem.h"
#include "idol/optimizers/dantzig-wolfe/infeasibility-strategies/DantzigWolfeInfeasibilityStrategy.h"
#include "idol/optimizers/dantzig-wolfe/stabilization/DualPriceSmoothingStabilization.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by henri on 31.10.23.
//

#ifndef IDOL_DANTZIGWOLFESUBPROBLEM_H
#define IDOL_DANTZIGWOLFESUBPROBLEM_H
#ifndef IDOL_SUBPROBLEM_H
#define IDOL_SUBPROBLEM_H

#include <list>
#include <memory>
Expand All @@ -22,6 +22,7 @@ class idol::DantzigWolfe::SubProblem {
std::list<std::unique_ptr<OptimizerFactory>> m_phase_optimizers;

std::optional<unsigned int> m_max_column_per_pricing;
std::optional<std::pair<unsigned int, double>> m_column_pool_clean_up_parameters; // threshold, ratio
public:
SubProblem() = default;

Expand All @@ -41,15 +42,21 @@ class idol::DantzigWolfe::SubProblem {

SubProblem& with_max_column_per_pricing(unsigned int t_n_columns);

SubProblem& with_column_pool_clean_up(unsigned int t_threshold, double t_ratio);

unsigned int max_column_per_pricing() const { return m_max_column_per_pricing.has_value() ? m_max_column_per_pricing.value() : 1; }

double lower_multiplicity() const;

double upper_multiplicity() const;

unsigned int column_pool_clean_up_threshold() const;

double column_pool_clean_up_ratio() const;

using PhaseId = std::list<std::unique_ptr<OptimizerFactory>>::const_iterator;

auto phases() const { return ConstIteratorForward(m_phase_optimizers); }
};

#endif //IDOL_DANTZIGWOLFESUBPROBLEM_H
#endif //IDOL_SUBPROBLEM_H
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Created by henri on 31.10.23.
//
#include "idol/optimizers/dantzig-wolfe/column-generation/ColumnGeneration.h"
#include "idol/optimizers/dantzig-wolfe/ColumnGeneration.h"

idol::Optimizers::DantzigWolfeDecomposition::ColumnGeneration::ColumnGeneration(DantzigWolfeDecomposition &t_parent,
bool t_use_farkas_for_infeasibility)
Expand Down Expand Up @@ -50,6 +50,8 @@ void idol::Optimizers::DantzigWolfeDecomposition::ColumnGeneration::execute() {

enrich_master();

pool_clean_up();

}

if (m_status == Feasible || m_status == Optimal) {
Expand Down Expand Up @@ -292,3 +294,19 @@ void idol::Optimizers::DantzigWolfeDecomposition::ColumnGeneration::initialize_s
}

}

void idol::Optimizers::DantzigWolfeDecomposition::ColumnGeneration::pool_clean_up() {

auto& formulation = m_parent.m_formulation;
unsigned int n_sub_problems = formulation.n_sub_problems();
for (unsigned int i = 0 ; i < n_sub_problems ; ++i) {
const auto& sub_problem_specifications = m_parent.m_sub_problem_specifications[i];
const auto& column_pool = formulation.column_pool(i);
const unsigned int threshold = sub_problem_specifications.column_pool_clean_up_threshold();
if (column_pool.size() >= threshold) {
const double ratio = sub_problem_specifications.column_pool_clean_up_ratio();
formulation.clean_up(i, ratio);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <memory>

#include "idol/optimizers/dantzig-wolfe/DantzigWolfeDecomposition.h"
#include "idol/optimizers/dantzig-wolfe/DantzigWolfeFormulation.h"
#include "idol/optimizers/dantzig-wolfe/Formulation.h"
#include "idol/optimizers/dantzig-wolfe/Optimizers_DantzigWolfeDecomposition.h"
#include "idol/optimizers/dantzig-wolfe/infeasibility-strategies/FarkasPricing.h"
#include "idol/optimizers/dantzig-wolfe/stabilization/NoStabilization.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
#include <utility>

#include "idol/optimizers/dantzig-wolfe/DantzigWolfeFormulation.h"
#include "idol/optimizers/dantzig-wolfe/Formulation.h"
#include "idol/modeling/objects/Env.h"
#include "idol/modeling/expressions/operations/operators.h"

Expand Down Expand Up @@ -528,3 +528,49 @@ void idol::DantzigWolfe::Formulation::update_obj(const idol::Expr<idol::Var, ido
}

}

void idol::DantzigWolfe::Formulation::clean_up(unsigned int t_sub_problem_id, double t_ratio) {

auto& pool = m_pools[t_sub_problem_id];
auto& present_generators = m_present_generators[t_sub_problem_id];
const auto n_to_remove = (unsigned int) (pool.size() * (1 - t_ratio));
unsigned int n_removed = 0;

present_generators.clear();

for (auto it = pool.values().begin(), end = pool.values().end() ; it != end ; ) {

const bool is_already_in_master = m_master.has(it->first);
const bool done_removing = n_removed >= n_to_remove;

if (done_removing) {

if (is_already_in_master) {
present_generators.emplace_back(it->first, it->second);
}

++it;
continue;

}

if (is_already_in_master) {

if (m_master.get_var_primal(it->first) > 0) {

present_generators.emplace_back(it->first, it->second);
++it;
continue;

}

m_master.remove(it->first);

}

it = pool.erase(it);
++n_removed;

}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Created by henri on 31.10.23.
//
#include "idol/optimizers/dantzig-wolfe/DantzigWolfeSubProblem.h"
#include "idol/optimizers/dantzig-wolfe/SubProblem.h"

idol::DantzigWolfe::SubProblem &idol::DantzigWolfe::SubProblem::with_multiplicities(double t_lower, double t_upper) {

Expand Down Expand Up @@ -73,3 +73,33 @@ double idol::DantzigWolfe::SubProblem::lower_multiplicity() const {
double idol::DantzigWolfe::SubProblem::upper_multiplicity() const {
return m_upper_multiplicity.has_value() ? m_upper_multiplicity.value() : 1.;
}

idol::DantzigWolfe::SubProblem &
idol::DantzigWolfe::SubProblem::with_column_pool_clean_up(unsigned int t_threshold, double t_ratio) {

if (m_column_pool_clean_up_parameters.has_value()) {
throw Exception("Column pool clean up has already been configured.");
}

m_column_pool_clean_up_parameters = { t_threshold, t_ratio };

return *this;
}

unsigned int idol::DantzigWolfe::SubProblem::column_pool_clean_up_threshold() const {

if (!m_column_pool_clean_up_parameters.has_value()) {
return std::numeric_limits<unsigned int>::max();
}

return m_column_pool_clean_up_parameters.value().first;
}

double idol::DantzigWolfe::SubProblem::column_pool_clean_up_ratio() const {

if (!m_column_pool_clean_up_parameters.has_value()) {
return .66;
}

return m_column_pool_clean_up_parameters.value().second;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Created by henri on 31.10.23.
//
#include "idol/optimizers/dantzig-wolfe/infeasibility-strategies/FarkasPricing.h"
#include "idol/optimizers/dantzig-wolfe/column-generation/ColumnGeneration.h"
#include "idol/optimizers/dantzig-wolfe/ColumnGeneration.h"

void idol::DantzigWolfe::FarkasPricing::Strategy::execute(Optimizers::DantzigWolfeDecomposition &t_parent) {

Expand Down

0 comments on commit fad0587

Please sign in to comment.