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

Replace Coin{Max,Min} by std::{max,min} #196

Merged
merged 1 commit into from
Aug 13, 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
8 changes: 4 additions & 4 deletions examples/opbdp_solve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static int solve(const OsiSolverInterface * model,PBCS & pbcs, OrdInt & sol)
// objective not too important
double maximumObjElement = 0.0 ;
for (i = 0 ; i < numberColumns ; i++)
maximumObjElement = CoinMax(maximumObjElement,fabs(objective[i])) ;
maximumObjElement = std::max(maximumObjElement,fabs(objective[i])) ;
int objGood = 0 ;
double objMultiplier = 2520.0 ;
bool good=true;
Expand Down Expand Up @@ -162,11 +162,11 @@ static int solve(const OsiSolverInterface * model,PBCS & pbcs, OrdInt & sol)
// now real stuff
for (i=0;i<numberRows;i++) {
if (rowLower[i]!=-infinity)
maximumElement = CoinMax(maximumElement,fabs(rowLower[i])) ;
maximumElement = std::max(maximumElement,fabs(rowLower[i])) ;
if (rowUpper[i]!=infinity)
maximumElement = CoinMax(maximumElement,fabs(rowUpper[i])) ;
maximumElement = std::max(maximumElement,fabs(rowUpper[i])) ;
for (CoinBigIndex j=rowStart[i];j<rowStart[i]+rowLength[i];j++)
maximumElement = CoinMax(maximumElement,fabs(elementByRow[j])) ;
maximumElement = std::max(maximumElement,fabs(elementByRow[j])) ;
}
assert (maximumElement);
int elGood = 0 ;
Expand Down
6 changes: 3 additions & 3 deletions src/Osi/OsiAuxInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int OsiBabSolver::solution(double &solutionValue,
// this,bestSolution_,bestObjectiveValue_);
if (bestObjectiveValue_ < solutionValue && bestSolution_) {
// new solution
memcpy(betterSolution, bestSolution_, CoinMin(numberColumns, sizeSolution_) * sizeof(double));
memcpy(betterSolution, bestSolution_, std::min(numberColumns, sizeSolution_) * sizeof(double));
if (sizeSolution_ < numberColumns)
CoinZeroN(betterSolution + sizeSolution_, numberColumns - sizeSolution_);
solutionValue = bestObjectiveValue_;
Expand Down Expand Up @@ -156,10 +156,10 @@ void OsiBabSolver::setSolution(const double *solution, int numberColumns, double
assert(solver_);
// just in case size has changed
delete[] bestSolution_;
sizeSolution_ = CoinMin(solver_->getNumCols(), numberColumns);
sizeSolution_ = std::min(solver_->getNumCols(), numberColumns);
bestSolution_ = new double[sizeSolution_];
CoinZeroN(bestSolution_, sizeSolution_);
CoinMemcpyN(solution, CoinMin(sizeSolution_, numberColumns), bestSolution_);
CoinMemcpyN(solution, std::min(sizeSolution_, numberColumns), bestSolution_);
bestObjectiveValue_ = objectiveValue * solver_->getObjSense();
}
// Get objective (well mip bound)
Expand Down
72 changes: 36 additions & 36 deletions src/Osi/OsiBranchingObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ double
OsiSimpleInteger::infeasibility(const OsiBranchingInformation *info, int &whichWay) const
{
double value = info->solution_[columnNumber_];
value = CoinMax(value, info->lower_[columnNumber_]);
value = CoinMin(value, info->upper_[columnNumber_]);
value = std::max(value, info->lower_[columnNumber_]);
value = std::min(value, info->upper_[columnNumber_]);
double nearest = floor(value + (1.0 - 0.5));
if (nearest > value) {
whichWay = 1;
Expand Down Expand Up @@ -558,21 +558,21 @@ OsiSimpleInteger::infeasibility(const OsiBranchingInformation *info, int &whichW
// if up makes infeasible then make at least default
double newUp = activity[iRow] + upMovement * el2;
if (newUp > upper[iRow] + tolerance || newUp < lower[iRow] - tolerance)
u = CoinMax(u, info->defaultDual_);
u = std::max(u, info->defaultDual_);
upEstimate += u * upMovement;
// if down makes infeasible then make at least default
double newDown = activity[iRow] - downMovement * el2;
if (newDown > upper[iRow] + tolerance || newDown < lower[iRow] - tolerance)
d = CoinMax(d, info->defaultDual_);
d = std::max(d, info->defaultDual_);
downEstimate += d * downMovement;
}
if (downEstimate >= upEstimate) {
infeasibility_ = CoinMax(1.0e-12, upEstimate);
otherInfeasibility_ = CoinMax(1.0e-12, downEstimate);
infeasibility_ = std::max(1.0e-12, upEstimate);
otherInfeasibility_ = std::max(1.0e-12, downEstimate);
whichWay = 1;
} else {
infeasibility_ = CoinMax(1.0e-12, downEstimate);
otherInfeasibility_ = CoinMax(1.0e-12, upEstimate);
infeasibility_ = std::max(1.0e-12, downEstimate);
otherInfeasibility_ = std::max(1.0e-12, upEstimate);
whichWay = 0;
}
returnValue = infeasibility_;
Expand All @@ -593,8 +593,8 @@ OsiSimpleInteger::feasibleRegion(OsiSolverInterface *solver,
const OsiBranchingInformation *info) const
{
double value = info->solution_[columnNumber_];
double newValue = CoinMax(value, info->lower_[columnNumber_]);
newValue = CoinMin(newValue, info->upper_[columnNumber_]);
double newValue = std::max(value, info->lower_[columnNumber_]);
newValue = std::min(newValue, info->upper_[columnNumber_]);
newValue = floor(newValue + 0.5);
solver->setColLower(columnNumber_, newValue);
solver->setColUpper(columnNumber_, newValue);
Expand All @@ -613,8 +613,8 @@ OsiBranchingObject *
OsiSimpleInteger::createBranch(OsiSolverInterface *solver, const OsiBranchingInformation *info, int way) const
{
double value = info->solution_[columnNumber_];
value = CoinMax(value, info->lower_[columnNumber_]);
value = CoinMin(value, info->upper_[columnNumber_]);
value = std::max(value, info->lower_[columnNumber_]);
value = std::min(value, info->upper_[columnNumber_]);
assert(info->upper_[columnNumber_] > info->lower_[columnNumber_]);
#ifndef NDEBUG
double nearest = floor(value + 0.5);
Expand Down Expand Up @@ -853,7 +853,7 @@ OsiSOS::OsiSOS(const OsiSolverInterface *, int numberMembers,
double last = -COIN_DBL_MAX;
int i;
for (i = 0; i < numberMembers_; i++) {
double possible = CoinMax(last + 1.0e-10, weights_[i]);
double possible = std::max(last + 1.0e-10, weights_[i]);
weights_[i] = possible;
last = possible;
}
Expand Down Expand Up @@ -946,7 +946,7 @@ OsiSOS::infeasibility(const OsiBranchingInformation *info, int &whichWay) const
throw CoinError("Weights too close together in SOS", "infeasibility", "OsiSOS");
lastWeight = weights_[j];
if (upper[iColumn]) {
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
if (value > integerTolerance) {
// Possibly due to scaling a fixed variable might slip through
#ifdef COIN_DEVELOP
Expand Down Expand Up @@ -1111,7 +1111,7 @@ OsiSOS::infeasibility(const OsiBranchingInformation *info, int &whichWay) const
// if makes infeasible then make at least default
double newValue = activity[iRow] + movement;
if (newValue > upper[iRow] + primalTolerance || newValue < lower[iRow] - primalTolerance)
thisEstimate = CoinMax(thisEstimate, info->defaultDual_);
thisEstimate = std::max(thisEstimate, info->defaultDual_);
estimate += thisEstimate;
}
for (j = 0; j < n2; j++) {
Expand All @@ -1131,7 +1131,7 @@ OsiSOS::infeasibility(const OsiBranchingInformation *info, int &whichWay) const
// if makes infeasible then make at least default
double newValue = activity[iRow] + movement;
if (newValue > upper[iRow] + primalTolerance || newValue < lower[iRow] - primalTolerance)
thisEstimate = CoinMax(thisEstimate, info->defaultDual_);
thisEstimate = std::max(thisEstimate, info->defaultDual_);
estimate += thisEstimate;
}
}
Expand All @@ -1141,12 +1141,12 @@ OsiSOS::infeasibility(const OsiBranchingInformation *info, int &whichWay) const
double downEstimate = fakeSolution[0];
double upEstimate = fakeSolution[1];
if (downEstimate >= upEstimate) {
infeasibility_ = CoinMax(1.0e-12, upEstimate);
otherInfeasibility_ = CoinMax(1.0e-12, downEstimate);
infeasibility_ = std::max(1.0e-12, upEstimate);
otherInfeasibility_ = std::max(1.0e-12, downEstimate);
whichWay = 1;
} else {
infeasibility_ = CoinMax(1.0e-12, downEstimate);
otherInfeasibility_ = CoinMax(1.0e-12, upEstimate);
infeasibility_ = std::max(1.0e-12, downEstimate);
otherInfeasibility_ = std::max(1.0e-12, upEstimate);
whichWay = 0;
}
whichWay_ = static_cast< short >(whichWay);
Expand Down Expand Up @@ -1176,7 +1176,7 @@ OsiSOS::feasibleRegion(OsiSolverInterface *solver, const OsiBranchingInformation
if (sosType_ == 1) {
for (j = 0; j < numberMembers_; j++) {
int iColumn = members_[j];
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
if (value > sum && upper[iColumn]) {
firstNonZero = j;
sum = value;
Expand All @@ -1188,8 +1188,8 @@ OsiSOS::feasibleRegion(OsiSolverInterface *solver, const OsiBranchingInformation
for (j = 1; j < numberMembers_; j++) {
int iColumn = members_[j];
int jColumn = members_[j - 1];
double value1 = CoinMax(0.0, solution[iColumn]);
double value0 = CoinMax(0.0, solution[jColumn]);
double value1 = std::max(0.0, solution[iColumn]);
double value0 = std::max(0.0, solution[jColumn]);
double value = value0 + value1;
if (value > sum) {
if (upper[iColumn] || upper[jColumn]) {
Expand All @@ -1203,7 +1203,7 @@ OsiSOS::feasibleRegion(OsiSolverInterface *solver, const OsiBranchingInformation
for (j = 0; j < numberMembers_; j++) {
if (j < firstNonZero || j > lastNonZero) {
int iColumn = members_[j];
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
movement += value;
solver->setColUpper(iColumn, 0.0);
}
Expand Down Expand Up @@ -1267,7 +1267,7 @@ OsiSOS::createBranch(OsiSolverInterface *solver, const OsiBranchingInformation *
for (j = 0; j < numberMembers_; j++) {
int iColumn = members_[j];
if (upper[iColumn]) {
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
sum += value;
if (firstNonFixed < 0)
firstNonFixed = j;
Expand Down Expand Up @@ -1396,8 +1396,8 @@ void OsiSOSBranchingObject::print(const OsiSolverInterface *solver)
for (i = 0; i < numberMembers; i++) {
double bound = upper[which[i]];
if (bound) {
first = CoinMin(first, i);
last = CoinMax(last, i);
first = std::min(first, i);
last = std::max(last, i);
}
}
// *** for way - up means fix all those in down section
Expand Down Expand Up @@ -1486,7 +1486,7 @@ OsiLotsize::OsiLotsize(const OsiSolverInterface *,
// and for safety
bound_[numberRanges_] = bound_[numberRanges_ - 1];
for (i = 1; i < numberRanges_; i++) {
largestGap_ = CoinMax(largestGap_, bound_[i] - bound_[i - 1]);
largestGap_ = std::max(largestGap_, bound_[i] - bound_[i - 1]);
}
} else {
bound_ = new double[2 * numberPoints + 2];
Expand All @@ -1505,15 +1505,15 @@ OsiLotsize::OsiLotsize(const OsiSolverInterface *,
hi = thisHi;
} else {
//overlap
hi = CoinMax(hi, thisHi);
hi = std::max(hi, thisHi);
bound_[2 * numberRanges_ - 1] = hi;
}
}
// and for safety
bound_[2 * numberRanges_] = bound_[2 * numberRanges_ - 2];
bound_[2 * numberRanges_ + 1] = bound_[2 * numberRanges_ - 1];
for (i = 1; i < numberRanges_; i++) {
largestGap_ = CoinMax(largestGap_, bound_[2 * i] - bound_[2 * i - 1]);
largestGap_ = std::max(largestGap_, bound_[2 * i] - bound_[2 * i - 1]);
}
}
delete[] sort;
Expand Down Expand Up @@ -1719,8 +1719,8 @@ OsiLotsize::infeasibility(const OsiBranchingInformation *info, int &preferredWay
const double *lower = info->lower_;
const double *upper = info->upper_;
double value = solution[columnNumber_];
value = CoinMax(value, lower[columnNumber_]);
value = CoinMin(value, upper[columnNumber_]);
value = std::max(value, lower[columnNumber_]);
value = std::min(value, upper[columnNumber_]);
double integerTolerance = info->integerTolerance_;
/*printf("%d %g %g %g %g\n",columnNumber_,value,lower[columnNumber_],
solution[columnNumber_],upper[columnNumber_]);*/
Expand Down Expand Up @@ -1783,8 +1783,8 @@ OsiLotsize::feasibleRegion(OsiSolverInterface *solver, const OsiBranchingInforma
const double *upper = solver->getColUpper();
const double *solution = info->solution_;
double value = solution[columnNumber_];
value = CoinMax(value, lower[columnNumber_]);
value = CoinMin(value, upper[columnNumber_]);
value = std::max(value, lower[columnNumber_]);
value = std::min(value, upper[columnNumber_]);
findRange(value, info->integerTolerance_);
double nearest;
if (rangeType_ == 1) {
Expand Down Expand Up @@ -1819,8 +1819,8 @@ OsiLotsize::createBranch(OsiSolverInterface *solver, const OsiBranchingInformati
const double *lower = solver->getColLower();
const double *upper = solver->getColUpper();
double value = solution[columnNumber_];
value = CoinMax(value, lower[columnNumber_]);
value = CoinMin(value, upper[columnNumber_]);
value = std::max(value, lower[columnNumber_]);
value = std::min(value, upper[columnNumber_]);
assert(!findRange(value, info->integerTolerance_));
return new OsiLotsizeBranchingObject(solver, this, way,
value);
Expand Down
2 changes: 1 addition & 1 deletion src/Osi/OsiBranchingObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class OSILIB_EXPORT OsiBranchingInformation {
const int *columnLength_;
/// Row indices
const int *row_;
/** Useful region of length CoinMax(numberColumns,2*numberRows)
/** Useful region of length std::max(numberColumns,2*numberRows)
This is allocated and deleted before OsiObject::infeasibility
It is zeroed on entry and should be so on exit
It only exists if defaultDual_>=0.0
Expand Down
26 changes: 13 additions & 13 deletions src/Osi/OsiChooseVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int OsiChooseVariable::setupList(OsiBranchingInformation *info, bool initialize)
int checkIndex = 0;
int bestPriority = COIN_INT_MAX;
// pretend one strong even if none
int maximumStrong = numberStrong_ ? CoinMin(numberStrong_, numberObjects) : 1;
int maximumStrong = numberStrong_ ? std::min(numberStrong_, numberObjects) : 1;
int putOther = numberObjects;
int i;
for (i = 0; i < maximumStrong; i++) {
Expand Down Expand Up @@ -683,7 +683,7 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
double check = -COIN_DBL_MAX;
int checkIndex = 0;
int bestPriority = COIN_INT_MAX;
int maximumStrong = CoinMin(numberStrong_, numberObjects);
int maximumStrong = std::min(numberStrong_, numberObjects);
int putOther = numberObjects;
int i;
for (i = 0; i < numberObjects; i++) {
Expand Down Expand Up @@ -711,7 +711,7 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
sumPi *= 0.01;
info->defaultDual_ = sumPi; // switch on
int numberColumns = solver_->getNumCols();
int size = CoinMax(numberColumns, 2 * numberRows);
int size = std::max(numberColumns, 2 * numberRows);
info->usefulRegion_ = new double[size];
CoinZeroN(info->usefulRegion_, size);
info->indexRegion_ = new int[size];
Expand Down Expand Up @@ -767,7 +767,7 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
list_[--putOther] = iObject;
}
}
maximumStrong = CoinMin(maximumStrong, putOther);
maximumStrong = std::min(maximumStrong, putOther);
bestPriority = priorityLevel;
check = -COIN_DBL_MAX;
checkIndex = 0;
Expand All @@ -790,7 +790,7 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
} else {
// use shadow prices always
}
value = MAXMIN_CRITERION * CoinMin(upEstimate, downEstimate) + (1.0 - MAXMIN_CRITERION) * CoinMax(upEstimate, downEstimate);
value = MAXMIN_CRITERION * std::min(upEstimate, downEstimate) + (1.0 - MAXMIN_CRITERION) * std::max(upEstimate, downEstimate);
if (value > check) {
//add to list
int iObject = list_[checkIndex];
Expand All @@ -803,7 +803,7 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
useful_[checkIndex] = value;
// find worst
check = COIN_DBL_MAX;
maximumStrong = CoinMin(maximumStrong, putOther);
maximumStrong = std::min(maximumStrong, putOther);
for (int j = 0; j < maximumStrong; j++) {
if (list_[j] >= 0) {
if (useful_[j] < check) {
Expand All @@ -820,14 +820,14 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
// to end
assert(list_[putOther - 1] < 0);
list_[--putOther] = i;
maximumStrong = CoinMin(maximumStrong, putOther);
maximumStrong = std::min(maximumStrong, putOther);
}
} else {
// worse priority
// to end
assert(list_[putOther - 1] < 0);
list_[--putOther] = i;
maximumStrong = CoinMin(maximumStrong, putOther);
maximumStrong = std::min(maximumStrong, putOther);
}
}
}
Expand All @@ -838,7 +838,7 @@ int OsiChooseStrong::setupList(OsiBranchingInformation *info, bool initialize)
// Get list
numberOnList_ = 0;
if (feasible) {
for (i = 0; i < CoinMin(maximumStrong, putOther); i++) {
for (i = 0; i < std::min(maximumStrong, putOther); i++) {
if (list_[i] >= 0) {
list_[numberOnList_] = list_[i];
useful_[numberOnList_++] = -useful_[i];
Expand Down Expand Up @@ -899,7 +899,7 @@ int OsiChooseStrong::chooseVariable(OsiSolverInterface *solver, OsiBranchingInfo
pseudoCosts_.setNumberBeforeTrusted(numberBeforeTrusted);
}

int numberLeft = CoinMin(numberStrong_ - numberStrongDone_, numberUnsatisfied_);
int numberLeft = std::min(numberStrong_ - numberStrongDone_, numberUnsatisfied_);
int numberToDo = 0;
resetResults(numberLeft);
int returnCode = 0;
Expand All @@ -917,7 +917,7 @@ int OsiChooseStrong::chooseVariable(OsiSolverInterface *solver, OsiBranchingInfo
const OsiObject *obj = solver->object(iObject);
double upEstimate = (upTotalChange[iObject] * obj->upEstimate()) / upNumber[iObject];
double downEstimate = (downTotalChange[iObject] * obj->downEstimate()) / downNumber[iObject];
double value = MAXMIN_CRITERION * CoinMin(upEstimate, downEstimate) + (1.0 - MAXMIN_CRITERION) * CoinMax(upEstimate, downEstimate);
double value = MAXMIN_CRITERION * std::min(upEstimate, downEstimate) + (1.0 - MAXMIN_CRITERION) * std::max(upEstimate, downEstimate);
if (value > bestTrusted) {
bestObjectIndex_ = iObject;
bestWhichWay_ = upEstimate > downEstimate ? 0 : 1;
Expand Down Expand Up @@ -980,7 +980,7 @@ int OsiChooseStrong::chooseVariable(OsiSolverInterface *solver, OsiBranchingInfo
delete branch;
}
}
double value = MAXMIN_CRITERION * CoinMin(upEstimate, downEstimate) + (1.0 - MAXMIN_CRITERION) * CoinMax(upEstimate, downEstimate);
double value = MAXMIN_CRITERION * std::min(upEstimate, downEstimate) + (1.0 - MAXMIN_CRITERION) * std::max(upEstimate, downEstimate);
if (value > bestTrusted) {
bestTrusted = value;
bestObjectIndex_ = iObject;
Expand Down Expand Up @@ -1186,7 +1186,7 @@ int OsiHotInfo::updateInformation(const OsiSolverInterface *solver, const OsiBra
status = 1; // infeasible
// Could do something different if we can't trust
double newObjectiveValue = solver->getObjSense() * solver->getObjValue();
changes_[iBranch] = CoinMax(0.0, newObjectiveValue - originalObjectiveValue_);
changes_[iBranch] = std::max(0.0, newObjectiveValue - originalObjectiveValue_);
// we might have got here by primal
if (choose->trustStrongForBound()) {
if (!status && newObjectiveValue >= info->cutoff_) {
Expand Down
Loading