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 a39161a commit 4dd6395
Show file tree
Hide file tree
Showing 21 changed files with 275 additions and 275 deletions.
2 changes: 1 addition & 1 deletion examples/cgl1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int main(int argc, const char *argv[])
// almost equal to prior value.
//
// The test is:
// abs(oldObj-newObj) <= 0.0001*(CoinMax(abs(oldObj),abs(newObj))+1.);
// abs(oldObj-newObj) <= 0.0001*(std::max(abs(oldObj),abs(newObj))+1.);
// see CoinRelFloatEqual.h
// -----------------------------------------------
equalObj = eq( si.getObjValue(), obj );
Expand Down
6 changes: 3 additions & 3 deletions src/CglAllDifferent/CglAllDifferent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void CglAllDifferent::generateCuts(const OsiSolverInterface & si, OsiCuts & cs,
for (i=0;i<numberSets_;i++) {
for (int j=start_[i];j<start_[i+1];j++) {
int k=which_[j];
offset = CoinMin(offset,lo[k]);
maxValue = CoinMax(maxValue,up[k]);
offset = std::min(offset,lo[k]);
maxValue = std::max(maxValue,up[k]);
}
numberLook++;
int gap = maxValue-offset+1;
Expand Down Expand Up @@ -452,7 +452,7 @@ originalWhich_(NULL)
for (i=0;i<n;i++) {
int iColumn = which[i];
assert (iColumn>=0);
maxValue = CoinMax(iColumn,maxValue);
maxValue = std::max(iColumn,maxValue);
}
maxValue++;
int * translate = new int[maxValue];
Expand Down
8 changes: 4 additions & 4 deletions src/CglClique/CglClique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ CglClique::generateCuts(const OsiSolverInterface& si, OsiCuts & cs,
}
// Just original rows
if (justOriginalRows_&&info.inTree)
sp_numrows = CoinMin(info.formulation_rows,sp_numrows);
sp_numrows = std::min(info.formulation_rows,sp_numrows);

#ifndef MAX_CGLCLIQUE_ROWS
#define MAX_CGLCLIQUE_ROWS 100000
Expand Down Expand Up @@ -220,7 +220,7 @@ CglClique::find_rcl(OsiCuts& cs)
for (k = 0; k < nodenum; k++)
if (cand[k])
cl_indices[cl_length++] = k;
largest_length = CoinMax(cl_length, largest_length);
largest_length = std::max(cl_length, largest_length);

/* if there is anything in indices, enumerate (or greedily find)
maximal cliques */
Expand Down Expand Up @@ -335,7 +335,7 @@ CglClique::find_scl(OsiCuts& cs)
v = current_indices[best_ind];
v_deg = current_degrees[best_ind];
v_val = current_values[best_ind];
largest_star_size = CoinMax(largest_star_size, v_deg);
largest_star_size = std::max(largest_star_size, v_deg);
continue;
}

Expand Down Expand Up @@ -394,7 +394,7 @@ CglClique::find_scl(OsiCuts& cs)
v = current_indices[best_ind];
v_deg = current_degrees[best_ind];
v_val = current_values[best_ind];
largest_star_size = CoinMax(largest_star_size, v_deg);
largest_star_size = std::max(largest_star_size, v_deg);
}

