From 49f9784593d20721345f7f6a86e67c1a0ed0c0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Apitzsch?= Date: Fri, 16 Aug 2024 14:42:06 +0200 Subject: [PATCH] Replace CoinAbs by std::abs --- src/CbcOrClpParam.cpp | 2 +- src/ClpCholeskyBase.cpp | 54 ++++++------- src/ClpCholeskyDense.cpp | 26 +++--- src/ClpHelperFunctions.cpp | 4 +- src/ClpInterior.cpp | 20 ++--- src/ClpModel.cpp | 6 +- src/ClpPredictorCorrector.cpp | 146 +++++++++++++++++----------------- src/ClpSimplex.cpp | 2 +- src/ClpSolve.cpp | 2 +- 9 files changed, 131 insertions(+), 131 deletions(-) diff --git a/src/CbcOrClpParam.cpp b/src/CbcOrClpParam.cpp index eaa26c27..e0b3ba77 100644 --- a/src/CbcOrClpParam.cpp +++ b/src/CbcOrClpParam.cpp @@ -992,7 +992,7 @@ CbcOrClpParam::setIntParameterWithMessage(CbcModel &model, int value, int &retur switch (type_) { case CLP_PARAM_INT_LOGLEVEL: oldValue = model.messageHandler()->logLevel(); - model.messageHandler()->setLogLevel(CoinAbs(value)); + model.messageHandler()->setLogLevel(std::abs(value)); break; case CLP_PARAM_INT_SOLVERLOGLEVEL: oldValue = model.solver()->messageHandler()->logLevel(); diff --git a/src/ClpCholeskyBase.cpp b/src/ClpCholeskyBase.cpp index 4161c55b..68b53ca7 100644 --- a/src/ClpCholeskyBase.cpp +++ b/src/ClpCholeskyBase.cpp @@ -267,12 +267,12 @@ void ClpCholeskyBase::solveKKT(CoinWorkDouble *region1, CoinWorkDouble *region2, solve(array); int iRow; for (iRow = 0; iRow < numberTotal; iRow++) { - if (rowsDropped_[iRow] && CoinAbs(array[iRow]) > 1.0e-8) { + if (rowsDropped_[iRow] && std::abs(array[iRow]) > 1.0e-8) { COIN_DETAIL_PRINT(printf("row region1 %d dropped %g\n", iRow, array[iRow])); } } for (; iRow < numberRows_; iRow++) { - if (rowsDropped_[iRow] && CoinAbs(array[iRow]) > 1.0e-8) { + if (rowsDropped_[iRow] && std::abs(array[iRow]) > 1.0e-8) { COIN_DETAIL_PRINT(printf("row region2 %d dropped %g\n", iRow, array[iRow])); } } @@ -2813,13 +2813,13 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) } } diagonal_[iRow] = work[iRow]; - largest2 = std::max(largest2, CoinAbs(work[iRow])); + largest2 = std::max(largest2, std::abs(work[iRow])); work[iRow] = 0.0; int j; for (j = 0; j < number; j++) { int jRow = which[j]; put[j] = work[jRow]; - largest2 = std::max(largest2, CoinAbs(work[jRow])); + largest2 = std::max(largest2, std::abs(work[jRow])); work[jRow] = 0.0; } } else { @@ -3009,9 +3009,9 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) if (iOriginalRow < numberColumns) { iColumn = iOriginalRow; CoinWorkDouble value = diagonal[iColumn]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); diagonal_[iRow] = -value; CoinBigIndex start = columnStart[iColumn]; CoinBigIndex end = columnStart[iColumn] + columnLength[iColumn]; @@ -3020,7 +3020,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) kRow = permuteInverse_[kRow]; if (kRow > iRow) { work[kRow] = element[j]; - largest = std::max(largest, CoinAbs(element[j])); + largest = std::max(largest, std::abs(element[j])); } } } else { @@ -3028,9 +3028,9 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) } } else if (iOriginalRow < numberTotal) { CoinWorkDouble value = diagonal[iOriginalRow]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); } else { value = 1.0e100; } @@ -3048,7 +3048,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) int jNewRow = permuteInverse_[jRow]; if (jNewRow > iRow) { work[jNewRow] = elementByRow[j]; - largest = std::max(largest, CoinAbs(elementByRow[j])); + largest = std::max(largest, std::abs(elementByRow[j])); } } // slack - should it be permute @@ -3078,7 +3078,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) CoinBigIndex j; iColumn = iOriginalRow; CoinWorkDouble value = diagonal[iColumn]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; for (j = columnQuadraticStart[iColumn]; j < columnQuadraticStart[iColumn] + columnQuadraticLength[iColumn]; j++) { @@ -3090,7 +3090,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) value += quadraticElement[j]; } } - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); diagonal_[iRow] = -value; CoinBigIndex start = columnStart[iColumn]; CoinBigIndex end = columnStart[iColumn] + columnLength[iColumn]; @@ -3099,7 +3099,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) kRow = permuteInverse_[kRow]; if (kRow > iRow) { work[kRow] = element[j]; - largest = std::max(largest, CoinAbs(element[j])); + largest = std::max(largest, std::abs(element[j])); } } } else { @@ -3107,9 +3107,9 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) } } else if (iOriginalRow < numberTotal) { CoinWorkDouble value = diagonal[iOriginalRow]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); } else { value = 1.0e100; } @@ -3127,7 +3127,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) int jNewRow = permuteInverse_[jRow]; if (jNewRow > iRow) { work[jNewRow] = elementByRow[j]; - largest = std::max(largest, CoinAbs(elementByRow[j])); + largest = std::max(largest, std::abs(elementByRow[j])); } } // slack - should it be permute @@ -3152,9 +3152,9 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) longDouble *put = sparseFactor_ + choleskyStart_[iColumn]; CoinBigIndex *which = choleskyRow_ + indexStart_[iColumn]; CoinWorkDouble value = diagonal[iColumn]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); diagonal_[iColumn] = -value; CoinBigIndex start = columnStart[iColumn]; CoinBigIndex end = columnStart[iColumn] + columnLength[iColumn]; @@ -3162,7 +3162,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) //choleskyRow_[numberElements]=row[j]+numberTotal; //sparseFactor_[numberElements++]=element[j]; work[row[j] + numberTotal] = element[j]; - largest = std::max(largest, CoinAbs(element[j])); + largest = std::max(largest, std::abs(element[j])); } } else { diagonal_[iColumn] = -value; @@ -3187,7 +3187,7 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) int number = choleskyStart_[iColumn + 1] - choleskyStart_[iColumn]; CoinWorkDouble value = diagonal[iColumn]; CoinBigIndex j; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; for (j = columnQuadraticStart[iColumn]; j < columnQuadraticStart[iColumn] + columnQuadraticLength[iColumn]; j++) { @@ -3198,13 +3198,13 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) value += quadraticElement[j]; } } - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); diagonal_[iColumn] = -value; CoinBigIndex start = columnStart[iColumn]; CoinBigIndex end = columnStart[iColumn] + columnLength[iColumn]; for (j = start; j < end; j++) { work[row[j] + numberTotal] = element[j]; - largest = std::max(largest, CoinAbs(element[j])); + largest = std::max(largest, std::abs(element[j])); } for (j = 0; j < number; j++) { int jRow = which[j]; @@ -3226,9 +3226,9 @@ int ClpCholeskyBase::factorize(const CoinWorkDouble *diagonal, int *rowsDropped) longDouble *put = sparseFactor_ + choleskyStart_[iColumn]; CoinBigIndex *which = choleskyRow_ + indexStart_[iColumn]; CoinWorkDouble value = diagonal[iColumn]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); } else { value = 1.0e100; } @@ -3839,7 +3839,7 @@ void ClpCholeskyBase::solve(CoinWorkDouble *region, int type) int j; double largestO = 0.0; for (i = 0; i < numberRows_; i++) { - largestO = std::max(largestO, CoinAbs(regionX[i])); + largestO = std::max(largestO, std::abs(regionX[i])); } for (i = 0; i < numberRows_; i++) { int iRow = permute_[i]; @@ -3880,8 +3880,8 @@ void ClpCholeskyBase::solve(CoinWorkDouble *region, int type) double largest = 0.0; double largestV = 0.0; for (i = 0; i < numberRows_; i++) { - largest = std::max(largest, CoinAbs(region[i] - regionX[i])); - largestV = std::max(largestV, CoinAbs(region[i])); + largest = std::max(largest, std::abs(region[i] - regionX[i])); + largestV = std::max(largestV, std::abs(region[i])); } printf("largest difference %g, largest %g, largest original %g\n", largest, largestV, largestO); diff --git a/src/ClpCholeskyDense.cpp b/src/ClpCholeskyDense.cpp index 4379da01..a21107bd 100644 --- a/src/ClpCholeskyDense.cpp +++ b/src/ClpCholeskyDense.cpp @@ -224,9 +224,9 @@ int ClpCholeskyDense::factorize(const CoinWorkDouble *diagonal, int *rowsDropped } } for (int j = iRow + 1; j < numberRows_; j++) - largest2 = std::max(largest2, CoinAbs(work[j])); + largest2 = std::max(largest2, std::abs(work[j])); diagonal_[iRow] = diagonalValue; - largest2 = std::max(largest2, CoinAbs(diagonalValue)); + largest2 = std::max(largest2, std::abs(diagonalValue)); } else { /* dropped*/ diagonal_[iRow] = 1.0; @@ -301,9 +301,9 @@ int ClpCholeskyDense::factorize(const CoinWorkDouble *diagonal, int *rowsDropped if (!quadratic) { for (iColumn = 0; iColumn < numberColumns; iColumn++) { CoinWorkDouble value = diagonal[iColumn]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); diagonal_[iColumn] = -value; CoinBigIndex start = columnStart[iColumn]; CoinBigIndex end = columnStart[iColumn] + columnLength[iColumn]; @@ -311,7 +311,7 @@ int ClpCholeskyDense::factorize(const CoinWorkDouble *diagonal, int *rowsDropped /*choleskyRow_[numberElements]=row[j]+numberTotal;*/ /*sparseFactor_[numberElements++]=element[j];*/ work[row[j] + numberTotal] = element[j]; - largest = std::max(largest, CoinAbs(element[j])); + largest = std::max(largest, std::abs(element[j])); } } else { diagonal_[iColumn] = -value; @@ -328,7 +328,7 @@ int ClpCholeskyDense::factorize(const CoinWorkDouble *diagonal, int *rowsDropped for (iColumn = 0; iColumn < numberColumns; iColumn++) { CoinWorkDouble value = diagonal[iColumn]; CoinBigIndex j; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; for (j = columnQuadraticStart[iColumn]; j < columnQuadraticStart[iColumn] + columnQuadraticLength[iColumn]; j++) { @@ -339,13 +339,13 @@ int ClpCholeskyDense::factorize(const CoinWorkDouble *diagonal, int *rowsDropped value += quadraticElement[j]; } } - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); diagonal_[iColumn] = -value; CoinBigIndex start = columnStart[iColumn]; CoinBigIndex end = columnStart[iColumn] + columnLength[iColumn]; for (j = start; j < end; j++) { work[row[j] + numberTotal] = element[j]; - largest = std::max(largest, CoinAbs(element[j])); + largest = std::max(largest, std::abs(element[j])); } } else { value = 1.0e100; @@ -358,9 +358,9 @@ int ClpCholeskyDense::factorize(const CoinWorkDouble *diagonal, int *rowsDropped /* slacks*/ for (iColumn = numberColumns; iColumn < numberTotal; iColumn++) { CoinWorkDouble value = diagonal[iColumn]; - if (CoinAbs(value) > 1.0e-100) { + if (std::abs(value) > 1.0e-100) { value = 1.0 / value; - largest = std::max(largest, CoinAbs(value)); + largest = std::max(largest, std::abs(value)); } else { value = 1.0e100; } @@ -656,8 +656,8 @@ void ClpCholeskyDense::factorizePart2(int *rowsDropped) int numberDropped = 0; for (int i = 0; i < numberRows_; i++) { if (diagonal_[i]) { - largest = std::max(largest, CoinAbs(diagonal_[i])); - smallest = std::min(smallest, CoinAbs(diagonal_[i])); + largest = std::max(largest, std::abs(diagonal_[i])); + smallest = std::min(smallest, std::abs(diagonal_[i])); } else { numberDropped++; } @@ -1312,7 +1312,7 @@ void ClpCholeskyDense::solve(CoinWorkDouble *region) #ifdef CHOL_COMPARE if (numberRows_ < 200) { for (int i = 0; i < numberRows_; i++) { - assert(CoinAbs(region[i] - region2[i]) < 1.0e-3); + assert(std::abs(region[i] - region2[i]) < 1.0e-3); } delete[] region2; } diff --git a/src/ClpHelperFunctions.cpp b/src/ClpHelperFunctions.cpp index 61c01ff0..e89ef7fa 100644 --- a/src/ClpHelperFunctions.cpp +++ b/src/ClpHelperFunctions.cpp @@ -136,7 +136,7 @@ maximumAbsElement(const CoinWorkDouble *region, int size) int i; CoinWorkDouble maxValue = 0.0; for (i = 0; i < size; i++) - maxValue = std::max(maxValue, CoinAbs(region[i])); + maxValue = std::max(maxValue, std::abs(region[i])); return maxValue; } void setElements(CoinWorkDouble *region, int size, CoinWorkDouble value) @@ -222,7 +222,7 @@ void getNorms(const CoinWorkDouble *region, int size, CoinWorkDouble &norm1, Coi int i; for (i = 0; i < size; i++) { norm2 += region[i] * region[i]; - norm1 = std::max(norm1, CoinAbs(region[i])); + norm1 = std::max(norm1, std::abs(region[i])); } } #endif diff --git a/src/ClpInterior.cpp b/src/ClpInterior.cpp index 4780155b..65b4a66d 100644 --- a/src/ClpInterior.cpp +++ b/src/ClpInterior.cpp @@ -762,7 +762,7 @@ bool ClpInterior::sanityCheck() CoinWorkDouble fixTolerance = 1.1 * primalTolerance(); for (i = numberColumns_; i < numberColumns_ + numberRows_; i++) { CoinWorkDouble value; - value = CoinAbs(cost_[i]); + value = std::abs(cost_[i]); if (value > 1.0e50) { numberBad++; if (firstBad < 0) @@ -789,14 +789,14 @@ bool ClpInterior::sanityCheck() minimumGap = value; } if (lower_[i] > -1.0e100 && lower_[i]) { - value = CoinAbs(lower_[i]); + value = std::abs(lower_[i]); if (value > largestBound) largestBound = value; if (value < smallestBound) smallestBound = value; } if (upper_[i] < 1.0e100 && upper_[i]) { - value = CoinAbs(upper_[i]); + value = std::abs(upper_[i]); if (value > largestBound) largestBound = value; if (value < smallestBound) @@ -814,7 +814,7 @@ bool ClpInterior::sanityCheck() largestBound = 0.0; for (i = 0; i < numberColumns_; i++) { CoinWorkDouble value; - value = CoinAbs(cost_[i]); + value = std::abs(cost_[i]); if (value > 1.0e50) { numberBad++; if (firstBad < 0) @@ -841,14 +841,14 @@ bool ClpInterior::sanityCheck() minimumGap = value; } if (lower_[i] > -1.0e100 && lower_[i]) { - value = CoinAbs(lower_[i]); + value = std::abs(lower_[i]); if (value > largestBound) largestBound = value; if (value < smallestBound) smallestBound = value; } if (upper_[i] < 1.0e100 && upper_[i]) { - value = CoinAbs(upper_[i]); + value = std::abs(upper_[i]); if (value > largestBound) largestBound = value; if (value < smallestBound) @@ -1126,7 +1126,7 @@ void ClpInterior::fixFixed(bool reallyFix) if (fixedOrFree(i)) { if (columnActivity_[i] - columnLower_[i] < columnUpper_[i] - columnActivity_[i]) { CoinWorkDouble change = columnLower_[i] - columnActivity_[i]; - if (CoinAbs(change) < tolerance) { + if (std::abs(change) < tolerance) { if (reallyFix) columnUpper_[i] = columnLower_[i]; columnChange[i] = change; @@ -1134,7 +1134,7 @@ void ClpInterior::fixFixed(bool reallyFix) } } else { CoinWorkDouble change = columnUpper_[i] - columnActivity_[i]; - if (CoinAbs(change) < tolerance) { + if (std::abs(change) < tolerance) { if (reallyFix) columnLower_[i] = columnUpper_[i]; columnChange[i] = change; @@ -1170,14 +1170,14 @@ void ClpInterior::fixFixed(bool reallyFix) if (fixedOrFree(i + numberColumns_)) { if (rowActivity_[i] - rowLower_[i] < rowUpper_[i] - rowActivity_[i]) { CoinWorkDouble change = rowLower_[i] - rowActivity_[i]; - if (CoinAbs(change) < tolerance) { + if (std::abs(change) < tolerance) { if (reallyFix) rowUpper_[i] = rowLower_[i]; rowActivity_[i] = rowLower_[i]; } } else { CoinWorkDouble change = rowLower_[i] - rowActivity_[i]; - if (CoinAbs(change) < tolerance) { + if (std::abs(change) < tolerance) { if (reallyFix) rowLower_[i] = rowUpper_[i]; rowActivity_[i] = rowUpper_[i]; diff --git a/src/ClpModel.cpp b/src/ClpModel.cpp index dcdb64ff..e0a72b68 100644 --- a/src/ClpModel.cpp +++ b/src/ClpModel.cpp @@ -5092,7 +5092,7 @@ int ClpModel::findNetwork(char *rotate, double fractionNeeded) for (CoinBigIndex j = rowStart[iRow]; j < rowStart[iRow + 1]; j++) { iColumn = column[j]; int iCount = columnCount[iColumn]; - int absCount = CoinAbs(iCount); + int absCount = std::abs(iCount); if (absCount < 2) { merit = std::max(columnLength[iColumn] - absCount - 1, merit); if (elementByRow[j] == iCount) @@ -5139,7 +5139,7 @@ int ClpModel::findNetwork(char *rotate, double fractionNeeded) iColumn = column[j]; currentColumnCount[iColumn]++; int iCount = columnCount[iColumn]; - int absCount = CoinAbs(iCount); + int absCount = std::abs(iCount); if (!absCount) { columnCount[iColumn] = static_cast< char >(elementByRow[j] * multiplier); } else { @@ -5157,7 +5157,7 @@ int ClpModel::findNetwork(char *rotate, double fractionNeeded) #endif trueNetwork = true; for (iColumn = 0; iColumn < numberColumns_; iColumn++) { - if (CoinAbs(static_cast< int >(columnCount[iColumn])) == 1) { + if (std::abs(static_cast< int >(columnCount[iColumn])) == 1) { trueNetwork = false; break; } diff --git a/src/ClpPredictorCorrector.cpp b/src/ClpPredictorCorrector.cpp index 91c0df73..82107f14 100644 --- a/src/ClpPredictorCorrector.cpp +++ b/src/ClpPredictorCorrector.cpp @@ -306,15 +306,15 @@ int ClpPredictorCorrector::solve() CoinWorkDouble lastGood = bestObjectiveGap; if (gonePrimalFeasible_ && goneDualFeasible_) { CoinWorkDouble largestObjective; - if (CoinAbs(primalObjective_) > CoinAbs(dualObjective_)) { - largestObjective = CoinAbs(primalObjective_); + if (std::abs(primalObjective_) > std::abs(dualObjective_)) { + largestObjective = std::abs(primalObjective_); } else { - largestObjective = CoinAbs(dualObjective_); + largestObjective = std::abs(dualObjective_); } if (largestObjective < 1.0) { largestObjective = 1.0; } - gapO = CoinAbs(primalObjective_ - dualObjective_) / largestObjective; + gapO = std::abs(primalObjective_ - dualObjective_) / largestObjective; handler_->message(CLP_BARRIER_OBJECTIVE_GAP, messages_) << static_cast< double >(gapO) << CoinMessageEol; @@ -356,7 +356,7 @@ int ClpPredictorCorrector::solve() } //std::cout <<"could stop"< maximumRHSChange) { - maximumRHSChange = CoinAbs(newValue); + if (std::abs(newValue) > maximumRHSChange) { + maximumRHSChange = std::abs(newValue); } CoinWorkDouble result = newValue + oldValue; - if (CoinAbs(result) > maximumRHSError) { - maximumRHSError = CoinAbs(result); + if (std::abs(result) > maximumRHSError) { + maximumRHSError = std::abs(result); } newError[iRow] = result; } else { CoinWorkDouble newValue = newError[iRow]; CoinWorkDouble oldValue = errorRegion_[iRow]; - if (CoinAbs(newValue) > maximumRHSChange) { - maximumRHSChange = CoinAbs(newValue); + if (std::abs(newValue) > maximumRHSChange) { + maximumRHSChange = std::abs(newValue); } CoinWorkDouble result = newValue + oldValue; newError[iRow] = result; @@ -1843,21 +1843,21 @@ CoinWorkDouble ClpPredictorCorrector::findDirectionVector(const int phase) quadraticDjs(check, deltaX_, -1.0); for (iColumn = 0; iColumn < numberTotal; iColumn++) { check[iColumn] += deltaZ_[iColumn] - deltaW_[iColumn]; - if (CoinAbs(check[iColumn] - rhsC_[iColumn]) > 1.0e-3) + if (std::abs(check[iColumn] - rhsC_[iColumn]) > 1.0e-3) printf("rhsC %d %g %g\n", iColumn, check[iColumn], rhsC_[iColumn]); } // Check out rhsZ_ for (iColumn = 0; iColumn < numberTotal; iColumn++) { check[iColumn] += lowerSlack_[iColumn] * deltaZ_[iColumn] + zVec_[iColumn] * deltaSL_[iColumn]; - if (CoinAbs(check[iColumn] - rhsZ_[iColumn]) > 1.0e-3) + if (std::abs(check[iColumn] - rhsZ_[iColumn]) > 1.0e-3) printf("rhsZ %d %g %g\n", iColumn, check[iColumn], rhsZ_[iColumn]); } // Check out rhsW_ for (iColumn = 0; iColumn < numberTotal; iColumn++) { check[iColumn] += upperSlack_[iColumn] * deltaW_[iColumn] + wVec_[iColumn] * deltaSU_[iColumn]; - if (CoinAbs(check[iColumn] - rhsW_[iColumn]) > 1.0e-3) + if (std::abs(check[iColumn] - rhsW_[iColumn]) > 1.0e-3) printf("rhsW %d %g %g\n", iColumn, check[iColumn], rhsW_[iColumn]); } delete [] check; @@ -1932,7 +1932,7 @@ int ClpPredictorCorrector::createSolution() int jColumn = columnQuadratic[j]; CoinWorkDouble scaleJ = columnScale_[jColumn]; quadraticElement[j] *= scaleI * scaleJ; - objectiveNorm_ = std::max(objectiveNorm_, CoinAbs(quadraticElement[j])); + objectiveNorm_ = std::max(objectiveNorm_, std::abs(quadraticElement[j])); } } } else { @@ -1941,7 +1941,7 @@ int ClpPredictorCorrector::createSolution() for (CoinBigIndex j = columnQuadraticStart[iColumn]; j < columnQuadraticStart[iColumn] + columnQuadraticLength[iColumn]; j++) { quadraticElement[j] *= scale; - objectiveNorm_ = std::max(objectiveNorm_, CoinAbs(quadraticElement[j])); + objectiveNorm_ = std::max(objectiveNorm_, std::abs(quadraticElement[j])); } } } @@ -2206,7 +2206,7 @@ int ClpPredictorCorrector::createSolution() CoinWorkDouble elementValue = quadraticElement[j]; reducedCost += valueJ * elementValue; } - quadraticNorm = std::max(quadraticNorm, CoinAbs(reducedCost)); + quadraticNorm = std::max(quadraticNorm, std::abs(reducedCost)); } dj_[iColumn] = reducedCost; if (primalValue > lowerValue + largeGap && primalValue < upperValue - largeGap) { @@ -2339,14 +2339,14 @@ int ClpPredictorCorrector::createSolution() #if 0 if (solution_[0] > 0.0) { for (int i = 0; i < numberTotal; i++) - printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, CoinAbs(solution_[i]), - diagonal_[i], CoinAbs(dj_[i]), + printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, std::abs(solution_[i]), + diagonal_[i], std::abs(dj_[i]), lowerSlack_[i], zVec_[i], upperSlack_[i], wVec_[i]); } else { for (int i = 0; i < numberTotal; i++) - printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, CoinAbs(solution_[i]), - diagonal_[i], CoinAbs(dj_[i]), + printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, std::abs(solution_[i]), + diagonal_[i], std::abs(dj_[i]), upperSlack_[i], wVec_[i], lowerSlack_[i], zVec_[i] ); } @@ -2522,13 +2522,13 @@ void ClpPredictorCorrector::setupForSolve(const int phase) } #if 0 for (int i = 0; i < 3; i++) { - if (!CoinAbs(rhsZ_[i])) + if (!std::abs(rhsZ_[i])) rhsZ_[i] = 0.0; - if (!CoinAbs(rhsW_[i])) + if (!std::abs(rhsW_[i])) rhsW_[i] = 0.0; - if (!CoinAbs(rhsU_[i])) + if (!std::abs(rhsU_[i])) rhsU_[i] = 0.0; - if (!CoinAbs(rhsL_[i])) + if (!std::abs(rhsL_[i])) rhsL_[i] = 0.0; } if (solution_[0] > 0.0) { @@ -2576,33 +2576,33 @@ void ClpPredictorCorrector::setupForSolve(const int phase) } #if 0 for (int i = 0; i < numberTotal; i++) { - if (!CoinAbs(rhsZ_[i])) + if (!std::abs(rhsZ_[i])) rhsZ_[i] = 0.0; - if (!CoinAbs(rhsW_[i])) + if (!std::abs(rhsW_[i])) rhsW_[i] = 0.0; - if (!CoinAbs(rhsU_[i])) + if (!std::abs(rhsU_[i])) rhsU_[i] = 0.0; - if (!CoinAbs(rhsL_[i])) + if (!std::abs(rhsL_[i])) rhsL_[i] = 0.0; } if (solution_[0] > 0.0) { for (int i = 0; i < numberTotal; i++) - printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, CoinAbs(solution_[i]), - diagonal_[i], CoinAbs(dj_[i]), + printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, std::abs(solution_[i]), + diagonal_[i], std::abs(dj_[i]), lowerSlack_[i], zVec_[i], upperSlack_[i], wVec_[i]); for (int i = 0; i < numberTotal; i++) - printf("%d %.18g %.18g %.18g %.18g %.18g\n", i, CoinAbs(rhsC_[i]), + printf("%d %.18g %.18g %.18g %.18g %.18g\n", i, std::abs(rhsC_[i]), rhsZ_[i], rhsL_[i], rhsW_[i], rhsU_[i]); } else { for (int i = 0; i < numberTotal; i++) - printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, CoinAbs(solution_[i]), - diagonal_[i], CoinAbs(dj_[i]), + printf("%d %.18g %.18g %.18g %.18g %.18g %.18g %.18g\n", i, std::abs(solution_[i]), + diagonal_[i], std::abs(dj_[i]), upperSlack_[i], wVec_[i], lowerSlack_[i], zVec_[i] ); for (int i = 0; i < numberTotal; i++) - printf("%d %.18g %.18g %.18g %.18g %.18g\n", i, CoinAbs(rhsC_[i]), + printf("%d %.18g %.18g %.18g %.18g %.18g\n", i, std::abs(rhsC_[i]), rhsW_[i], rhsU_[i], rhsZ_[i], rhsL_[i]); } @@ -2887,7 +2887,7 @@ bool ClpPredictorCorrector::checkGoodMove(const bool doCorrector, //sumPerturbCost-=deltaX_[iColumn]; //deltaObjectiveDual -= deltaW_[iColumn] * upper_[iColumn]; //} - CoinWorkDouble change = CoinAbs(workArray_[iColumn] - deltaZ_[iColumn] + deltaW_[iColumn]); + CoinWorkDouble change = std::abs(workArray_[iColumn] - deltaZ_[iColumn] + deltaW_[iColumn]); error = std::max(change, error); } //deltaObjectivePrimal += cost_[iColumn] * deltaX_[iColumn]; @@ -3019,7 +3019,7 @@ bool ClpPredictorCorrector::checkGoodMove2(CoinWorkDouble move, CoinWorkDouble newInfeasibility = nextDj[iColumn] - newZ + newW + gammaTerm * (solution_[iColumn] + actualPrimalStep_ * deltaX_[iColumn]); maximumDualError = std::max(maximumDualError, newInfeasibility); - //if (CoinAbs(newInfeasibility)>std::max(2000.0*maximumDualError_,1.0e-2)) { + //if (std::abs(newInfeasibility)>std::max(2000.0*maximumDualError_,1.0e-2)) { //if (dualInfeasibility*newInfeasibility<0.0) { // printf("%d current %g next %g\n",iColumn,dualInfeasibility, // newInfeasibility); @@ -3084,7 +3084,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) freeMultiplier = 1.0e12; } freeMultiplier = 0.5 / freeMultiplier; - CoinWorkDouble condition = CoinAbs(cholesky_->choleskyCondition()); + CoinWorkDouble condition = std::abs(cholesky_->choleskyCondition()); bool caution; if ((condition < 1.0e10 && trueNorm < 1.0e12) || numberIterations_ < 20) { caution = false; @@ -3178,7 +3178,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) for (iRow = 0; iRow < numberRows_; iRow++) { CoinWorkDouble value = errorRegion_[iRow]; CoinWorkDouble valueNew = rhsFixRegion_[iRow]; - if (CoinAbs(value) < tol && CoinAbs(valueNew) > tol) { + if (std::abs(value) < tol && std::abs(valueNew) > tol) { printf("row %d old %g new %g\n", iRow, value, valueNew); goneInf = true; } @@ -3224,7 +3224,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) CoinWorkDouble sUpper = extra; CoinWorkDouble sLower = extra; CoinWorkDouble kill; - if (CoinAbs(newPrimal) > 1.0e4) { + if (std::abs(newPrimal) > 1.0e4) { kill = killTolerance * 1.0e-4 * newPrimal; } else { kill = killTolerance; @@ -3277,7 +3277,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) newSlack = lowerSlack_[iColumn] + actualPrimalStep_ * (oldPrimal - oldSlack + thisWeight - lower_[iColumn]); if (fakeOldBounds) newSlack = lowerSlack_[iColumn]; - CoinWorkDouble epsilon = CoinAbs(newSlack) * epsilonBase; + CoinWorkDouble epsilon = std::abs(newSlack) * epsilonBase; epsilon = std::min(epsilon, 1.0e-5); //epsilon=1.0e-14; //make sure reasonable @@ -3292,7 +3292,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) } else { larger = feasibleSlack; } - if (CoinAbs(feasibleSlack - newSlack) < 1.0e-6 * larger) { + if (std::abs(feasibleSlack - newSlack) < 1.0e-6 * larger) { newSlack = feasibleSlack; } } @@ -3303,8 +3303,8 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) if (newSlack < smallerSlack) { smallerSlack = newSlack; } - lowerBoundInfeasibility = CoinAbs(newPrimal - lowerSlack_[iColumn] - lower_[iColumn]); - if (lowerSlack_[iColumn] <= kill * killFactor && CoinAbs(newPrimal - lower_[iColumn]) <= kill * killFactor) { + lowerBoundInfeasibility = std::abs(newPrimal - lowerSlack_[iColumn] - lower_[iColumn]); + if (lowerSlack_[iColumn] <= kill * killFactor && std::abs(newPrimal - lower_[iColumn]) <= kill * killFactor) { CoinWorkDouble step = std::min(actualPrimalStep_ * 1.1, 1.0); CoinWorkDouble newPrimal2 = solution_[iColumn] + step * thisWeight; if (newPrimal2 < newPrimal && dj_[iColumn] > 1.0e-5 && numberIterations_ > 50 - 40) { @@ -3313,7 +3313,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) //printf("fixing %d to lower\n",iColumn); } } - if (lowerSlack_[iColumn] <= kill && CoinAbs(newPrimal - lower_[iColumn]) <= kill) { + if (lowerSlack_[iColumn] <= kill && std::abs(newPrimal - lower_[iColumn]) <= kill) { //may be better to leave at value? newPrimal = lower_[iColumn]; lowerSlack_[iColumn] = 0.0; @@ -3329,7 +3329,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) newSlack = upperSlack_[iColumn] + actualPrimalStep_ * (-oldPrimal - oldSlack - thisWeight + upper_[iColumn]); if (fakeOldBounds) newSlack = upperSlack_[iColumn]; - CoinWorkDouble epsilon = CoinAbs(newSlack) * epsilonBase; + CoinWorkDouble epsilon = std::abs(newSlack) * epsilonBase; epsilon = std::min(epsilon, 1.0e-5); //make sure reasonable //epsilon=1.0e-14; @@ -3344,7 +3344,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) } else { larger = feasibleSlack; } - if (CoinAbs(feasibleSlack - newSlack) < 1.0e-6 * larger) { + if (std::abs(feasibleSlack - newSlack) < 1.0e-6 * larger) { newSlack = feasibleSlack; } } @@ -3355,8 +3355,8 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) if (newSlack < smallerSlack) { smallerSlack = newSlack; } - upperBoundInfeasibility = CoinAbs(newPrimal + upperSlack_[iColumn] - upper_[iColumn]); - if (upperSlack_[iColumn] <= kill * killFactor && CoinAbs(newPrimal - upper_[iColumn]) <= kill * killFactor) { + upperBoundInfeasibility = std::abs(newPrimal + upperSlack_[iColumn] - upper_[iColumn]); + if (upperSlack_[iColumn] <= kill * killFactor && std::abs(newPrimal - upper_[iColumn]) <= kill * killFactor) { CoinWorkDouble step = std::min(actualPrimalStep_ * 1.1, 1.0); CoinWorkDouble newPrimal2 = solution_[iColumn] + step * thisWeight; if (newPrimal2 > newPrimal && dj_[iColumn] < -1.0e-5 && numberIterations_ > 50 - 40) { @@ -3365,7 +3365,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) //printf("fixing %d to upper\n",iColumn); } } - if (upperSlack_[iColumn] <= kill && CoinAbs(newPrimal - upper_[iColumn]) <= kill) { + if (upperSlack_[iColumn] <= kill && std::abs(newPrimal - upper_[iColumn]) <= kill) { //may be better to leave at value? newPrimal = upper_[iColumn]; upperSlack_[iColumn] = 0.0; @@ -3387,8 +3387,8 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) } #endif solution_[iColumn] = newPrimal; - if (CoinAbs(newPrimal) > solutionNorm) { - solutionNorm = CoinAbs(newPrimal); + if (std::abs(newPrimal) > solutionNorm) { + solutionNorm = std::abs(newPrimal); } if (!thisKilled) { CoinWorkDouble gammaTerm = gamma2; @@ -3397,7 +3397,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) quadraticOffset += newPrimal * newPrimal * primalR_[iColumn]; } CoinWorkDouble dualInfeasibility = reducedCost - zVec_[iColumn] + wVec_[iColumn] + gammaTerm * newPrimal; - if (CoinAbs(dualInfeasibility) > dualTolerance) { + if (std::abs(dualInfeasibility) > dualTolerance) { #if 0 if (dualInfeasibility > 0.0) { // To improve we could reduce t and/or increase z @@ -3469,7 +3469,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) if (upperBoundInfeasibility > maximumBoundInfeasibility) { maximumBoundInfeasibility = upperBoundInfeasibility; } - dualInfeasibility = CoinAbs(dualInfeasibility); + dualInfeasibility = std::abs(dualInfeasibility); if (dualInfeasibility > maximumDualError) { //printf("bad dual %d %g\n",iColumn, // reducedCost-zVec_[iColumn]+wVec_[iColumn]+gammaTerm*newPrimal); @@ -3560,7 +3560,7 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) if (largestDiagonal > 1.0e17 * smallestDiagonal) { CoinWorkDouble killValue = largestDiagonal * 1.0e-17; for (int iColumn = 0; iColumn < numberTotal; iColumn++) { - if (CoinAbs(diagonal_[iColumn]) < killValue) + if (std::abs(diagonal_[iColumn]) < killValue) diagonal_[iolumn] = 0.0; } } @@ -3613,12 +3613,12 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) for (iRow = 0; iRow < numberRows_; iRow++) { CoinWorkDouble value = errorRegion_[iRow]; if (!dropped[iRow]) { - if (CoinAbs(value) > maximumRHSError1) { - maximumRHSError1 = CoinAbs(value); + if (std::abs(value) > maximumRHSError1) { + maximumRHSError1 = std::abs(value); } } else { - if (CoinAbs(value) > maximumRHSError2) { - maximumRHSError2 = CoinAbs(value); + if (std::abs(value) > maximumRHSError2) { + maximumRHSError2 = std::abs(value); } primalOffset += value * dualArray[iRow]; } @@ -3663,8 +3663,8 @@ int ClpPredictorCorrector::updateSolution(CoinWorkDouble /*nextGap*/) primalFeasible = false; #endif // relax dual test if obj big and gap smallish - CoinWorkDouble gap = CoinAbs(primalObjective_ - dualObjective_); - CoinWorkDouble sizeObj = std::min(CoinAbs(primalObjective_), CoinAbs(dualObjective_)) + 1.0e-50; + CoinWorkDouble gap = std::abs(primalObjective_ - dualObjective_); + CoinWorkDouble sizeObj = std::min(std::abs(primalObjective_), std::abs(dualObjective_)) + 1.0e-50; //printf("gap %g sizeObj %g ratio %g comp %g\n", // gap,sizeObj,gap/sizeObj,complementarityGap_); if (numberIterations_ > 100 && gap / sizeObj < 1.0e-9 && complementarityGap_ < 1.0e-7 * sizeObj) @@ -3805,7 +3805,7 @@ void ClpPredictorCorrector::debugMove(int /*phase*/, //if (zValue > dualTolerance) { // dualObjectiveValue += lower_[iColumn] * zVec_[iColumn]; //} - lowerBoundInfeasibility = CoinAbs(newPrimal - newSlack - lower_[iColumn]); + lowerBoundInfeasibility = std::abs(newPrimal - newSlack - lower_[iColumn]); //newGap += newSlack * zValue; } if (upperBound(iColumn)) { @@ -3814,11 +3814,11 @@ void ClpPredictorCorrector::debugMove(int /*phase*/, //if (wValue > dualTolerance) { // dualObjectiveValue -= upper_[iColumn] * wVec_[iColumn]; //} - upperBoundInfeasibility = CoinAbs(newPrimal + newSlack - upper_[iColumn]); + upperBoundInfeasibility = std::abs(newPrimal + newSlack - upper_[iColumn]); //newGap += newSlack * wValue; } - if (CoinAbs(newPrimal) > solutionNorm) { - solutionNorm = CoinAbs(newPrimal); + if (std::abs(newPrimal) > solutionNorm) { + solutionNorm = std::abs(newPrimal); } CoinWorkDouble gammaTerm = gamma2; if (primalR_) { @@ -3826,7 +3826,7 @@ void ClpPredictorCorrector::debugMove(int /*phase*/, //quadraticOffset += newPrimal * newPrimal * primalR_[iColumn]; } CoinWorkDouble dualInfeasibility = reducedCost - zValue + wValue + gammaTerm * newPrimal; - //if (CoinAbs(dualInfeasibility) > dualTolerance) { + //if (std::abs(dualInfeasibility) > dualTolerance) { // dualFake += newPrimal * dualInfeasibility; //} if (lowerBoundInfeasibility > maximumBoundInfeasibility) { @@ -3835,7 +3835,7 @@ void ClpPredictorCorrector::debugMove(int /*phase*/, if (upperBoundInfeasibility > maximumBoundInfeasibility) { maximumBoundInfeasibility = upperBoundInfeasibility; } - dualInfeasibility = CoinAbs(dualInfeasibility); + dualInfeasibility = std::abs(dualInfeasibility); if (dualInfeasibility > maximumDualError) { //printf("bad dual %d %g\n",iColumn, // reducedCost-zVec_[iColumn]+wVec_[iColumn]+gammaTerm*newPrimal); @@ -3884,12 +3884,12 @@ void ClpPredictorCorrector::debugMove(int /*phase*/, for (iRow = 0; iRow < numberRows_; iRow++) { CoinWorkDouble value = errorRegionNew[iRow]; if (!dropped[iRow]) { - if (CoinAbs(value) > maximumRHSError1) { - maximumRHSError1 = CoinAbs(value); + if (std::abs(value) > maximumRHSError1) { + maximumRHSError1 = std::abs(value); } } else { - if (CoinAbs(value) > maximumRHSError2) { - maximumRHSError2 = CoinAbs(value); + if (std::abs(value) > maximumRHSError2) { + maximumRHSError2 = std::abs(value); } //primalOffset += value * dualNew[iRow]; } diff --git a/src/ClpSimplex.cpp b/src/ClpSimplex.cpp index 1d007fc2..8cc1c716 100644 --- a/src/ClpSimplex.cpp +++ b/src/ClpSimplex.cpp @@ -9102,7 +9102,7 @@ int ClpSimplex::pivot() } rowArray_[0]->setNumElements(0); // check incoming - assert(fabs(dj_[sequenceIn_]) < 1.0e-6 || CoinAbs(solveType_) == 2); + assert(fabs(dj_[sequenceIn_]) < 1.0e-6 || std::abs(solveType_) == 2); } // if stable replace in basis diff --git a/src/ClpSolve.cpp b/src/ClpSolve.cpp index 7130830f..29516c1b 100644 --- a/src/ClpSolve.cpp +++ b/src/ClpSolve.cpp @@ -325,7 +325,7 @@ solveWithVolume(ClpSimplex *model, int numberPasses, int doIdiot) for (i = 0; i < dsize; ++i) { switch (sense[i]) { case 'E': - avg += CoinAbs(volprob.viol[i]); + avg += std::abs(volprob.viol[i]); break; case 'L': if (volprob.viol[i] < 0)