Skip to content

Commit

Permalink
take out unused fields from Dynamic and know CbcModel is minimize - a…
Browse files Browse the repository at this point in the history
…ll for a small increase in speed
  • Loading branch information
jjhforrest committed Nov 9, 2023
1 parent 71fb020 commit dfe3e3b
Show file tree
Hide file tree
Showing 14 changed files with 461 additions and 139 deletions.
15 changes: 10 additions & 5 deletions src/CbcBranchDynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void CbcBranchDynamicDecision::updateInformation(OsiSolverInterface *solver,
const CbcModel *model = object_->model();
double originalValue = node->objectiveValue();
int originalUnsatisfied = node->numberUnsatisfied();
double objectiveValue = solver->getObjValue() * model->getObjSense();
double objectiveValue = solver->getObjValue() * model->getObjSenseInCbc();
int unsatisfied = 0;
int i;
int numberIntegers = model->numberIntegers();
Expand Down Expand Up @@ -758,12 +758,17 @@ int CbcDynamicPseudoCostBranchingObject::fillStrongInfo(CbcStrongInfo &info)
info.finishedDown = false;
info.numItersDown = 0;
info.fix = 0;
if (object_->numberTimesUp() < object_->numberBeforeTrust() + 2 * object_->numberTimesUpInfeasible() || object_->numberTimesDown() < object_->numberBeforeTrust() + 2 * object_->numberTimesDownInfeasible()) {
#define FL_MULTIPLIER -2.0
if (object_->numberTimesUp() < object_->numberBeforeTrust() + fabs(FL_MULTIPLIER) * object_->numberTimesUpInfeasible() || object_->numberTimesDown() < object_->numberBeforeTrust() + fabs(FL_MULTIPLIER) * object_->numberTimesDownInfeasible()) {
return 0;
} else {
#if CBC_DYNAMIC_EXPERIMENT > 0
if (object_->numberBeforeTrust()>1) {
if (FL_MULTIPLIER<0.0) {
return 0;
}
}
#endif
return 1;
}
}

/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
*/
20 changes: 10 additions & 10 deletions src/CbcHeuristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ bool CbcHeuristic::exitNow(double bestObjective) const
}
// See if can stop on gap
OsiSolverInterface *solver = model_->solver();
double bestPossibleObjective = solver->getObjValue() * solver->getObjSense();
double bestPossibleObjective = solver->getObjValue() * solver->getObjSenseInCbc();
double absGap = CoinMax(model_->getAllowableGap(),
model_->getHeuristicGap());
double fracGap = CoinMax(model_->getAllowableFractionGap(),
Expand Down Expand Up @@ -915,7 +915,7 @@ int CbcHeuristic::smallBranchAndBound(OsiSolverInterface *solver, int numberNode
solver->getHintParam(OsiDoReducePrint, takeHint, strength);
solver->setHintParam(OsiDoReducePrint, true, OsiHintTry);
solver->setHintParam(OsiDoPresolveInInitial, false, OsiHintTry);
double signedCutoff = cutoff * solver->getObjSense();
double signedCutoff = cutoff * solver->getObjSenseInCbc();
solver->setDblParam(OsiDualObjectiveLimit, signedCutoff);
solver->initialSolve();
if (solver->isProvenOptimal()) {
Expand Down Expand Up @@ -1297,7 +1297,7 @@ int CbcHeuristic::smallBranchAndBound(OsiSolverInterface *solver, int numberNode
4 and static continuous, 5 as 3 but no internal integers
6 as 3 but all slack basis!
*/
double value = solver2->getObjSense() * solver2->getObjValue();
double value = solver2->getObjSenseInCbc() * solver2->getObjValue();
int w = pumpTune / 10;
int ix = w % 10;
w /= 10;
Expand Down Expand Up @@ -1423,17 +1423,17 @@ int CbcHeuristic::smallBranchAndBound(OsiSolverInterface *solver, int numberNode
if (solver3->isProvenOptimal()) {
// good
CbcSerendipity heuristic(model);
double value = solver3->getObjSense() * solver3->getObjValue();
double value = solver3->getObjSenseInCbc() * solver3->getObjValue();
heuristic.setInputSolution(solver3->getColSolution(), value);
value = value + 1.0e-7 * (1.0 + fabs(value));
value *= solver3->getObjSense();
value *= solver3->getObjSenseInCbc();
model.setCutoff(value);
model.addHeuristic(&heuristic, "Previous solution", 0);
//printf("added seren\n");
} else {
double value = model_->getMinimizationObjValue();
value = value + 1.0e-7 * (1.0 + fabs(value));
value *= solver3->getObjSense();
value *= solver3->getObjSenseInCbc();
model.setCutoff(value);
sprintf(generalPrint, "Unable to insert previous solution - using cutoff of %g",
trueObjValue(value));
Expand Down Expand Up @@ -1541,7 +1541,7 @@ int CbcHeuristic::smallBranchAndBound(OsiSolverInterface *solver, int numberNode
}
} else {
// empty model
model.setMinimizationObjValue(model.solver()->getObjSense() * model.solver()->getObjValue());
model.setMinimizationObjValue(model.solver()->getObjSenseInCbc() * model.solver()->getObjValue());
}
if (logLevel > 1)
model_->messageHandler()->message(CBC_END_SUB, model_->messages())
Expand All @@ -1565,7 +1565,7 @@ int CbcHeuristic::smallBranchAndBound(OsiSolverInterface *solver, int numberNode
setPreProcessingMode(model.solver(),2);
process.postProcess(*model.solver());
setPreProcessingMode(solver,0);
if (solver->isProvenOptimal() && solver->getObjValue() * solver->getObjSense() < cutoff) {
if (solver->isProvenOptimal() && solver->getObjValue() * solver->getObjSenseInCbc() < cutoff) {
// Solution now back in solver
int numberColumns = solver->getNumCols();
memcpy(newSolution, solver->getColSolution(),
Expand Down Expand Up @@ -2111,7 +2111,7 @@ int CbcRounding::solution(double &solutionValue,
heuristicName(), numRuns_, numCouldRun_, when_);
#endif
OsiSolverInterface *solver = model_->solver();
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double newSolutionValue = direction * solver->getObjValue();
return solution(solutionValue, betterSolution, newSolutionValue);
}
Expand Down Expand Up @@ -2149,7 +2149,7 @@ int CbcRounding::solution(double &solutionValue,
int numberIntegers = model_->numberIntegers();
const int *integerVariable = model_->integerVariable();
int i;
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
//double newSolutionValue = direction*solver->getObjValue();
int returnCode = 0;
// Column copy
Expand Down
10 changes: 5 additions & 5 deletions src/CbcHeuristicDive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ int CbcHeuristicDive::solution(double &solutionValue, int &numberNodes,
assert(numberRows <= solver->getNumRows());
int numberIntegers = model_->numberIntegers();
const int *integerVariable = model_->integerVariable();
double direction = solver->getObjSense(); // 1 for min, -1 for max
double direction = solver->getObjSenseInCbc(); // 1 for min, -1 for max
double newSolutionValue = direction * solver->getObjValue();
int returnCode = 0;
// Column copy
Expand Down Expand Up @@ -609,7 +609,7 @@ int CbcHeuristicDive::solution(double &solutionValue, int &numberNodes,
#ifdef GAP
double cutoff = model_->getCutoff();
if (cutoff < 1.0e20 && false) {
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
gap = cutoff - solver->getObjValue() * direction;
gap *= 0.1; // Fix more if plausible
double tolerance;
Expand Down Expand Up @@ -1418,7 +1418,7 @@ int CbcHeuristicDive::reducedCostFix(OsiSolverInterface *solver)
#ifdef DIVE_DEBUG
std::cout << "cutoff = " << cutoff << std::endl;
#endif
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double gap = cutoff - solver->getObjValue() * direction;
gap *= 0.5; // Fix more
double tolerance;
Expand Down Expand Up @@ -1508,13 +1508,13 @@ int CbcHeuristicDive::fixOtherVariables(OsiSolverInterface *solver,
// fix other integer variables that are at their bounds
int cnt = 0;
#ifdef GAP
double direction = solver->getObjSense(); // 1 for min, -1 for max
double direction = solver->getObjSenseInCbc(); // 1 for min, -1 for max
double gap = 1.0e30;
#endif
#ifdef GAP
double cutoff = model_->getCutoff();
if (cutoff < 1.0e20 && false) {
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
gap = cutoff - solver->getObjValue() * direction;
gap *= 0.1; // Fix more if plausible
double tolerance;
Expand Down
16 changes: 8 additions & 8 deletions src/CbcHeuristicFPump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
model_->solver()->getDblParam(OsiDualObjectiveLimit, cutoff);
double realCutoff = cutoff;
bool secondMajorPass = false;
double direction = model_->solver()->getObjSense();
double direction = model_->solver()->getObjSenseInCbc();
cutoff *= direction;
int numberBandBsolutions = 0;
double firstCutoff = fabs(cutoff);
Expand Down Expand Up @@ -432,7 +432,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
numRuns_++;
if (cutoff < 1.0e50 && false) {
// Fix on djs
double direction = model_->solver()->getObjSense();
double direction = model_->solver()->getObjSenseInCbc();
double gap = cutoff - model_->solver()->getObjValue() * direction;
double tolerance;
model_->solver()->getDblParam(OsiDualTolerance, tolerance);
Expand All @@ -452,7 +452,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
saveBasis = *basis;
delete basis;
}
double continuousObjectiveValue = model_->solver()->getObjValue() * model_->solver()->getObjSense();
double continuousObjectiveValue = model_->solver()->getObjValue() * model_->solver()->getObjSenseInCbc();
double *firstPerturbedObjective = NULL;
double *firstPerturbedSolution = NULL;
double firstPerturbedValue = COIN_DBL_MAX;
Expand Down Expand Up @@ -584,7 +584,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
#endif
if (CoinMin(fakeCutoff_, cutoff) < 1.0e50) {
// Fix on djs
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double gap = CoinMin(fakeCutoff_, cutoff) - solver->getObjValue() * direction;
double tolerance;
solver->getDblParam(OsiDualTolerance, tolerance);
Expand Down Expand Up @@ -712,7 +712,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
}
}
bool finished = false;
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
int returnCode = 0;
bool takeHint;
OsiHintStrength strength;
Expand Down Expand Up @@ -1241,7 +1241,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,

// 2. update the objective function based on the new rounded solution
double offset = 0.0;
double costValue = (1.0 - scaleFactor) * solver->getObjSense();
double costValue = (1.0 - scaleFactor) * solver->getObjSenseInCbc();
int numberChanged = 0;
const double *oldObjective = solver->getObjCoefficients();
bool fixOnesAtBound = false;
Expand Down Expand Up @@ -2261,7 +2261,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
#endif
newSolver->initialSolve();
if (newSolver->isProvenOptimal()) {
double value = newSolver->getObjValue() * newSolver->getObjSense();
double value = newSolver->getObjValue() * newSolver->getObjSenseInCbc();
if (value < newSolutionValue) {
//newSolver->writeMpsNative("query.mps", NULL, NULL, 2);
#ifdef JJF_ZERO
Expand Down Expand Up @@ -2327,7 +2327,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue,
}
newSolver->initialSolve();
if (newSolver->isProvenOptimal()) {
double value = newSolver->getObjValue() * newSolver->getObjSense();
double value = newSolver->getObjValue() * newSolver->getObjSenseInCbc();
if (value < saveValue) {
sprintf(pumpPrint, "Freeing continuous variables gives a solution of %g", trueObjValue(value));
model_->messageHandler()->message(CBC_FPUMP1, model_->messages())
Expand Down
10 changes: 5 additions & 5 deletions src/CbcHeuristicGreedy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int CbcHeuristicGreedyCover::solution(double &solutionValue,
numRuns_++;
assert(numberRows == matrix_.getNumRows());
int iRow, iColumn;
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double offset;
solver->getDblParam(OsiObjOffset, offset);
double newSolutionValue = -offset;
Expand Down Expand Up @@ -388,7 +388,7 @@ void CbcHeuristicGreedyCover::validate()
const double *columnLower = solver->getColLower();
const double *rowUpper = solver->getRowUpper();
const double *objective = solver->getObjCoefficients();
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();

int numberRows = solver->getNumRows();
int numberColumns = solver->getNumCols();
Expand Down Expand Up @@ -552,7 +552,7 @@ int CbcHeuristicGreedyEquality::solution(double &solutionValue,

assert(numberRows == matrix_.getNumRows());
int iRow, iColumn;
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double offset;
solver->getDblParam(OsiObjOffset, offset);
double newSolutionValue = -offset;
Expand Down Expand Up @@ -815,7 +815,7 @@ void CbcHeuristicGreedyEquality::validate()
const double *rowUpper = solver->getRowUpper();
const double *rowLower = solver->getRowLower();
const double *objective = solver->getObjCoefficients();
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();

int numberRows = solver->getNumRows();
int numberColumns = solver->getNumCols();
Expand Down Expand Up @@ -1059,7 +1059,7 @@ int CbcHeuristicGreedySOS::solution(double &solutionValue,
int *firstGub = new int[numberRows];
int *nextGub = new int[numberColumns];
int iRow, iColumn;
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double *slackCost = new double[numberRows];
double *modifiedCost = CoinCopyOfArray(objective, numberColumns);
for (int iRow = 0; iRow < numberRows; iRow++) {
Expand Down
8 changes: 4 additions & 4 deletions src/CbcHeuristicLocal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ int CbcHeuristicLocal::solutionFix(double &objectiveValue,
int nAtLb = 0;
//double sumDj=0.0;
const double *dj = newSolver->getReducedCost();
double direction = newSolver->getObjSense();
double direction = newSolver->getObjSenseInCbc();
for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
if (!isHeuristicInteger(newSolver, iColumn)) {
if (!used_[iColumn]) {
Expand Down Expand Up @@ -414,7 +414,7 @@ int CbcHeuristicLocal::solution(double &solutionValue,
const int *integerVariable = model_->integerVariable();

int i;
double direction = solver->getObjSense();
double direction = solver->getObjSenseInCbc();
double newSolutionValue = model_->getObjValue() * direction;
int returnCode = 0;
numRuns_++;
Expand Down Expand Up @@ -1333,7 +1333,7 @@ int CbcHeuristicNaive::solution(double &solutionValue,
numRuns_++;
double cutoff;
model_->solver()->getDblParam(OsiDualObjectiveLimit, cutoff);
double direction = model_->solver()->getObjSense();
double direction = model_->solver()->getObjSenseInCbc();
cutoff *= direction;
cutoff = CoinMin(cutoff, solutionValue);
OsiSolverInterface *solver = model_->continuousSolver();
Expand Down Expand Up @@ -1620,7 +1620,7 @@ int CbcHeuristicCrossover::solution(double &solutionValue,
numRuns_++;
double cutoff;
model_->solver()->getDblParam(OsiDualObjectiveLimit, cutoff);
double direction = model_->solver()->getObjSense();
double direction = model_->solver()->getObjSenseInCbc();
cutoff *= direction;
cutoff = CoinMin(cutoff, solutionValue);
OsiSolverInterface *solver = cloneBut(2);
Expand Down
4 changes: 2 additions & 2 deletions src/CbcHeuristicRENS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ int CbcHeuristicRENS::solution(double &solutionValue,
int type = rensType_ & 15;
if (type < 12)
newSolver->resolve();
double direction = newSolver->getObjSense();
double direction = newSolver->getObjSenseInCbc();
double cutoff = model_->getCutoff();
newSolver->setDblParam(OsiDualObjectiveLimit, 1.0e100);
//cutoff *= direction;
Expand Down Expand Up @@ -910,7 +910,7 @@ int CbcHeuristicRENS::solution(double &solutionValue,
int nAtLb = 0;
double sumDj = 0.0;
const double *dj = newSolver->getReducedCost();
double direction = newSolver->getObjSense();
double direction = newSolver->getObjSenseInCbc();
for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
if (!newSolver->isInteger(iColumn)) {
double value = currentSolution[iColumn];
Expand Down
Loading

0 comments on commit dfe3e3b

Please sign in to comment.