From 5008ca07b0b9a190104c43462a34ded04dcded6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Apitzsch?= Date: Fri, 16 Aug 2024 14:40:34 +0200 Subject: [PATCH] Replace CoinAbs by std::abs --- src/Attic/CbcSolver.cpp | 2 +- src/Attic/unitTestClp.cpp | 2 +- src/CbcHeuristic.cpp | 2 +- src/CbcModel.cpp | 16 ++++++++-------- src/CbcNode.cpp | 4 ++-- src/CbcSolver.cpp | 2 +- src/unitTestClp.cpp | 2 +- test/gamsTest.cpp | 40 +++++++++++++++++++-------------------- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Attic/CbcSolver.cpp b/src/Attic/CbcSolver.cpp index 0c48dea95..2fe012f67 100644 --- a/src/Attic/CbcSolver.cpp +++ b/src/Attic/CbcSolver.cpp @@ -13351,7 +13351,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/Attic/unitTestClp.cpp b/src/Attic/unitTestClp.cpp index f9d391408..d7915588a 100644 --- a/src/Attic/unitTestClp.cpp +++ b/src/Attic/unitTestClp.cpp @@ -796,7 +796,7 @@ int CbcClpUnitTest(const CbcModel &saveModel, const std::string &dirMiplibIn, */ model->setMinimumDrop(std::min(5.0e-2, fabs(model->getMinimizationObjValue()) * 1.0e-3 + 1.0e-4)); - if (CoinAbs(model->getMaximumCutPassesAtRoot()) <= 100) { + if (std::abs(model->getMaximumCutPassesAtRoot()) <= 100) { if (model->getNumCols() < 500) { model->setMaximumCutPassesAtRoot(-100); } else if (model->getNumCols() < 5000) { diff --git a/src/CbcHeuristic.cpp b/src/CbcHeuristic.cpp index 1d74c7f5d..b2edc5170 100644 --- a/src/CbcHeuristic.cpp +++ b/src/CbcHeuristic.cpp @@ -1135,7 +1135,7 @@ int CbcHeuristic::smallBranchAndBound(OsiSolverInterface *solver, int numberNode CbcStrategyDefaultSubTree strategy(model_, 1, 5, 1, 0); model.setStrategy(strategy); model.solver()->setIntParam(OsiMaxNumIterationHotStart, 10); - model.setMaximumCutPassesAtRoot(std::min(20, CoinAbs(model_->getMaximumCutPassesAtRoot()))); + model.setMaximumCutPassesAtRoot(std::min(20, std::abs(model_->getMaximumCutPassesAtRoot()))); model.setMaximumCutPasses(std::min(10, model_->getMaximumCutPasses())); // Set best solution (even if bad for this submodel) if (model_->bestSolution()) { diff --git a/src/CbcModel.cpp b/src/CbcModel.cpp index d007e5070..5fcab3e68 100644 --- a/src/CbcModel.cpp +++ b/src/CbcModel.cpp @@ -1734,7 +1734,7 @@ void CbcModel::AddIntegers() { #if CBC_USEFUL_PRINTING > 1 printf("INTA network %d rows out of %d\n", n, numberRows); #endif - if (CoinAbs(n) == numberRows) { + if (std::abs(n) == numberRows) { couldBeNetwork = true; for (int i = 0; i < numberRows; i++) { if (!possibleRow[i]) { @@ -8242,7 +8242,7 @@ int CbcModel::addCuts(CbcNode *node, CoinWarmStartBasis *&lastws) { bool canMissStuff = false; if ((specialOptions_ & 4096) == 0) { bool redoCuts = true; - if (CoinAbs(lastNumberCuts2_ - numberToAdd) < 5) { + if (std::abs(lastNumberCuts2_ - numberToAdd) < 5) { int numberToCheck = std::min(lastNumberCuts2_, numberToAdd); int i1 = 0; int i2 = 0; @@ -10210,7 +10210,7 @@ bool CbcModel::solveWithCuts(OsiCuts &cuts, int numberTries, CbcNode *node) } #ifdef JJF_ZERO } else if (currentPassNumber_ < - std::min(CoinAbs(maximumCutPassesAtRoot_), 8)) { + std::min(std::abs(maximumCutPassesAtRoot_), 8)) { if (whenCuts_ == 999999) { whenCuts_ = 8000008; maximumCutPasses_ = 1; @@ -10219,7 +10219,7 @@ bool CbcModel::solveWithCuts(OsiCuts &cuts, int numberTries, CbcNode *node) maximumCutPasses_ = 1; } } else if (currentPassNumber_ < - std::min(CoinAbs(maximumCutPassesAtRoot_), 50)) { + std::min(std::abs(maximumCutPassesAtRoot_), 50)) { if (whenCuts_ == 999999) { whenCuts_ = 8000008; maximumCutPasses_ = 1; @@ -10227,7 +10227,7 @@ bool CbcModel::solveWithCuts(OsiCuts &cuts, int numberTries, CbcNode *node) whenCuts_ = 10000006; maximumCutPasses_ = 1; } - } else if (currentPassNumber_ < CoinAbs(maximumCutPassesAtRoot_)) { + } else if (currentPassNumber_ < std::abs(maximumCutPassesAtRoot_)) { if (whenCuts_ == 999999) { whenCuts_ = 8000008; maximumCutPasses_ = 1; @@ -10251,7 +10251,7 @@ bool CbcModel::solveWithCuts(OsiCuts &cuts, int numberTries, CbcNode *node) // Objective changed #ifdef JJF_ZERO if (currentPassNumber_ < - std::min(CoinAbs(maximumCutPassesAtRoot_), 8)) { + std::min(std::abs(maximumCutPassesAtRoot_), 8)) { if (whenCuts_ == 999999) { whenCuts_ = 8000008; maximumCutPasses_ = 1; @@ -10260,7 +10260,7 @@ bool CbcModel::solveWithCuts(OsiCuts &cuts, int numberTries, CbcNode *node) maximumCutPasses_ = 1; } } else if (currentPassNumber_ < - std::min(CoinAbs(maximumCutPassesAtRoot_), 50)) { + std::min(std::abs(maximumCutPassesAtRoot_), 50)) { if (whenCuts_ == 999999) { whenCuts_ = 8000008; maximumCutPasses_ = 1; @@ -10270,7 +10270,7 @@ bool CbcModel::solveWithCuts(OsiCuts &cuts, int numberTries, CbcNode *node) } } else #endif - if (currentPassNumber_ < CoinAbs(maximumCutPassesAtRoot_)) { + if (currentPassNumber_ < std::abs(maximumCutPassesAtRoot_)) { if (whenCuts_ == 999999) { whenCuts_ = 8000008; if (!smallProblem) diff --git a/src/CbcNode.cpp b/src/CbcNode.cpp index 2a7c9a8b8..98e9c15d3 100644 --- a/src/CbcNode.cpp +++ b/src/CbcNode.cpp @@ -756,9 +756,9 @@ int CbcNode::chooseBranch(CbcModel *model, CbcNode *lastNode, int numberPassesLe } else { preferredWay = 1; } - priorityLevel = CoinAbs(priorityLevel); + priorityLevel = std::abs(priorityLevel); } else if (priorityLevel < 0) { - priorityLevel = CoinAbs(priorityLevel); + priorityLevel = std::abs(priorityLevel); if (targetValue == saveLower[iColumn]) { infeasibility = integerTolerance + 1.0e-12; preferredWay = -1; diff --git a/src/CbcSolver.cpp b/src/CbcSolver.cpp index c1ff879d8..81f7764ea 100644 --- a/src/CbcSolver.cpp +++ b/src/CbcSolver.cpp @@ -2214,7 +2214,7 @@ int CbcMain1(std::deque inputQueue, CbcModel &model, } else if (cbcParamCode == CbcParam::ODDWEXTMETHOD) { oddWExtMethod = iValue; } else if (cbcParamCode == CbcParam::LOGLEVEL) { - model_.messageHandler()->setLogLevel(CoinAbs(iValue)); + model_.messageHandler()->setLogLevel(std::abs(iValue)); } else if (cbcParamCode == CbcParam::MAXNODES) { model_.setIntParam(CbcModel::CbcMaxNumNode, iValue); } else if (cbcParamCode == CbcParam::MAXSOLS) { diff --git a/src/unitTestClp.cpp b/src/unitTestClp.cpp index 85586e82f..03de39b02 100644 --- a/src/unitTestClp.cpp +++ b/src/unitTestClp.cpp @@ -932,7 +932,7 @@ int CbcClpUnitTest(const CbcModel &saveModel, const std::string &dirMiplibIn, */ model->setMinimumDrop(std::min(5.0e-2, fabs(model->getMinimizationObjValue()) * 1.0e-3 + 1.0e-4)); - if (CoinAbs(model->getMaximumCutPassesAtRoot()) <= 100) { + if (std::abs(model->getMaximumCutPassesAtRoot()) <= 100) { if (model->getNumCols() < 500) { model->setMaximumCutPassesAtRoot(-100); } else if (model->getNumCols() < 5000) { diff --git a/test/gamsTest.cpp b/test/gamsTest.cpp index dde4abac5..57d02b56d 100644 --- a/test/gamsTest.cpp +++ b/test/gamsTest.cpp @@ -122,7 +122,7 @@ void sos1a(int &error_count, int &warning_count) std::cout << "Objective value model: " << model.getObjValue() << "\t solver: " << solver->getObjValue() << "\t expected: 0.72" << std::endl; - if (CoinAbs(model.getObjValue() - 0.72) > testtol || CoinAbs(solver->getObjValue() - 0.72) > testtol) { + if (std::abs(model.getObjValue() - 0.72) > testtol || std::abs(solver->getObjValue() - 0.72) > testtol) { std::cerr << "Error: Objective value incorrect." << std::endl; ++error_count; } @@ -130,21 +130,21 @@ void sos1a(int &error_count, int &warning_count) std::cout << "Primal value variable 0 in model: " << model.bestSolution()[0] << "\t in solver: " << solver->getColSolution()[0] << "\t expected: 0.8" << std::endl; - if (CoinAbs(model.bestSolution()[0] - 0.8) > testtol || CoinAbs(solver->getColSolution()[0] - 0.8) > testtol) { + if (std::abs(model.bestSolution()[0] - 0.8) > testtol || std::abs(solver->getColSolution()[0] - 0.8) > testtol) { std::cerr << "Error: Primal value incorrect." << std::endl; ++error_count; } std::cout << "Primal value variable 1 in model: " << model.bestSolution()[1] << "\t in solver: " << solver->getColSolution()[1] << "\t expected: 0.0" << std::endl; - if (CoinAbs(model.bestSolution()[1]) > testtol || CoinAbs(solver->getColSolution()[1]) > testtol) { + if (std::abs(model.bestSolution()[1]) > testtol || std::abs(solver->getColSolution()[1]) > testtol) { std::cerr << "Error: Primal value incorrect." << std::endl; ++error_count; } std::cout << "Primal value variable 2 in model: " << model.bestSolution()[2] << "\t in solver: " << solver->getColSolution()[2] << "\t expected: 0.0" << std::endl; - if (CoinAbs(model.bestSolution()[2]) > testtol || CoinAbs(solver->getColSolution()[2]) > testtol) { + if (std::abs(model.bestSolution()[2]) > testtol || std::abs(solver->getColSolution()[2]) > testtol) { std::cerr << "Error: Primal value incorrect." << std::endl; ++error_count; } @@ -319,7 +319,7 @@ void sos2a(int &error_count, int &warning_count) std::cout << "Objective value model: " << model.getObjValue() << "\t solver: " << solver->getObjValue() << "\t expected: " << optvalue << std::endl; - if (CoinAbs(model.getObjValue() - optvalue) > testtol || CoinAbs(solver->getObjValue() - optvalue) > testtol) { + if (std::abs(model.getObjValue() - optvalue) > testtol || std::abs(solver->getObjValue() - optvalue) > testtol) { std::cerr << "Error: Objective value incorrect." << std::endl; ++error_count; } @@ -328,7 +328,7 @@ void sos2a(int &error_count, int &warning_count) << "\t in solver: " << solver->getColSolution()[i] << "\t expected: " << primalval[i] << std::endl; - if (CoinAbs(model.bestSolution()[i] - primalval[i]) > testtol || CoinAbs(solver->getColSolution()[i] - primalval[i]) > testtol) { + if (std::abs(model.bestSolution()[i] - primalval[i]) > testtol || std::abs(solver->getColSolution()[i] - primalval[i]) > testtol) { std::cerr << "Error: Primal value incorrect." << std::endl; ++error_count; } @@ -338,7 +338,7 @@ void sos2a(int &error_count, int &warning_count) << "\t in solver: " << solver->getReducedCost()[i] << "\t expected: " << redcost[i] << std::endl; - if (CoinAbs(model.getReducedCost()[i] - redcost[i]) > testtol || CoinAbs(solver->getReducedCost()[i] - redcost[i]) > testtol) { + if (std::abs(model.getReducedCost()[i] - redcost[i]) > testtol || std::abs(solver->getReducedCost()[i] - redcost[i]) > testtol) { std::cerr << "Warning: Reduced cost incorrect." << std::endl; ++warning_count; } @@ -504,7 +504,7 @@ void semicon1(int &error_count, int &warning_count) std::cout << "Objective value in model: " << model.getObjValue() << "\t in solver: " << solver->getObjValue() << "\t expected: " << objval << std::endl; - if (CoinAbs(model.getObjValue() - objval) > testtol || CoinAbs(solver->getObjValue() - objval) > testtol) { + if (std::abs(model.getObjValue() - objval) > testtol || std::abs(solver->getObjValue() - objval) > testtol) { std::cerr << "Error: Objective value incorrect." << std::endl; ++error_count; } @@ -513,7 +513,7 @@ void semicon1(int &error_count, int &warning_count) << "\t in solver: " << solver->getColSolution()[i] << "\t expected: " << primalval[i] << std::endl; - if (CoinAbs(model.bestSolution()[i] - primalval[i]) > testtol || CoinAbs(solver->getColSolution()[i] - primalval[i]) > testtol) { + if (std::abs(model.bestSolution()[i] - primalval[i]) > testtol || std::abs(solver->getColSolution()[i] - primalval[i]) > testtol) { std::cerr << "Error: Primal value incorrect." << std::endl; ++error_count; } @@ -522,7 +522,7 @@ void semicon1(int &error_count, int &warning_count) << "\t in solver: " << solver->getReducedCost()[0] << "\t expected: " << redcost[0] << std::endl; - if (CoinAbs(model.getReducedCost()[0] - redcost[0]) > testtol || CoinAbs(solver->getReducedCost()[0] - redcost[0]) > testtol) { + if (std::abs(model.getReducedCost()[0] - redcost[0]) > testtol || std::abs(solver->getReducedCost()[0] - redcost[0]) > testtol) { std::cerr << "Warning: Reduced cost incorrect." << std::endl; ++warning_count; } @@ -530,21 +530,21 @@ void semicon1(int &error_count, int &warning_count) << "\t in solver: " << solver->getReducedCost()[3] << "\t expected: " << redcost[3] << std::endl; - if (CoinAbs(model.getReducedCost()[3] - redcost[3]) > testtol || CoinAbs(solver->getReducedCost()[3] - redcost[3]) > testtol) { + if (std::abs(model.getReducedCost()[3] - redcost[3]) > testtol || std::abs(solver->getReducedCost()[3] - redcost[3]) > testtol) { std::cerr << "Warning: Reduced cost incorrect." << std::endl; ++warning_count; } std::cout << "Reduced cost variable 1 plus - dual of row 0 in model: " << model.getReducedCost()[1] - model.getRowPrice()[0] << "\t expected: " << redcost[1] << std::endl; - if (CoinAbs(model.getReducedCost()[1] - model.getRowPrice()[0] - redcost[1]) > testtol) { + if (std::abs(model.getReducedCost()[1] - model.getRowPrice()[0] - redcost[1]) > testtol) { std::cerr << "Warning: Reduced cost or row margin incorrect." << std::endl; ++warning_count; } std::cout << "Reduced cost variable 2 plus + dual of row 1 in model: " << model.getReducedCost()[2] + model.getRowPrice()[1] << "\t expected: " << redcost[2] << std::endl; - if (CoinAbs(model.getReducedCost()[2] + model.getRowPrice()[1] - redcost[2]) > testtol) { + if (std::abs(model.getReducedCost()[2] + model.getRowPrice()[1] - redcost[2]) > testtol) { std::cerr << "Warning: Reduced cost or row margin incorrect." << std::endl; ++warning_count; } @@ -552,7 +552,7 @@ void semicon1(int &error_count, int &warning_count) std::cout << "Row 2 marginal (price) in model: " << model.getRowPrice()[2] << "\t in solver: " << solver->getRowPrice()[2] << "\t expected: " << row2marg << std::endl; - if (CoinAbs(model.getRowPrice()[2] - row2marg) > testtol || CoinAbs(solver->getRowPrice()[2] - row2marg) > testtol) { + if (std::abs(model.getRowPrice()[2] - row2marg) > testtol || std::abs(solver->getRowPrice()[2] - row2marg) > testtol) { std::cerr << "Warning: Row price incorrect." << std::endl; ++warning_count; } @@ -741,7 +741,7 @@ void semiint1(int &error_count, int &warning_count) std::cout << "Objective value in model: " << model.getObjValue() << "\t in solver: " << solver->getObjValue() << "\t expected: " << objval << std::endl; - if (CoinAbs(model.getObjValue() - objval) > testtol || CoinAbs(solver->getObjValue() - objval) > testtol) { + if (std::abs(model.getObjValue() - objval) > testtol || std::abs(solver->getObjValue() - objval) > testtol) { std::cerr << "Error: Objective value incorrect." << std::endl; ++error_count; } @@ -750,7 +750,7 @@ void semiint1(int &error_count, int &warning_count) << "\t in solver: " << solver->getColSolution()[i] << "\t expected: " << primalval[i] << std::endl; - if (CoinAbs(model.bestSolution()[i] - primalval[i]) > testtol || CoinAbs(solver->getColSolution()[i] - primalval[i]) > testtol) { + if (std::abs(model.bestSolution()[i] - primalval[i]) > testtol || std::abs(solver->getColSolution()[i] - primalval[i]) > testtol) { std::cerr << "Error: Primal value incorrect." << std::endl; ++error_count; } @@ -759,7 +759,7 @@ void semiint1(int &error_count, int &warning_count) << "\t in solver: " << solver->getReducedCost()[0] << "\t expected: " << redcost[0] << std::endl; - if (CoinAbs(model.getReducedCost()[0] - redcost[0]) > testtol || CoinAbs(solver->getReducedCost()[0] - redcost[0]) > testtol) { + if (std::abs(model.getReducedCost()[0] - redcost[0]) > testtol || std::abs(solver->getReducedCost()[0] - redcost[0]) > testtol) { std::cerr << "Warning: Reduced cost incorrect." << std::endl; ++warning_count; } @@ -767,14 +767,14 @@ void semiint1(int &error_count, int &warning_count) << "\t in solver: " << solver->getReducedCost()[3] << "\t expected: " << redcost[3] << std::endl; - if (CoinAbs(model.getReducedCost()[3] - redcost[3]) > testtol || CoinAbs(solver->getReducedCost()[3] - redcost[3]) > testtol) { + if (std::abs(model.getReducedCost()[3] - redcost[3]) > testtol || std::abs(solver->getReducedCost()[3] - redcost[3]) > testtol) { std::cerr << "Warning: Reduced cost incorrect." << std::endl; ++warning_count; } std::cout << "Row 2 marginal (price) in model: " << model.getRowPrice()[2] << "\t in solver: " << solver->getRowPrice()[2] << "\t expected: " << row2marg << std::endl; - if (CoinAbs(model.getRowPrice()[2] - row2marg) > testtol || CoinAbs(solver->getRowPrice()[2] - row2marg) > testtol) { + if (std::abs(model.getRowPrice()[2] - row2marg) > testtol || std::abs(solver->getRowPrice()[2] - row2marg) > testtol) { std::cerr << "Warning: Row price incorrect." << std::endl; ++warning_count; } @@ -782,7 +782,7 @@ void semiint1(int &error_count, int &warning_count) std::cout << "Row 2 marginal (price) in model: " << model.getRowPrice()[2] << "\t in solver: " << solver->getRowPrice()[2] << "\t expected: " << row2marg << std::endl; - if (CoinAbs(model.getRowPrice()[2] - row2marg) > testtol || CoinAbs(solver->getRowPrice()[2] - row2marg) > testtol) { + if (std::abs(model.getRowPrice()[2] - row2marg) > testtol || std::abs(solver->getRowPrice()[2] - row2marg) > testtol) { std::cerr << "Warning: Row price incorrect." << std::endl; ++warning_count; }