Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tabu columns in column generation #20

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions include/columngenerationsolver/algorithms/column_generation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "columngenerationsolver/linear_programming_solver.hpp"

#include <unordered_set>

namespace columngenerationsolver
{

Expand Down Expand Up @@ -85,6 +87,15 @@ struct ColumnGenerationParameters: Parameters
bool automatic_directional_smoothing = false;


/**
* Tabu columns.
*
* These columns are never added to the LP solver and therefore won't be
* part of the returned solution.
*/
std::unordered_set<std::shared_ptr<const Column>>* tabu = nullptr;


virtual int format_width() const override { return 41; }

virtual void format(std::ostream& os) const override
Expand Down
23 changes: 17 additions & 6 deletions src/algorithms/column_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(
!= infeasible_columns.end())
continue;

// Don't add a tabu column.
if (parameters.tabu != nullptr
&& parameters.tabu->find(column) != parameters.tabu->end())
continue;

std::vector<RowIdx> row_ids;
std::vector<Value> row_coefficients;
bool ok = true;
Expand Down Expand Up @@ -403,6 +408,11 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(
if (solver_generated_columns.find(column) != solver_generated_columns.end())
continue;

// Don't add a tabu column.
if (parameters.tabu != nullptr
&& parameters.tabu->find(column) != parameters.tabu->end())
continue;

// Add the column if its reduced cost is negative.
Value rc = compute_reduced_cost(*column, duals_out);
if (model.objective_sense == optimizationtools::ObjectiveDirection::Minimize
Expand Down Expand Up @@ -626,12 +636,12 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(
// Look for negative reduced cost columns.
for (const std::shared_ptr<const Column>& column: all_columns) {

// Discard columns which have already been generated.
// If they were worth adding to the LP, then they would
// have been added at the previous step (looking for
// column from the pool).
if (column_pool.find(column) != column_pool.end())
continue;
// Discard columns which have already been generated.
// If they were worth adding to the LP, then they would
// have been added at the previous step (looking for
// column from the pool).
if (column_pool.find(column) != column_pool.end())
continue;

// Store these new columns.
column_pool.insert(column);
Expand Down Expand Up @@ -738,6 +748,7 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(

// Add new columns to the linear program.
for (const std::shared_ptr<const Column>& column: new_columns) {

//std::cout << column << std::endl;
std::vector<RowIdx> ri;
std::vector<Value> rc;
Expand Down
5 changes: 3 additions & 2 deletions src/algorithms/limited_discrepancy_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "columngenerationsolver/algorithm_formatter.hpp"

#include <unordered_set>
#include <set>

using namespace columngenerationsolver;
Expand Down Expand Up @@ -143,7 +142,8 @@ const LimitedDiscrepancySearchOutput columngenerationsolver::limited_discrepancy
}

if (node->parent != nullptr
&& node->value <= node->value_frac) {
&& node->value <= node->value_frac
&& !node->tabu) {

node->relaxation_solution = node->parent->relaxation_solution;

Expand Down Expand Up @@ -192,6 +192,7 @@ const LimitedDiscrepancySearchOutput columngenerationsolver::limited_discrepancy
}
column_generation_parameters.column_pool = column_pool;
column_generation_parameters.fixed_columns = fixed_columns.columns();
column_generation_parameters.tabu = &tabu;

// Solve.
auto cg_output = column_generation(
Expand Down
Loading