const int clique_cnt = clique_cnt_e + clique_cnt_g;
Expand Down
10 changes: 5 additions & 5 deletions src/CglCommon/CglTreeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ static int outDupsEtc(int numberIntegers, int &numberCliques, int &numberMatrixC
int iValue = value[kClique];
if (iValue < numberIntegers)
break;
iLowest = CoinMin(iLowest, kClique);
iLowest = std::min(iLowest, kClique);
}
if (jClique > jFirst) {
// mark all apart from lowest number as duplicate and move on
Expand Down Expand Up @@ -1012,7 +1012,7 @@ CglTreeProbingInfo::analyze(const OsiSolverInterface &si, int createSolver,
printf("] by %d(0)\n", iColumn);
nStrengthen++;
if (numberEntries + jCount + 1 > maximumEntries) {
maximumEntries = CoinMax(numberEntries + jCount + 1, (maximumEntries * 12) / 10 + 100);
maximumEntries = std::max(numberEntries + jCount + 1, (maximumEntries * 12) / 10 + 100);
CliqueEntry *temp = new CliqueEntry[maximumEntries];
memcpy(temp, entry, numberEntries * sizeof(CliqueEntry));
delete[] entry;
Expand Down Expand Up @@ -1101,7 +1101,7 @@ CglTreeProbingInfo::analyze(const OsiSolverInterface &si, int createSolver,
#endif
nStrengthen++;
if (numberEntries + jCount + 1 > maximumEntries) {
maximumEntries = CoinMax(numberEntries + jCount + 1, (maximumEntries * 12) / 10 + 100);
maximumEntries = std::max(numberEntries + jCount + 1, (maximumEntries * 12) / 10 + 100);
CliqueEntry *temp = new CliqueEntry[maximumEntries];
memcpy(temp, entry, numberEntries * sizeof(CliqueEntry));
delete[] entry;
Expand Down Expand Up @@ -1178,7 +1178,7 @@ CglTreeProbingInfo::analyze(const OsiSolverInterface &si, int createSolver,
if (numberCliques > numberMatrixCliques || alwaysDo) {
newSolver = si.clone();
// Delete all rows
CoinBigIndex *start = new CoinBigIndex[CoinMax(numberRows, numberCliques + 1)];
CoinBigIndex *start = new CoinBigIndex[std::max(numberRows, numberCliques + 1)];
int i;
int *start2 = reinterpret_cast< int * >(start);
for (i = 0; i < numberRows; i++)
Expand Down Expand Up @@ -1245,7 +1245,7 @@ bool CglTreeProbingInfo::fixes(int variable, int toValue, int fixedVariable, boo
int fixedTo = fixedToLower ? 0 : 1;
if (numberEntries_ == maximumEntries_) {
// See if taking too much memory
if (maximumEntries_ >= CoinMax(1000000, 10 * numberIntegers_))
if (maximumEntries_ >= std::max(1000000, 10 * numberIntegers_))
return false;
maximumEntries_ += 100 + maximumEntries_ / 2;
CliqueEntry *temp1 = new CliqueEntry[maximumEntries_];
Expand Down
58 changes: 29 additions & 29 deletions src/CglDuplicateRow/CglDuplicateRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void CglDuplicateRow::generateCuts12(const OsiSolverInterface & si, OsiCuts & cs
if ((rowLower[i]<=0.0||rowLower[i]==rowUpper[i])&&
rowUpper[i]==floor(rowUpper[i])) {
effectiveRhs[i]= static_cast<int> (rowUpper[i]);
effectiveLower[i] = static_cast<int> (CoinMax(0.0,rowLower[i]));
effectiveLower[i] = static_cast<int> (std::max(0.0,rowLower[i]));
bool goodRow=true;
for (CoinBigIndex j=rowStart[i];j<rowStart[i]+rowLength[i];j++) {
int iColumn = column[j];
Expand Down Expand Up @@ -1054,7 +1054,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
break;
}
nRow2=nnRow2;
nRowStart=CoinMax(0,nRowStart);
nRowStart=std::max(0,nRowStart);
unsigned char * mark = columnFlag+nCol2;
memset(mark,0,nCol2);
/* at most 3 0-1 integers -
Expand Down Expand Up @@ -1102,7 +1102,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
if (nInt==2) {
double upRhs = effectiveRhs[i];
double loRhs = ((rowFlag[i]&1)!=0) ? effectiveRhs[i] : -1.0e30;
double tolerance = CoinMax(1.0e-5,fabs(upRhs)*1.0e-10);
double tolerance = std::max(1.0e-5,fabs(upRhs)*1.0e-10);
for (int j0=0;j0<2;j0++) {
for (int j1=0;j1<2;j1++) {
double value = element0[0]*j0+element0[1]*j1;
Expand All @@ -1115,7 +1115,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
}
upRhs = effectiveRhs[k];
loRhs = ((rowFlag[k]&1)!=0) ? effectiveRhs[k] : -1.0e30;
tolerance = CoinMax(1.0e-5,fabs(upRhs)*1.0e-10);
tolerance = std::max(1.0e-5,fabs(upRhs)*1.0e-10);
for (int j0=0;j0<2;j0++) {
for (int j1=0;j1<2;j1++) {
double value = element1[0]*j0+element1[1]*j1;
Expand Down Expand Up @@ -1310,7 +1310,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
assert (nInt==3);
double upRhs = effectiveRhs[i];
double loRhs = ((rowFlag[i]&1)!=0) ? effectiveRhs[i] : -1.0e30;
double tolerance = CoinMax(1.0e-5,fabs(upRhs)*1.0e-10);
double tolerance = std::max(1.0e-5,fabs(upRhs)*1.0e-10);
for (int j0=0;j0<2;j0++) {
for (int j1=0;j1<2;j1++) {
for (int j2=0;j2<2;j2++) {
Expand All @@ -1326,7 +1326,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
}
upRhs = effectiveRhs[k];
loRhs = ((rowFlag[k]&1)!=0) ? effectiveRhs[k] : -1.0e30;
tolerance = CoinMax(1.0e-5,fabs(upRhs)*1.0e-10);
tolerance = std::max(1.0e-5,fabs(upRhs)*1.0e-10);
for (int j0=0;j0<2;j0++) {
for (int j1=0;j1<2;j1++) {
for (int j2=0;j2<2;j2++) {
Expand Down Expand Up @@ -1551,7 +1551,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
} else {
el0[2]=element0[j];
col[2]=iColumn;
bound=CoinMin(newBound[iColumn],1.0e30);
bound=std::min(newBound[iColumn],1.0e30);
}
}
kk=0;
Expand All @@ -1574,7 +1574,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
// crude - should go stack based
double upRhs = effectiveRhs[i];
double loRhs = ((rowFlag[i]&1)!=0) ? effectiveRhs[i] : -1.0e30;
double tolerance = CoinMax(1.0e-5,fabs(upRhs)*1.0e-10);
double tolerance = std::max(1.0e-5,fabs(upRhs)*1.0e-10);
for (int j0=0;j0<2;j0++) {
for (int j1=0;j1<2;j1++) {
double value = el0[0]*j0+el0[1]*j1;
Expand Down Expand Up @@ -1609,7 +1609,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
}
upRhs = effectiveRhs[k];
loRhs = ((rowFlag[k]&1)!=0) ? effectiveRhs[k] : -1.0e30;
tolerance = CoinMax(1.0e-5,fabs(upRhs)*1.0e-10);
tolerance = std::max(1.0e-5,fabs(upRhs)*1.0e-10);
for (int j0=0;j0<2;j0++) {
for (int j1=0;j1<2;j1++) {
double value = el1[0]*j0+el1[1]*j1;
Expand Down Expand Up @@ -1701,8 +1701,8 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
#ifdef CGL_INVESTIGATE
printf("\n");
#endif
newLo=CoinMin(newLo,CoinMax(loC0[jj],loC1[jj]));
newUp=CoinMax(newUp,CoinMin(upC0[jj],upC1[jj]));
newLo=std::min(newLo,std::max(loC0[jj],loC1[jj]));
newUp=std::max(newUp,std::min(upC0[jj],upC1[jj]));
} else {
#ifdef CGL_INVESTIGATE
printf(" INF\n");
Expand All @@ -1725,8 +1725,8 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
#ifdef CGL_INVESTIGATE
printf("\n");
#endif
newLo=CoinMin(newLo,CoinMax(loC0[k],loC1[k]));
newUp=CoinMax(newUp,CoinMin(upC0[k],upC1[k]));
newLo=std::min(newLo,std::max(loC0[k],loC1[k]));
newUp=std::max(newUp,std::min(upC0[k],upC1[k]));
} else {
#ifdef CGL_INVESTIGATE
printf(" INF\n");
Expand Down Expand Up @@ -1763,10 +1763,10 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
}
}
for (int jj=0;jj<(1<<nInt);jj++) {
loC0[jj]=CoinMax(loC0[jj],newLo);
loC1[jj]=CoinMax(loC1[jj],newLo);
upC0[jj]=CoinMin(upC0[jj],newUp);
upC1[jj]=CoinMin(upC1[jj],newUp);
loC0[jj]=std::max(loC0[jj],newLo);
loC1[jj]=std::max(loC1[jj],newLo);
upC0[jj]=std::min(upC0[jj],newUp);
upC1[jj]=std::min(upC1[jj],newUp);
}
for (int jj=0;jj<(1<<nInt);jj++) {
if (fabs(loC0[jj]-loC1[jj])>1.0e-8)
Expand Down Expand Up @@ -1956,15 +1956,15 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
if (el0[2]>0.0)
up0=bound0;
else
lo0=CoinMax(0.0,bound0);
lo0=std::max(0.0,bound0);
double rhs1 =effectiveRhs[k]-el1[0]*value0;
double lo1=0.0;
double up1=1.0e30;
double bound1=rhs1/el1[2];
if (el1[2]>0.0)
up1=bound1;
else
lo1=CoinMax(0.0,bound1);
lo1=std::max(0.0,bound1);
if (fabs(lo0-lo1)>1.0e-8||
fabs(up0-up1)>1.0e-8*(1.0+fabs(up1))) {
if (lo0>lo1+1.0e-8) {
Expand Down Expand Up @@ -2051,7 +2051,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
if (el0[2]>0.0)
up0=bound0;
else
lo0=CoinMax(0.0,bound0);
lo0=std::max(0.0,bound0);
double rhs1 =effectiveRhs[k]-el1[0]*value0
-el1[1]*value1;
double lo1=0.0;
Expand All @@ -2060,7 +2060,7 @@ void CglDuplicateRow::generateCuts4(const OsiSolverInterface & si, OsiCuts & cs,
if (el1[2]>0.0)
up1=bound1;
else
lo1=CoinMax(0.0,bound1);
lo1=std::max(0.0,bound1);
if (fabs(lo0-lo1)>1.0e-8||
fabs(up0-up1)>1.0e-8*(1.0+fabs(up1))) {
if (lo0>lo1+1.0e-8) {
Expand Down Expand Up @@ -2419,10 +2419,10 @@ static int outDupsEtc(int numberIntegers, int numberCliques, int * statusClique,
if (iValue<numberIntegers)
break;
if (cliqueType[kClique]=='E') {
iLowest = CoinMin(iLowest,kClique);
iLowest = std::min(iLowest,kClique);
type='E';
} else if (type=='S') {
iLowest = CoinMin(iLowest,kClique);
iLowest = std::min(iLowest,kClique);
}
}
if (jClique>jFirst) {
Expand Down Expand Up @@ -2730,10 +2730,10 @@ static int outDupsEtc(int numberIntegers, int numberCliques, int * statusClique,
if (iValue<numberIntegers)
break;
if (cliqueType[kClique]=='E') {
iLowest = CoinMin(iLowest,kClique);
iLowest = std::min(iLowest,kClique);
type='E';
} else if (type=='S') {
iLowest = CoinMin(iLowest,kClique);
iLowest = std::min(iLowest,kClique);
}
}
if (jClique>jFirst) {
Expand Down Expand Up @@ -2863,8 +2863,8 @@ static int outDupsEtc(int numberIntegers, int numberCliques, int * statusClique,
printf("\n");
}
nOut++;
used[iClique]=CoinMin(used[iClique],kClique);;
used[kClique]=CoinMin(used[kClique],iClique);;
used[iClique]=std::min(used[iClique],kClique);;
used[kClique]=std::min(used[kClique],iClique);;
// But need to look at type
// when might be able to fix variables
if (cliqueType[kClique]=='E') {
Expand Down Expand Up @@ -3053,7 +3053,7 @@ void CglDuplicateRow::generateCuts8(const OsiSolverInterface & si, OsiCuts & cs,
}
delete[] whichP;
int * dups = new int [2*numberCliques];
int * fixed = new int[CoinMax(numberIntegers,numberCliques)];
int * fixed = new int[std::max(numberIntegers,numberCliques)];
memset(fixed,0,numberIntegers*sizeof(int));
outDupsEtc(numberIntegers, numberCliques, dups,
cliqueStart, cliqueType, entry, fixed, printit ? 2 : 0);
Expand Down Expand Up @@ -3263,7 +3263,7 @@ CglDuplicateRow::refreshSolver(OsiSolverInterface * solver)
}
}
if (good) {
lower_[iRow] = static_cast<int> (CoinMax(0.0,ceil(rowLower[iRow])));
lower_[iRow] = static_cast<int> (std::max(0.0,ceil(rowLower[iRow])));
if (iRhs>=lower_[iRow]) {
rhs_[iRow]=iRhs;
//numberGood++;
Expand Down
6 changes: 3 additions & 3 deletions src/CglFlowCover/CglFlowCover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -995,16 +995,16 @@ CglFlowCover::generateOneFlowCut( const OsiSolverInterface & si,
}

/* Get ml */
double ml = CoinMin(sum, lambda);
double ml = std::min(sum, lambda);
if(CGLFLOW_DEBUG) {
// sum = sum_{i in C+\C++} m_i + sum_{i in L--} m_i = m. Page 15.
std::cout << "ml = CoinMin(m, lambda) = CoinMin(" << sum << ", " << lambda << ") =" << ml << std::endl;
std::cout << "ml = std::min(m, lambda) = std::min(" << sum << ", " << lambda << ") =" << ml << std::endl;
}
/* rho_i = max[0, m_i - (minPlsM - lamda) - ml */
if (t < index ) { /* rho exits only for t <= index-1 */
value = (minPlsM - lambda) + ml;
for (i = t; i < index; ++i) {
rho[i] = CoinMax(0.0, mt[i] - value);
rho[i] = std::max(0.0, mt[i] - value);
if(CGLFLOW_DEBUG) {
std::cout << "rho[" << std::setw(5) << i << "]=" << std::setw(20) << rho[i] << std::endl;
}
Expand Down
8 changes: 4 additions & 4 deletions src/CglGMI/CglGMI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,8 @@ bool CglGMI::checkDynamism(const double* cutElem, const int* cutIndex,
for (int i = 0; i < cutNz; ++i) {
if (!isZero(cutElem[i])) {
val = fabs(cutElem[i]);
min = CoinMin(min, val);
max = CoinMax(max, val);
min = std::min(min, val);
max = std::max(max, val);
}
}
if (max > min*param.getMAXDYN()) {
Expand Down Expand Up @@ -821,7 +821,7 @@ bool CglGMI::scaleCut(double* cutElem, int* cutIndex, int cutNz,
double max = fabs(cutRhs);
for (int i = 0; i < cutNz; ++i) {
if (!isZero(cutElem[i])) {
max = CoinMax(max, fabs(cutElem[i]));
max = std::max(max, fabs(cutElem[i]));
}
}
if (max < param.getEPS() || max > param.getMAXDYN()) {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ void CglGMI::generateCuts(OsiCuts &cs)
for (int i = 0; i < ncol; ++i) {
// j is the variable which is basic in row i
if ((cstat[i] == 1) && (isInteger[i])) {
if (CoinMin(aboveInteger(xlp[i]),
if (std::min(aboveInteger(xlp[i]),
1-aboveInteger(xlp[i])) > param.getAway()) {
listFracBasic[numFracBasic] = i;
numFracBasic++;
Expand Down
Loading

0 comments on commit 4dd6395

Please sign in to comment.