From 21a61b33ec2d681501e6a8033d6b80e3ae00607e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= <26088210+flomnes@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:05:57 +0100 Subject: [PATCH] Small code improvement in solver_utils.cpp (#1824) * Small code improvement in solver_utils.cpp * Simplify a bit more --- src/solver/simulation/solver_utils.cpp | 35 ++++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/solver/simulation/solver_utils.cpp b/src/solver/simulation/solver_utils.cpp index 32449af22b..a9f539860e 100644 --- a/src/solver/simulation/solver_utils.cpp +++ b/src/solver/simulation/solver_utils.cpp @@ -16,14 +16,9 @@ static const std::string optimizationTimeFilename static const std::string updateTimeFilename = std::string("optimization") + SEP + "update-durations.txt"; -static std::string to_scientific(const double d) +static std::ostream& toScientific(std::ostream& os) { - std::ostringstream stream; - stream << std::scientific; - stream << std::setprecision(14); - stream << d; - - return stream.str(); + return os << std::scientific << std::setprecision(14); } namespace Antares::Solver::Simulation @@ -100,18 +95,20 @@ void annualCostsStatistics::writeSystemCostToOutput(IResultWriter& writer) void annualCostsStatistics::writeCriterionCostsToOutput(IResultWriter& writer) const { - std::string buffer; - buffer += to_scientific(criterionCost1.costAverage) + "\n"; - buffer += to_scientific(criterionCost1.costStdDeviation) + "\n"; - buffer += to_scientific(criterionCost1.costMin) + "\n"; - buffer += to_scientific(criterionCost1.costMax) + "\n"; - - buffer += to_scientific(criterionCost2.costAverage) + "\n"; - buffer += to_scientific(criterionCost2.costStdDeviation) + "\n"; - buffer += to_scientific(criterionCost2.costMin) + "\n"; - buffer += to_scientific(criterionCost2.costMax) + "\n"; - - writer.addEntryFromBuffer(criterionsCostsFilename, buffer); + using std::endl; + std::ostringstream buffer; + buffer << toScientific + << criterionCost1.costAverage << endl + << criterionCost1.costStdDeviation << endl + << criterionCost1.costMin << endl + << criterionCost1.costMax << endl + << criterionCost2.costAverage << endl + << criterionCost2.costStdDeviation << endl + << criterionCost2.costMin << endl + << criterionCost2.costMax << endl; + + std::string s = buffer.str(); // TODO allow std::string&& in addEntryFromBuffer + writer.addEntryFromBuffer(criterionsCostsFilename, s); } void annualCostsStatistics::writeUpdateTimes(IResultWriter& writer) const