Skip to content

Commit

Permalink
Merge pull request #8 from fontanf/bugfix/infeasible-master
Browse files Browse the repository at this point in the history
Fix when mater problem is infeasible
  • Loading branch information
fontanf authored Jul 20, 2024
2 parents 9c57300 + 997f8f4 commit 1414cd0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
14 changes: 14 additions & 0 deletions include/columngenerationsolver/commons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ class Solution
/** Return 'true' iff the solution is feasible. */
bool feasible() const { return feasible_; }

/**
* Return 'true' iff the solution is feasible for the constraints (but not
* necessarily for the variable integrality).
*/
bool feasible_relaxation() const { return feasible_relaxation_; }

/** Get the objective value of the solution. */
Value objective_value() const { return objective_value_; }

Expand Down Expand Up @@ -375,6 +381,12 @@ class Solution
/** Feasible. */
bool feasible_;

/**
* Feasible regarding the constraints but the regarding the column
* integrality.
*/
bool feasible_relaxation_;

/** Objective value. */
Value objective_value_;

Expand Down Expand Up @@ -441,6 +453,7 @@ class SolutionBuilder
}

solution_.feasible_ = true;
solution_.feasible_relaxation_ = true;
for (RowIdx row = 0;
row < (RowIdx)solution_.model_->rows.size();
++row) {
Expand All @@ -459,6 +472,7 @@ class SolutionBuilder
// << " ub " << solution_.model_->rows[row].upper_bound
// << std::endl;
solution_.feasible_ = false;
solution_.feasible_relaxation_ = false;
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/algorithms/column_generation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(
std::unordered_set<std::shared_ptr<const Column>,
const ColumnHasher&,
const ColumnHasher&> column_pool(0, column_hasher, column_hasher);
Value column_highest_objective_coefficient = 0;
// We first add to it the columns from the input column pool.
for (const auto& column: parameters.column_pool) {

Expand All @@ -116,6 +117,9 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(
if (!ok)
continue;

column_highest_objective_coefficient = (std::max)(
column_highest_objective_coefficient,
std::abs(column->objective_coefficient));
column_pool.insert(column);
}

Expand Down Expand Up @@ -590,6 +594,9 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(

// Store these new columns.
column_pool.insert(column);
column_highest_objective_coefficient = (std::max)(
column_highest_objective_coefficient,
std::abs(column->objective_coefficient));
output.columns.push_back(column);

// Only add the ones with negative reduced cost.
Expand Down Expand Up @@ -741,6 +748,18 @@ const ColumnGenerationOutput columngenerationsolver::column_generation(
output.relaxation_solution = solution_builder.build();
break;
}

// If the final solution contains some dummy columns, and the dummy
// column objective coefficient is significantly larger than the
// largest generated column objective coefficient, then we consider the
// problem infeasible.
if (column_highest_objective_coefficient > 0
&& std::abs(output.dummy_column_objective_coefficient)
> 100 * column_highest_objective_coefficient) {
output.relaxation_solution = solution_builder.build();
break;
}

// Otherwise, increase the dummy column objective coefficient and
// restart.
output.dummy_column_objective_coefficient *= 4;
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/greedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const GreedyOutput columngenerationsolver::greedy(
if (parameters.timer.needs_to_end())
break;

if (cg_output.relaxation_solution.columns().size() == 0)
if (!cg_output.relaxation_solution.feasible_relaxation())
break;

// Update bound.
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/limited_discrepancy_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const LimitedDiscrepancySearchOutput columngenerationsolver::limited_discrepancy
}
output.relaxation_solution = cg_output.relaxation_solution;
}
if (cg_output.relaxation_solution.columns().empty()) {
if (!cg_output.relaxation_solution.feasible_relaxation()) {
//std::cout << "no solution" << std::endl;
continue;
}
Expand Down

0 comments on commit 1414cd0

Please sign in to comment.