From f6572004bddef66ee0b3b71f0da3d96570ed3657 Mon Sep 17 00:00:00 2001 From: John Forrest Date: Tue, 10 Sep 2024 16:34:33 +0100 Subject: [PATCH] more accuracy in printing objective value --- src/CbcHeuristicFPump.cpp | 22 +++++++++++----------- src/CbcMessage.cpp | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/CbcHeuristicFPump.cpp b/src/CbcHeuristicFPump.cpp index 43c973c6c..cee067ed1 100644 --- a/src/CbcHeuristicFPump.cpp +++ b/src/CbcHeuristicFPump.cpp @@ -886,7 +886,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, for (i = 0; i < numberColumns; i++) newSolutionValue += saveObjective[i] * newSolution[i]; newSolutionValue *= direction; - sprintf(pumpPrint, "Solution found of %g", trueObjValue(newSolutionValue)); + sprintf(pumpPrint, "Solution found of %.13g", trueObjValue(newSolutionValue)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint << CoinMessageEol; @@ -981,7 +981,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, for (i = 0; i < numberColumns; i++) { newSolutionValue += saveObjective[i] * newSolution[i]; } - sprintf(pumpPrint, "Relaxing continuous gives %g", + sprintf(pumpPrint, "Relaxing continuous gives %.13g", model_->trueObjValue(newSolutionValue)); //#define DEBUG_BEST #ifdef DEBUG_BEST @@ -1102,7 +1102,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, if (numberSolutions >= maxSolutions) exitAll = true; if (general && saveValue != newSolutionValue) { - sprintf(pumpPrint, "Cleaned solution of %g", trueObjValue(solutionValue)); + sprintf(pumpPrint, "Cleaned solution of %.13g", trueObjValue(solutionValue)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint << CoinMessageEol; @@ -1116,7 +1116,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, << CoinMessageEol; } } else { - sprintf(pumpPrint, "After further testing solution no better than previous of %g", trueObjValue(solutionValue)); + sprintf(pumpPrint, "After further testing solution no better than previous of %.13g", trueObjValue(solutionValue)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint << CoinMessageEol; @@ -1349,7 +1349,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, for (i = 0; i < numberColumns; i++) newSolutionValue += saveObjective[i] * newSolution[i]; newSolutionValue *= direction; - sprintf(pumpPrint, "Intermediate solution found of %g", trueObjValue(newSolutionValue)); + sprintf(pumpPrint, "Intermediate solution found of %.13g", trueObjValue(newSolutionValue)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint << CoinMessageEol; @@ -1951,7 +1951,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, // see if rounding worked! if (roundingObjective < solutionValue) { if (roundingObjective < solutionValue - 1.0e-6 * fabs(roundingObjective)) { - sprintf(pumpPrint, "Rounding solution of %g is better than previous of %g\n", + sprintf(pumpPrint, "Rounding solution of %.13g is better than previous of %.13g\n", trueObjValue(roundingObjective), trueObjValue(solutionValue)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint @@ -2158,7 +2158,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, } bool gotSolution = false; if (returnCode && newSolutionValue < saveValue) { - sprintf(pumpPrint, "Mini branch and bound improved solution from %g to %g (%.2f seconds)", + sprintf(pumpPrint, "Mini branch and bound improved solution from %.13g to %.13g (%.2f seconds)", trueObjValue(saveValue), trueObjValue(newSolutionValue), model_->getCurrentSeconds()); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint @@ -2266,7 +2266,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, newSumInfeas); } #endif - sprintf(pumpPrint, "Freeing continuous variables gives a solution of %g", trueObjValue(value)); + sprintf(pumpPrint, "Freeing continuous variables gives a solution of %.13g", trueObjValue(value)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint << CoinMessageEol; @@ -2307,7 +2307,7 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, if (newSolver->isProvenOptimal()) { double value = newSolver->getObjValue() * newSolver->getObjSenseInCbc(); if (value < saveValue) { - sprintf(pumpPrint, "Freeing continuous variables gives a solution of %g", trueObjValue(value)); + sprintf(pumpPrint, "Freeing continuous variables gives a solution of %.13g", trueObjValue(value)); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) << pumpPrint << CoinMessageEol; @@ -2455,10 +2455,10 @@ int CbcHeuristicFPump::solutionInternal(double &solutionValue, sprintf(pumpPrint, "After %.2f seconds - Feasibility pump exiting - took %.2f seconds", model_->getCurrentSeconds(), CoinCpuTime() - time1); else if (numberSolutions < maxSolutions) - sprintf(pumpPrint, "After %.2f seconds - Feasibility pump exiting with objective of %g - took %.2f seconds", + sprintf(pumpPrint, "After %.2f seconds - Feasibility pump exiting with objective of %.13g - took %.2f seconds", model_->getCurrentSeconds(), trueObjValue(solutionValue), CoinCpuTime() - time1); else - sprintf(pumpPrint, "After %.2f seconds - Feasibility pump exiting with objective of %g (stopping after %d solutions) - took %.2f seconds", + sprintf(pumpPrint, "After %.2f seconds - Feasibility pump exiting with objective of %.13g (stopping after %d solutions) - took %.2f seconds", model_->getCurrentSeconds(), trueObjValue(solutionValue), numberSolutions, CoinCpuTime() - time1); model_->messageHandler()->message(CBC_FPUMP1, model_->messages()) diff --git a/src/CbcMessage.cpp b/src/CbcMessage.cpp index 5ff2857c0..05d726c8a 100644 --- a/src/CbcMessage.cpp +++ b/src/CbcMessage.cpp @@ -39,9 +39,9 @@ static Cbc_message us_english[] = { #endif { CBC_GAP, 11, 1, "Exiting as integer gap of %g less than %g or %g%%" }, #ifndef CBC_MANY_NODE_COUNTS - { CBC_ROUNDING, 12, 1, "Integer solution of %g found by %s after %d iterations and %d nodes (%.2f seconds)" }, + { CBC_ROUNDING, 12, 1, "Integer solution of %.13g found by %s after %d iterations and %d nodes (%.2f seconds)" }, #else - { CBC_ROUNDING, 12, 1, "Integer solution of %g found by %s after %ld iterations and %ld nodes (%.2f seconds)" }, + { CBC_ROUNDING, 12, 1, "Integer solution of %.13g found by %s after %ld iterations and %ld nodes (%.2f seconds)" }, #endif { CBC_ROOT, 13, 1, "At root node, %d cuts changed objective from %g to %g in %d passes" }, { CBC_GENERATOR, 14, 1, "Cut generator %d (%s) - %d row cuts average %.1f elements, %d column cuts (%d active) %? in %.3f seconds - new frequency is %d" },