Skip to content

Commit

Permalink
Work on cutoff for Highs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaslundell committed Jun 18, 2024
1 parent 55503af commit a2a9495
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/MIPSolver/MIPSolverGurobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ void MIPSolverGurobi::setCutOff(double cutOff)
{
gurobiModel->set(GRB_DoubleParam_Cutoff, cutOff + cutOffTol);
env->output->outputDebug(
fmt::format(" Setting cutoff value to {} for maximization.", cutOff + cutOffTol));
fmt::format(" Setting cutoff value to {} for minimization.", cutOff + cutOffTol));
}
else
{
Expand Down
31 changes: 23 additions & 8 deletions src/MIPSolver/MIPSolverHighs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ bool MIPSolverHighs::initializeProblem()
{
discreteVariablesActivated = true;

this->cutOff = 1e100;

aMatrixStart.push_back(0);

cachedSolutionHasChanged = true;
Expand Down Expand Up @@ -207,12 +205,12 @@ bool MIPSolverHighs::finalizeObjective(bool isMinimize, double constant)
{
if(!isMinimize)
{
objectiveSense = ObjSense::kMaximize;
this->objectiveSense = ObjSense::kMaximize;
isMinimizationProblem = false;
}
else
{
objectiveSense = ObjSense::kMinimize;
this->objectiveSense = ObjSense::kMinimize;
isMinimizationProblem = true;
}

Expand Down Expand Up @@ -578,10 +576,27 @@ void MIPSolverHighs::setTimeLimit(double seconds) { highsInstance.setOptionValue

void MIPSolverHighs::setCutOff(double cutOff)
{
// TODO: Some problems with maximization problems and cutoff, disabling for now
return;

if(cutOff == SHOT_DBL_MAX || cutOff == SHOT_DBL_MIN)
return;

highsInstance.setOptionValue("objective_bound", cutOff);
double cutOffTol = env->settings->getSetting<double>("MIP.CutOff.Tolerance", "Dual");
double cutOffWithTol = (isMinimizationProblem) ? cutOff + cutOffTol : cutOff - cutOffTol;

if(isMinimizationProblem)
{
highsInstance.setOptionValue("objective_bound", cutOffWithTol);

env->output->outputInfo(fmt::format(" Setting cutoff value to {} for minimization.", cutOffWithTol));
}
else
{
highsInstance.setOptionValue("objective_bound", cutOffWithTol);

env->output->outputInfo(fmt::format(" Setting cutoff value to {} for maximization.", cutOffWithTol));
}
}

void MIPSolverHighs::setCutOffAsConstraint(double cutOff)
Expand Down Expand Up @@ -614,8 +629,8 @@ void MIPSolverHighs::setCutOffAsConstraint(double cutOff)
}
else
{
highsInstance.addRow(-highsInstance.getInfinity(), -1.0 * (cutOff - this->objectiveConstant),
variableIndexes.size(), &variableIndexes[0], &coefficients[0]);
highsInstance.addRow(cutOff - this->objectiveConstant, highsInstance.getInfinity(), variableIndexes.size(),
&variableIndexes[0], &coefficients[0]);
env->output->outputDebug(
" Setting cutoff constraint value to " + Utilities::toString(cutOff) + " for maximization.");
}
Expand All @@ -637,7 +652,7 @@ void MIPSolverHighs::setCutOffAsConstraint(double cutOff)
else
{
highsInstance.changeRowBounds(
cutOffConstraintIndex, -highsInstance.getInfinity(), -(cutOff - this->objectiveConstant));
cutOffConstraintIndex, cutOff - this->objectiveConstant, highsInstance.getInfinity());
env->output->outputDebug(
" Setting cutoff constraint value to " + Utilities::toString(cutOff) + " for maximization.");
}
Expand Down
3 changes: 0 additions & 3 deletions src/MIPSolver/MIPSolverHighs.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ class MIPSolverHighs : public IMIPSolver, MIPSolverBase
HighsMipData highsCallbackData;

long int solutionLimit;
double timeLimit = 1e100;
double cutOff;
int numberOfThreads = 1;
double objectiveConstant = 0.0;

std::vector<std::pair<std::string, double>> MIPStart;
Expand Down

0 comments on commit a2a9495

Please sign in to comment.