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 authored and tkralphs committed Aug 16, 2024
1 parent ba1c6bb commit 2878ea1
Show file tree
Hide file tree
Showing 79 changed files with 2,001 additions and 2,000 deletions.
2 changes: 1 addition & 1 deletion examples/addColumns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int main(int argc, const char *argv[])
model.dual();
// Print column solution Just first 3 columns
int numberColumns = model.numberColumns();
numberColumns = CoinMin(3, numberColumns);
numberColumns = std::min(3, numberColumns);

// Alternatively getColSolution()
double * columnPrimal = model.primalColumnSolution();
Expand Down
4 changes: 2 additions & 2 deletions examples/cleanModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ int main(int argc, const char *argv[])
double value = mult*tempSave[i];
if (value) {
double vint = floor(value+0.01);
largestError = CoinMax(largestError,fabs(value-vint));
largestError = std::max(largestError,fabs(value-vint));
assert (fabs(vint)>0.9);
}
}
Expand Down Expand Up @@ -240,7 +240,7 @@ int main(int argc, const char *argv[])
if (fabs(rowScale[iRow])!=1.0) {
value *= rowScale[iRow];
double vint = floor(value+0.01);
largestDelta = CoinMax(largestDelta,fabs(value-vint));
largestDelta = std::max(largestDelta,fabs(value-vint));
assert (largestDelta<1.0e-9);
columnElements[j] = vint;
assert (fabs(vint)>0.9);
Expand Down
8 changes: 4 additions & 4 deletions examples/decompose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ int main(int argc, const char *argv[])
double value = elementAdd[start+i];
if (fabs(value) > 1.0e-15) {
dj -= dual[i] * value;
smallest = CoinMin(smallest, fabs(value));
largest = CoinMax(largest, fabs(value));
smallest = std::min(smallest, fabs(value));
largest = std::max(largest, fabs(value));
rowAdd[number] = i;
elementAdd[number++] = value;
}
Expand Down Expand Up @@ -380,8 +380,8 @@ int main(int argc, const char *argv[])
double value = elementAdd[start+i];
if (fabs(value) > 1.0e-15) {
dj -= dual[i] * value;
smallest = CoinMin(smallest, fabs(value));
largest = CoinMax(largest, fabs(value));
smallest = std::min(smallest, fabs(value));
largest = std::max(largest, fabs(value));
rowAdd[number] = i;
elementAdd[number++] = value;
}
Expand Down
12 changes: 6 additions & 6 deletions examples/dualCuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, const char *argv[])
numberSort /= 2;
// Just add this number of rows each time in small problem
int smallNumberRows = 2 * numberColumns;
smallNumberRows = CoinMin(smallNumberRows, originalNumberRows / 20);
smallNumberRows = std::min(smallNumberRows, originalNumberRows / 20);
// and pad out with random rows
double ratio = ((double)(smallNumberRows - numberSort)) / ((double) originalNumberRows);
for (iRow = 0; iRow < originalNumberRows; iRow++) {
Expand All @@ -104,8 +104,8 @@ int main(int argc, const char *argv[])
double * columnLower = model2->columnLower();
double * columnUpper = model2->columnUpper();
for (iColumn = 0; iColumn < numberColumns; iColumn++) {
columnLower[iColumn] = CoinMax(-1.0e6, columnLower[iColumn]);
columnUpper[iColumn] = CoinMin(1.0e6, columnUpper[iColumn]);
columnLower[iColumn] = std::max(-1.0e6, columnLower[iColumn]);
columnUpper[iColumn] = std::min(1.0e6, columnUpper[iColumn]);
}
#endif
model2->tightenPrimalBounds(-1.0e4, true);
Expand Down Expand Up @@ -183,7 +183,7 @@ int main(int argc, const char *argv[])
// Basic - we can get rid of if early on
if (iPass < takeOutPass && !dualInfeasible) {
// may have hit max iterations so check
double infeasibility = CoinMax(fullSolution[iRow] - rowUpper[iRow],
double infeasibility = std::max(fullSolution[iRow] - rowUpper[iRow],
rowLower[iRow] - fullSolution[iRow]);
weight[iRow] = -infeasibility;
if (infeasibility > 1.0e-8) {
Expand All @@ -210,7 +210,7 @@ int main(int argc, const char *argv[])
sort[iRow] = iRow;
if (weight[iRow] == 1.123e50) {
// not looked at yet
double infeasibility = CoinMax(fullSolution[iRow] - rowUpper[iRow],
double infeasibility = std::max(fullSolution[iRow] - rowUpper[iRow],
rowLower[iRow] - fullSolution[iRow]);
weight[iRow] = -infeasibility;
if (infeasibility > 1.0e-8) {
Expand All @@ -221,7 +221,7 @@ int main(int argc, const char *argv[])
}
// sort
CoinSort_2(weight, weight + originalNumberRows, sort);
numberSort = CoinMin(originalNumberRows, smallNumberRows + numberKept);
numberSort = std::min(originalNumberRows, smallNumberRows + numberKept);
memset(take, 0, originalNumberRows);
for (iRow = 0; iRow < numberSort; iRow++)
take[sort[iRow]] = 1;
Expand Down
10 changes: 5 additions & 5 deletions examples/myPdco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ myPdco::myPdco(ClpInterior & model, FILE * fpData, FILE * fpParam)
numlinks_++;
ir[nonzpt++] = *ifrom;
ir[nonzpt++] = *ito;
imax = CoinMax(imax, *ifrom);
imax = CoinMax(imax, *ito);
imin = CoinMin(imin, *ifrom);
imin = CoinMin(imin, *ito);
imax = std::max(imax, *ifrom);
imax = std::max(imax, *ito);
imin = std::min(imin, *ifrom);
imin = std::min(imin, *ito);
}
fclose(fpData);
fclose(fpParam);
Expand Down Expand Up @@ -294,6 +294,6 @@ myPdco::myPdco(ClpInterior & model, FILE * fpData, FILE * fpParam)
model.y_ = y;
model.dj_ = dj;
model.xsize_ = 50 / ncol;
model.xsize_ = CoinMin(model.xsize_, 1.0);
model.xsize_ = std::min(model.xsize_, 1.0);
model.zsize_ = 1;
}
2 changes: 1 addition & 1 deletion examples/pdco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, const char *argv[])
info.LSdamp = 0.0;
// These are already set?
model.xsize_ = 50.0 / (model.numberColumns());
model.xsize_ = CoinMin(1.0, model.xsize_);
model.xsize_ = std::min(1.0, model.xsize_);

/*
* Solve the test problem
Expand Down
6 changes: 3 additions & 3 deletions examples/sprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ int main(int argc, const char *argv[])
double lastObjective = 1.0e31;

// Just take this number of columns in small problem
int smallNumberColumns = CoinMin(3 * numberRows, numberColumns);
smallNumberColumns = CoinMax(smallNumberColumns, 3000);
int smallNumberColumns = std::min(3 * numberRows, numberColumns);
smallNumberColumns = std::max(smallNumberColumns, 3000);
// To stop seg faults on unsuitable problems
smallNumberColumns = CoinMin(smallNumberColumns,numberColumns);
smallNumberColumns = std::min(smallNumberColumns,numberColumns);
// We will be using all rows
int * whichRows = new int [numberRows];
for (int iRow = 0; iRow < numberRows; iRow++)
Expand Down
4 changes: 2 additions & 2 deletions examples/sprint2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, const char *argv[])
// Just take this number of columns in small problem
int smallNumberColumns = 3 * numberRows;
// To stop seg faults on unsuitable problems
smallNumberColumns = CoinMin(smallNumberColumns,numberColumns);
smallNumberColumns = std::min(smallNumberColumns,numberColumns);
// And we want number of rows to be this
int smallNumberRows = numberRows / 4;

Expand Down Expand Up @@ -102,7 +102,7 @@ int main(int argc, const char *argv[])
double ratio = ((double) smallNumberRows) / ((double) model2->numberRows());
smallNumberColumns = (int)(smallNumberColumns * ratio);
// deal with pathological case
smallNumberColumns = CoinMax(smallNumberColumns,0);
smallNumberColumns = std::max(smallNumberColumns,0);
}
delete model2;
/* After this postsolve model should be optimal.
Expand Down
4 changes: 2 additions & 2 deletions examples/testGub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ int main(int argc, const char *argv[])
gubRow = false;
break;
} else {
last = CoinMax(last, iColumn);
first = CoinMin(first, iColumn);
last = std::max(last, iColumn);
first = std::min(first, iColumn);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/testGub2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ int main(int argc, const char *argv[])
gubRow = false;
break;
} else {
last = CoinMax(last, iColumn);
first = CoinMin(first, iColumn);
last = std::max(last, iColumn);
first = std::min(first, iColumn);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/AbcDualRowDantzig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ int AbcDualRowDantzig::pivotRow()
const double *COIN_RESTRICT upperBasic = model_->upperBasic();
const int *pivotVariable = model_->pivotVariable();
// code so has list of infeasibilities (like steepest)
int numberWanted = CoinMax(2000, numberRows >> 4);
numberWanted = CoinMax(numberWanted, number >> 2);
int numberWanted = std::max(2000, numberRows >> 4);
numberWanted = std::max(numberWanted, number >> 2);
if (model_->largestPrimalError() > 1.0e-3)
numberWanted = number + 1; // be safe
// Setup two passes
Expand All @@ -202,7 +202,7 @@ int AbcDualRowDantzig::pivotRow()
int endThis = start[2 * iPass + 1];
int startThis = start[2 * iPass];
while (startThis < endThis) {
int end = CoinMin(endThis, startThis + numberWanted);
int end = std::min(endThis, startThis + numberWanted);
#ifdef DO_REDUCE
if (doReduce) {
choose(infeasible, chosenRow, largest, startThis, end, tolerance);
Expand Down
50 changes: 25 additions & 25 deletions src/AbcDualRowSteepest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ AbcDualRowSteepest::AbcDualRowSteepest(const AbcDualRowSteepest &rhs)
if ((model_ && model_->whatsChanged() & 1) != 0) {
int number = model_->numberRows();
if (rhs.savedWeights_)
number = CoinMin(number, rhs.savedWeights_->capacity());
number = std::min(number, rhs.savedWeights_->capacity());
if (rhs.infeasible_) {
infeasible_ = new CoinIndexedVector(rhs.infeasible_);
} else {
Expand Down Expand Up @@ -103,7 +103,7 @@ AbcDualRowSteepest::operator=(const AbcDualRowSteepest &rhs)
assert(model_);
int number = model_->numberRows();
if (rhs.savedWeights_)
number = CoinMin(number, rhs.savedWeights_->capacity());
number = std::min(number, rhs.savedWeights_->capacity());
if (rhs.infeasible_ != NULL) {
infeasible_ = new CoinIndexedVector(rhs.infeasible_);
} else {
Expand Down Expand Up @@ -135,7 +135,7 @@ void AbcDualRowSteepest::fill(const AbcDualRowSteepest &rhs)
assert(model_);
int number = model_->numberRows();
if (rhs.savedWeights_)
number = CoinMin(number, rhs.savedWeights_->capacity());
number = std::min(number, rhs.savedWeights_->capacity());
if (rhs.infeasible_ != NULL) {
if (!infeasible_)
infeasible_ = new CoinIndexedVector(rhs.infeasible_);
Expand Down Expand Up @@ -182,7 +182,7 @@ static void choose(int &chosenRow, double &largest, int n,
int iRow = index[i];
double value = infeas[iRow];
if (value > tolerance) {
double thisWeight = CoinMin(weights[iRow], 1.0e50);
double thisWeight = std::min(weights[iRow], 1.0e50);
maximumIndex.calc_max(iRow, value / thisWeight);
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ static void choose(AbcDualRowSteepest *steepest,
int iRow = index[i];
double value = infeas[iRow];
if (value > tolerance) {
double thisWeight = CoinMin(weights[iRow], 1.0e50);
double thisWeight = std::min(weights[iRow], 1.0e50);
if (value > largest * thisWeight) {
largest = value / thisWeight;
chosenRow = iRow;
Expand All @@ -234,7 +234,7 @@ static void choose(AbcDualRowSteepest *steepest,
if (value > tolerance) {
int iSequence = pivotVariable[iRow];
value *= (fabs(fakeDjs[iSequence]) + 1.0e-6);
double thisWeight = CoinMin(weights[iRow], 1.0e50);
double thisWeight = std::min(weights[iRow], 1.0e50);
/*
Ideas
always use fake
Expand Down Expand Up @@ -302,11 +302,11 @@ int AbcDualRowSteepest::pivotRow()
double tolerance = model_->currentPrimalTolerance();
// we can't really trust infeasibilities if there is primal error
// this coding has to mimic coding in checkPrimalSolution
double error = CoinMin(1.0e-2, model_->largestPrimalError());
double error = std::min(1.0e-2, model_->largestPrimalError());
// allow tolerance at least slightly bigger than standard
tolerance = tolerance + error;
// But cap
tolerance = CoinMin(1000.0, tolerance);
tolerance = std::min(1000.0, tolerance);
tolerance *= tolerance; // as we are using squares
bool toleranceChanged = false;
const double *COIN_RESTRICT solutionBasic = model_->solutionBasic();
Expand Down Expand Up @@ -343,7 +343,7 @@ int AbcDualRowSteepest::pivotRow()
if (model_->numberIterations() < model_->lastBadIteration() + 200) {
// we can't really trust infeasibilities if there is dual error
if (model_->largestDualError() > model_->largestPrimalError()) {
tolerance *= CoinMin(model_->largestDualError() / model_->largestPrimalError(), 1000.0);
tolerance *= std::min(model_->largestDualError() / model_->largestPrimalError(), 1000.0);
toleranceChanged = true;
}
}
Expand Down Expand Up @@ -382,28 +382,28 @@ int AbcDualRowSteepest::pivotRow()
// look at this and modify
numberWanted = number+1;
if (factorizationRatio_ < 1.0) {
numberWanted = CoinMax(2000, numberRows / 20);
numberWanted = std::max(2000, numberRows / 20);
#if 0
} else if (factorizationRatio_ > 10.0) {
double ratio = number * (factorizationRatio_ / 80.0);
if (ratio > number)
numberWanted = number + 1;
else
numberWanted = CoinMax(2000, static_cast<int> (ratio));
numberWanted = std::max(2000, static_cast<int> (ratio));
#else
} else {
//double multiplier=CoinMin(factorizationRatio_*0.1,1.0)
//double multiplier=std::min(factorizationRatio_*0.1,1.0)
#endif
}
#else
numberWanted = CoinMax(2000, number / 8);
numberWanted = std::max(2000, number / 8);
if (factorizationRatio_ < 1.5) {
numberWanted = CoinMax(2000, number / 20);
numberWanted = std::max(2000, number / 20);
} else if (factorizationRatio_ > 5.0) {
numberWanted = number + 1;
}
#endif
numberWanted = CoinMin(numberWanted, number + 1);
numberWanted = std::min(numberWanted, number + 1);
}
if (model_->largestPrimalError() > 1.0e-3)
numberWanted = number + 1; // be safe
Expand Down Expand Up @@ -439,7 +439,7 @@ int AbcDualRowSteepest::pivotRow()
int endThis = start[2 * iPass + 1];
int startThis = start[2 * iPass];
while (startThis < endThis) {
int end = CoinMin(endThis, startThis + numberWanted);
int end = std::min(endThis, startThis + numberWanted);
#ifdef DO_REDUCE
if (doReduce) {
#if DO_REDUCE == 1
Expand Down Expand Up @@ -474,9 +474,9 @@ int AbcDualRowSteepest::pivotRow()
if (upper[iRow] == lower[iRow])
value *= 2.0;
#endif
double thisWeight = CoinMin(weights[iRow], 1.0e50);
//largestWeight = CoinMax(largestWeight,weight);
//smallestWeight = CoinMin(smallestWeight,weight);
double thisWeight = std::min(weights[iRow], 1.0e50);
//largestWeight = std::max(largestWeight,weight);
//smallestWeight = std::min(smallestWeight,weight);
//double dubious = dubiousWeights_[iRow];
//weight *= dubious;
//if (value>2.0*largest*weight||(value>0.5*largest*weight&&value*largestWeight>dubious*largest*weight)) {
Expand All @@ -496,7 +496,7 @@ int AbcDualRowSteepest::pivotRow()
value2 = solutionBasic[iRow] - upperBasic[iRow];
else if (solutionBasic[iRow] < lowerBasic[iRow] - tolerance)
value2 = solutionBasic[iRow] - lowerBasic[iRow];
assert(fabs(value2 * value2 - infeas[iRow]) < 1.0e-8 * CoinMin(value2 * value2, infeas[iRow]));
assert(fabs(value2 * value2 - infeas[iRow]) < 1.0e-8 * std::min(value2 * value2, infeas[iRow]));
#endif
if (solutionBasic[iRow] > upperBasic[iRow] + tolerance || solutionBasic[iRow] < lowerBasic[iRow] - tolerance) {
chosenRow = iRow;
Expand Down Expand Up @@ -592,7 +592,7 @@ AbcDualRowSteepest::updateWeights(CoinIndexedVector &input,
array[iRow] = 0.0;
}
temp.setNumElements(0);
double w = CoinMax(weights[i], value) * .1;
double w = std::max(weights[i], value) * .1;
if (fabs(weights[i] - value) > w) {
printf("%d old %g, true %g\n", i, weights[i], value);
weights[i] = value; // to reduce printout
Expand Down Expand Up @@ -722,7 +722,7 @@ AbcDualRowSteepest::updateWeights1(CoinIndexedVector &input, CoinIndexedVector &
array[iRow] = 0.0;
}
temp.setNumElements(0);
double w = CoinMax(weights[i], value) * .1;
double w = std::max(weights[i], value) * .1;
if (fabs(weights[i] - value) > w) {
printf("XX row %d (variable %d) old %g, true %g\n", i, pivotVariable[i],
weights[i], value);
Expand Down Expand Up @@ -1229,7 +1229,7 @@ void AbcDualRowSteepest::saveWeights(AbcSimplex *model, int mode)
} else {
// parallel
// get arrays
int numberCpuMinusOne = CoinMin(model_->parallelMode(), 3);
int numberCpuMinusOne = std::min(model_->parallelMode(), 3);
int which[3];
CoinIndexedVector *whichVector[4];
for (int i = 0; i < numberCpuMinusOne; i++) {
Expand Down Expand Up @@ -1426,11 +1426,11 @@ bool AbcDualRowSteepest::looksOptimal() const
double tolerance = model_->currentPrimalTolerance();
// we can't really trust infeasibilities if there is primal error
// this coding has to mimic coding in checkPrimalSolution
double error = CoinMin(1.0e-2, model_->largestPrimalError());
double error = std::min(1.0e-2, model_->largestPrimalError());
// allow tolerance at least slightly bigger than standard
tolerance = tolerance + error;
// But cap
tolerance = CoinMin(1000.0, tolerance);
tolerance = std::min(1000.0, tolerance);
int numberRows = model_->numberRows();
int numberInfeasible = 0;
const double *COIN_RESTRICT solutionBasic = model_->solutionBasic();
Expand Down
Loading

0 comments on commit 2878ea1

Please sign in to comment.