Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CoinAbs by std::abs #666

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Attic/CbcSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Attic/unitTestClp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/CbcHeuristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 8 additions & 8 deletions src/CbcModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -10219,15 +10219,15 @@ 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;
} else if (whenCuts_ == 999998) {
whenCuts_ = 10000006;
maximumCutPasses_ = 1;
}
} else if (currentPassNumber_ < CoinAbs(maximumCutPassesAtRoot_)) {
} else if (currentPassNumber_ < std::abs(maximumCutPassesAtRoot_)) {
if (whenCuts_ == 999999) {
whenCuts_ = 8000008;
maximumCutPasses_ = 1;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/CbcNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/CbcSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ int CbcMain1(std::deque<std::string> 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/unitTestClp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
40 changes: 20 additions & 20 deletions test/gamsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,29 @@ 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;
}

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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -522,37 +522,37 @@ 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;
}
std::cout << "Reduced cost variable " << 3 << " in model: " << model.getReducedCost()[3]
<< "\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;
}

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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -759,30 +759,30 @@ 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;
}
std::cout << "Reduced cost variable " << 3 << " in model: " << model.getReducedCost()[3]
<< "\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;
}

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;
}
Expand Down