Skip to content

Commit

Permalink
Solves adlittle with slack removed
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed Nov 8, 2024
1 parent d5ffacc commit b14bbe1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
23 changes: 10 additions & 13 deletions src/presolve/HPresolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4404,17 +4404,13 @@ HPresolve::Result HPresolve::removeSlacks(HighsPostsolveStack& postsolve_stack)
assert(coeff);
// Slack is s = (rhs - a^Tx)/coeff
//
if (coeff > 0) {
// Constraint bounds become [rhs - coeff * lower, rhs - coeff *
// upper]
model->col_lower_[iCol] = rhs - coeff * lower;
model->col_upper_[iCol] = rhs - coeff * upper;
} else {
// Constraint bounds become [rhs - coeff * upper, rhs - coeff *
// lower]
model->col_lower_[iCol] = rhs - coeff * upper;
model->col_upper_[iCol] = rhs - coeff * lower;
}
// Constraint bounds become:
//
// For coeff > 0 [rhs - coeff * upper, rhs - coeff * lower]
//
// For coeff < 0 [rhs - coeff * lower, rhs - coeff * upper]
model->row_lower_[iRow] = coeff > 0 ? rhs - coeff * upper : rhs - coeff * lower;
model->row_upper_[iRow] = coeff > 0 ? rhs - coeff * lower : rhs - coeff * upper;
if (cost) {
// Cost is (cost * rhs / coeff) + (col_cost - (cost/coeff) row_values)^Tx
double multiplier = cost / coeff;
Expand All @@ -4426,8 +4422,9 @@ HPresolve::Result HPresolve::removeSlacks(HighsPostsolveStack& postsolve_stack)
model->offset_ += multiplier * rhs;
}
//
postsolve_stack.slackColSubstitution(iRow, iCol, rhs, cost, lower, upper, coeff,
getColumnVector(iCol));
postsolve_stack.slackColSubstitution(iRow, iCol, rhs, cost, lower, upper, //coeff,
getRowVector(iRow),
getColumnVector(iCol));
markColDeleted(iCol);

unlink(coliter);
Expand Down
15 changes: 9 additions & 6 deletions src/presolve/HighsPostsolveStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,11 +1356,14 @@ void HighsPostsolveStack::SlackColSubstitution::undo(
const std::vector<Nonzero>& colValues, HighsSolution& solution,
HighsBasis& basis) {

assert(111==222);



// Taken from HighsPostsolveStack::FreeColSubstitution::undo(
//
// a (removed) cut may have been used in this reduction.
//
// May have to determine row dual and basis status unless doing
// primal-only transformation in MIP solver, in which case row may
// no longer exist if it corresponds to a removed cut, so have to
// avoid exceeding array bounds of solution.row_value
bool isModelRow = static_cast<size_t>(row) < solution.row_value.size();

// compute primal values
Expand All @@ -1375,9 +1378,9 @@ void HighsPostsolveStack::SlackColSubstitution::undo(

assert(colCoef != 0);
// Row values aren't fully postsolved, so why do this?
if (isModelRow)
solution.row_value[row] =
if (isModelRow) solution.row_value[row] =
double(rowValue + colCoef * solution.col_value[col]);
printf("HighsPostsolveStack::SlackColSubstitution::undo rowValue = %g\n", double(rowValue));
solution.col_value[col] = double((rhs - rowValue) / colCoef);

// if no dual values requested, return here
Expand Down
16 changes: 11 additions & 5 deletions src/presolve/HighsPostsolveStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class HighsPostsolveStack {
double colCost;
double colLower;
double colUpper;
double colCoeff;
// double colCoeff;
HighsInt row;
HighsInt col;

Expand Down Expand Up @@ -339,16 +339,22 @@ class HighsPostsolveStack {
reductionAdded(ReductionType::kFreeColSubstitution);
}

template <typename ColStorageFormat>
template <typename RowStorageFormat, typename ColStorageFormat>
void slackColSubstitution(HighsInt row, HighsInt col, double rhs,
double colCost, double colLower, double colUpper, double colCoeff,
double colCost, double colLower, double colUpper, //double colCoeff,
const HighsMatrixSlice<RowStorageFormat>& rowVec,
const HighsMatrixSlice<ColStorageFormat>& colVec) {
rowValues.clear();
for (const HighsSliceNonzero& rowVal : rowVec)
rowValues.emplace_back(origColIndex[rowVal.index()], rowVal.value());

colValues.clear();
for (const HighsSliceNonzero& colVal : colVec)
colValues.emplace_back(origRowIndex[colVal.index()], colVal.value());

reductionValues.push(SlackColSubstitution{rhs, colCost, colLower, colUpper, colCoeff, origRowIndex[row],
origColIndex[col]});
reductionValues.push(SlackColSubstitution{rhs, colCost, colLower, colUpper, //colCoeff,
origRowIndex[row],
origColIndex[col]});
reductionValues.push(rowValues);
reductionValues.push(colValues);
reductionAdded(ReductionType::kSlackColSubstitution);
Expand Down

0 comments on commit b14bbe1

Please sign in to comment.