Skip to content

Commit

Permalink
Replace Coin{Max,Min} by std::{max,min}
Browse files Browse the repository at this point in the history
  • Loading branch information
a-andre committed Aug 13, 2024
1 parent 38e3568 commit bc4c6e4
Show file tree
Hide file tree
Showing 71 changed files with 1,041 additions and 1,040 deletions.
4 changes: 2 additions & 2 deletions examples/CbcBranchFollow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ int CbcFollowOn2::gutsOfFollowOn2(int &otherRow, int &preferredWay,
double value = elementByRow[j];
double solValue = solution[iColumn];
if (columnLower[iColumn] != columnUpper[iColumn]) {
smallest = CoinMin(smallest, value);
largest = CoinMax(largest, value);
smallest = std::min(smallest, value);
largest = std::max(largest, value);
if (value == 1.0)
number1++;
else
Expand Down
20 changes: 10 additions & 10 deletions examples/CbcBranchLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ CbcLink::infeasibility(int &preferredWay) const
//throw CoinError("Non zero lower bound in CBCLink","infeasibility","CbcLink");
if (lastWeight >= weights_[j] - 1.0e-7)
throw CoinError("Weights too close together in CBCLink", "infeasibility", "CbcLink");
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
sum += value;
if (value > integerTolerance && upper[iColumn]) {
// Possibly due to scaling a fixed variable might slip through
Expand All @@ -177,7 +177,7 @@ CbcLink::infeasibility(int &preferredWay) const
iColumn, j, value, upper[iColumn]);
#endif
}
value = CoinMin(value, upper[iColumn]);
value = std::min(value, upper[iColumn]);
weight += weights_[j] * value;
if (firstNonZero < 0)
firstNonZero = j;
Expand Down Expand Up @@ -228,9 +228,9 @@ CbcLink::infeasibility(int &preferredWay) const
for (j = firstNonZero; j <= lastNonZero; j++) {
for (int k = 0; k < numberLinks_; k++) {
int iColumn = which_[base + k];
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
if (value > integerTolerance && upper[iColumn]) {
value = CoinMin(value, upper[iColumn]);
value = std::min(value, upper[iColumn]);
for (int j = columnStart[iColumn]; j < columnStart[iColumn] + columnLength[iColumn]; j++) {
int iRow = row[j];
double a = array[iRow];
Expand Down Expand Up @@ -317,7 +317,7 @@ void CbcLink::feasibleRegion()
for (j = 0; j < numberMembers_; j++) {
for (int k = 0; k < numberLinks_; k++) {
int iColumn = which_[base + k];
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
sum += value;
if (value > integerTolerance && upper[iColumn]) {
weight += weights_[j] * value;
Expand Down Expand Up @@ -361,9 +361,9 @@ void CbcLink::feasibleRegion()
for (j = firstNonZero; j <= lastNonZero; j++) {
for (int k = 0; k < numberLinks_; k++) {
int iColumn = which_[base + k];
double value = CoinMax(0.0, solution[iColumn]);
double value = std::max(0.0, solution[iColumn]);
if (value > integerTolerance && upper[iColumn]) {
value = CoinMin(value, upper[iColumn]);
value = std::min(value, upper[iColumn]);
for (int j = columnStart[iColumn]; j < columnStart[iColumn] + columnLength[iColumn]; j++) {
int iRow = row[j];
double a = array[iRow];
Expand Down Expand Up @@ -470,7 +470,7 @@ CbcLink::createCbcBranch(OsiSolverInterface * /*solver*/, const OsiBranchingInfo
for (int k = 0; k < numberLinks_; k++) {
int iColumn = which_[base + k];
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 @@ -619,8 +619,8 @@ void CbcLinkBranchingObject::print()
int iColumn = which[base + k];
double bound = upper[iColumn];
if (bound) {
first = CoinMin(first, i);
last = CoinMax(last, i);
first = std::min(first, i);
last = std::max(last, i);
}
}
base += numberLinks;
Expand Down
24 changes: 12 additions & 12 deletions examples/CbcBranchUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
case 0:
// could add in depth as well
for (i = 0; i < numberObjects; i++) {
int thisNumber = CoinMin(numberInfeasibilitiesUp[i], numberInfeasibilitiesDown[i]);
int thisNumber = std::min(numberInfeasibilitiesUp[i], numberInfeasibilitiesDown[i]);
if (thisNumber <= bestNumber) {
int betterWay = 0;
if (numberInfeasibilitiesUp[i] < numberInfeasibilitiesDown[i]) {
Expand All @@ -164,7 +164,7 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
if (numberInfeasibilitiesUp[i] < bestNumber) {
better = true;
} else if (numberInfeasibilitiesUp[i] == bestNumber) {
if (CoinMin(changeUp[i], changeDown[i]) < bestCriterion)
if (std::min(changeUp[i], changeDown[i]) < bestCriterion)
better = true;
;
}
Expand All @@ -177,7 +177,7 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
}
}
if (betterWay) {
bestCriterion = CoinMin(changeUp[i], changeDown[i]);
bestCriterion = std::min(changeUp[i], changeDown[i]);
bestNumber = thisNumber;
whichObject = i;
bestWay = betterWay;
Expand All @@ -196,15 +196,15 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
betterWay = -1;
}
if (betterWay) {
bestCriterion = CoinMin(changeUp[i], changeDown[i]);
bestCriterion = std::min(changeUp[i], changeDown[i]);
whichObject = i;
bestWay = betterWay;
}
}
break;
case 2:
for (i = 0; i < numberObjects; i++) {
double change = CoinMin(changeUp[i], changeDown[i]);
double change = std::min(changeUp[i], changeDown[i]);
double sum = changeUp[i] + changeDown[i];
bool take = false;
if (change > 1.1 * bestCriterion)
Expand Down Expand Up @@ -257,7 +257,7 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
// first get best number or when going down
// now choose smallest change up amongst equal number infeas
for (i = 0; i < numberObjects; i++) {
int thisNumber = CoinMin(numberInfeasibilitiesUp[i], numberInfeasibilitiesDown[i]);
int thisNumber = std::min(numberInfeasibilitiesUp[i], numberInfeasibilitiesDown[i]);
if (thisNumber <= bestNumber) {
int betterWay = 0;
if (numberInfeasibilitiesUp[i] < numberInfeasibilitiesDown[i]) {
Expand All @@ -280,7 +280,7 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
if (numberInfeasibilitiesUp[i] < bestNumber) {
better = true;
} else if (numberInfeasibilitiesUp[i] == bestNumber) {
if (CoinMin(changeUp[i], changeDown[i]) < bestCriterion)
if (std::min(changeUp[i], changeDown[i]) < bestCriterion)
better = true;
;
}
Expand All @@ -293,7 +293,7 @@ int CbcBranchUserDecision::bestBranch(CbcBranchingObject **objects, int numberOb
}
}
if (betterWay) {
bestCriterion = CoinMin(changeUp[i], changeDown[i]);
bestCriterion = std::min(changeUp[i], changeDown[i]);
bestNumber = thisNumber;
whichObject = i;
bestWay = betterWay;
Expand Down Expand Up @@ -381,8 +381,8 @@ CbcSimpleIntegerFixed::infeasibility(int &preferredWay) const
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_]);
/*printf("%d %g %g %g %g\n",columnNumber_,value,lower[columnNumber_],
solution[columnNumber_],upper[columnNumber_]);*/
double nearest = floor(value + (1.0 - breakEven_));
Expand Down Expand Up @@ -418,8 +418,8 @@ CbcSimpleIntegerFixed::createBranch(OsiSolverInterface *solver,
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(upper[columnNumber_] > lower[columnNumber_]);
if (!model_->hotstartSolution()) {
double nearest = floor(value + 0.5);
Expand Down
4 changes: 2 additions & 2 deletions examples/CbcCompareUser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ CbcCompareUser::test (CbcNode * x, CbcNode * y)
return x->depth() < y->depth();
} else {
// after solution
double weight = CoinMax(weight_,0.0);
double weight = std::max(weight_,0.0);
return x->objectiveValue()+ weight*x->numberUnsatisfied() >
y->objectiveValue() + weight*y->numberUnsatisfied();
//return x->guessedObjectiveValue()>y->guessedObjectiveValue();
Expand Down Expand Up @@ -202,7 +202,7 @@ bool CbcCompareUser::test(CbcNode *x, CbcNode *y)
}
} else {
// after solution
double weight = CoinMax(weight_, 0.0);
double weight = std::max(weight_, 0.0);
double testX = x->objectiveValue() + weight * x->numberUnsatisfied();
double testY = y->objectiveValue() + weight * y->numberUnsatisfied();
if (testX != testY)
Expand Down
4 changes: 2 additions & 2 deletions examples/CbcSolver2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void CbcSolver2::resolve()
int i;
for (i = 0; i < numberColumns; i++) {
if (solution[i] > 1.0e-6 || modelPtr_->getStatus(i) == ClpSimplex::basic) {
node_[i] = CoinMax(count_, node_[i]);
node_[i] = std::max(count_, node_[i]);
howMany_[i]++;
}
}
Expand Down Expand Up @@ -342,7 +342,7 @@ void CbcSolver2::resolve()
printf("count %d, bad %d - iterations %d\n", count_, timesBad_, iterationsBad_);
for (i = 0; i < numberColumns; i++) {
if (solution[i] > 1.0e-6 || modelPtr_->getStatus(i) == ClpSimplex::basic) {
node_[i] = CoinMax(count_, node_[i]);
node_[i] = std::max(count_, node_[i]);
howMany_[i]++;
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/CbcSolver3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void CbcSolver3::resolve()
for (i = 0; i < numberColumns2; i++) {
temp2.setInteger(i);
double value = solution2[i];
value = CoinMin(CoinMax(value, colLower2[i]), colUpper2[i]);
value = std::min(std::max(value, colLower2[i]), colUpper2[i]);
cleanSolution2[i] = value;
}
temp2.setColSolution(cleanSolution2);
Expand Down Expand Up @@ -270,7 +270,7 @@ void CbcSolver3::resolve()
int i;
for (i = 0; i < numberColumns; i++) {
if (solution[i] > 1.0e-6 || modelPtr_->getStatus(i) == ClpSimplex::basic) {
node_[i] = CoinMax(count_, node_[i]);
node_[i] = std::max(count_, node_[i]);
howMany_[i]++;
}
}
Expand Down Expand Up @@ -376,7 +376,7 @@ void CbcSolver3::resolve()
printf("count %d, bad %d\n", count_, timesBad_);
for (i = 0; i < numberColumns; i++) {
if (solution[i] > 1.0e-6 || modelPtr_->getStatus(i) == ClpSimplex::basic) {
node_[i] = CoinMax(count_, node_[i]);
node_[i] = std::max(count_, node_[i]);
howMany_[i]++;
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/CbcSolverLongThin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void CbcSolverLongThin::resolve()
for (i = 0; i < numberColumns2; i++) {
temp2.setInteger(i);
double value = solution2[i];
value = CoinMin(CoinMax(value, colLower2[i]), colUpper2[i]);
value = std::min(std::max(value, colLower2[i]), colUpper2[i]);
cleanSolution2[i] = value;
}
temp2.setColSolution(cleanSolution2);
Expand Down Expand Up @@ -496,7 +496,7 @@ void CbcSolverLongThin::resolve()
int i;
for (i = 0; i < numberColumns; i++) {
if (solution[i] > 1.0e-6 || modelPtr_->getStatus(i) == ClpSimplex::basic) {
node_[i] = CoinMax(count_, node_[i]);
node_[i] = std::max(count_, node_[i]);
howMany_[i]++;
}
}
Expand Down Expand Up @@ -601,7 +601,7 @@ void CbcSolverLongThin::resolve()
printf("count %d, bad %d\n", count_, timesBad_);
for (i = 0; i < numberColumns; i++) {
if (solution[i] > 1.0e-6 || modelPtr_->getStatus(i) == ClpSimplex::basic) {
node_[i] = CoinMax(count_, node_[i]);
node_[i] = std::max(count_, node_[i]);
howMany_[i]++;
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/allCuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void CglStoredUser::generateCuts(const OsiSolverInterface &si, OsiCuts &cs,
for (i = 0; i < numberColumns; i++) {
double value = solution[i];
// In case slightly away from bounds
value = CoinMax(colLower[i], value);
value = CoinMin(colUpper[i], value);
value = std::max(colLower[i], value);
value = std::min(colUpper[i], value);
if (si.isInteger(i) && fabs(value - fabs(value + 0.5)) > 1.0e-5)
numberAway++;
}
Expand Down Expand Up @@ -326,7 +326,7 @@ int main(int argc, const char *argv[])
}
}
// leave some rows to avoid empty problem (Gomory does not like)
nDelete = CoinMax(CoinMin(nDelete, numberRows - 5), 0);
nDelete = std::max(std::min(nDelete, numberRows - 5), 0);
for (int jRow = 0; jRow < nDelete; jRow++) {
iRow = whichRow[jRow];
int start = rowStart[iRow];
Expand Down Expand Up @@ -441,7 +441,7 @@ int main(int argc, const char *argv[])

// Could tune more
double objValue = model.solver()->getObjSense() * model.solver()->getObjValue();
double minimumDropA = CoinMin(1.0, fabs(objValue) * 1.0e-3 + 1.0e-4);
double minimumDropA = std::min(1.0, fabs(objValue) * 1.0e-3 + 1.0e-4);
double minimumDrop = fabs(objValue) * 1.0e-4 + 1.0e-4;
printf("min drop %g (A %g)\n", minimumDrop, minimumDropA);
model.setMinimumDrop(minimumDrop);
Expand Down
16 changes: 8 additions & 8 deletions examples/driver5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ CbcUserSOS::infeasibility(const OsiBranchingInformation *info,

if (lastWeight >= weights_[j] - 1.0e-7)
throw CoinError("Weights too close together in SOS", "infeasibility", "CbcSOS");
double value = CoinMax(lower[iColumn], solution[iColumn]);
value = CoinMin(upper[iColumn], value);
double value = std::max(lower[iColumn], solution[iColumn]);
value = std::min(upper[iColumn], value);
sum += value;
if (fabs(value) > integerTolerance && (upper[iColumn] > 0.0 || oddValues_)) {
weight += weights_[j] * value;
Expand Down Expand Up @@ -233,7 +233,7 @@ CbcUserSOS::infeasibility(const OsiBranchingInformation *info,
// if move makes infeasible then make at least default
double newValue = activity[iRow] + movement;
if (newValue > upper[iRow] + tolerance || newValue < lower[iRow] - tolerance) {
shadowEstimateDown_ += fabs(movement) * CoinMax(fabs(valueP), info->defaultDual_);
shadowEstimateDown_ += fabs(movement) * std::max(fabs(valueP), info->defaultDual_);
infeasible = true;
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ CbcUserSOS::infeasibility(const OsiBranchingInformation *info,
// if move makes infeasible then make at least default
double newValue = activity[iRow] + movement;
if (newValue > upper[iRow] + tolerance || newValue < lower[iRow] - tolerance) {
shadowEstimateUp_ += fabs(movement) * CoinMax(fabs(valueP), info->defaultDual_);
shadowEstimateUp_ += fabs(movement) * std::max(fabs(valueP), info->defaultDual_);
infeasible = true;
}
}
Expand All @@ -307,8 +307,8 @@ CbcUserSOS::infeasibility(const OsiBranchingInformation *info,
#define WEIGHT_BEFORE 0.1
int stateOfSearch = model_->stateOfSearch() % 10;
double returnValue = 0.0;
double minValue = CoinMin(downCost, upCost);
double maxValue = CoinMax(downCost, upCost);
double minValue = std::min(downCost, upCost);
double maxValue = std::max(downCost, upCost);
if (stateOfSearch <= 2) {
// no branching solution
returnValue = WEIGHT_BEFORE * minValue + (1.0 - WEIGHT_BEFORE) * maxValue;
Expand Down Expand Up @@ -342,8 +342,8 @@ CbcUserSOS::createCbcBranch(OsiSolverInterface *solver, const OsiBranchingInform
int lastNonZero = -1;
for (j = 0; j < numberMembers_; j++) {
int iColumn = members_[j];
double value = CoinMax(lower[iColumn], solution[iColumn]);
value = CoinMin(upper[iColumn], value);
double value = std::max(lower[iColumn], solution[iColumn]);
value = std::min(upper[iColumn], value);
if (fabs(value) > integerTolerance) {
if (firstNonZero < 0)
firstNonZero = j;
Expand Down
Loading

0 comments on commit bc4c6e4

Please sign in to comment.