From 21df56e1646789210d2391ff8386119fa065ff1c Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:32:46 +0100 Subject: [PATCH 1/2] Small code improvement in solver_utils.cpp --- src/solver/simulation/solver_utils.cpp | 37 +++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/solver/simulation/solver_utils.cpp b/src/solver/simulation/solver_utils.cpp index 32449af22b..fc425ee40c 100644 --- a/src/solver/simulation/solver_utils.cpp +++ b/src/solver/simulation/solver_utils.cpp @@ -16,14 +16,11 @@ 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(); + os << std::scientific; + os << std::setprecision(14); + return os; } namespace Antares::Solver::Simulation @@ -100,18 +97,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 From 59d7d89aa38f0c7ff2e5d9dcc0c11d097ae82ced Mon Sep 17 00:00:00 2001 From: Florian OMNES <26088210+flomnes@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:36:29 +0100 Subject: [PATCH 2/2] Simplify a bit more --- src/solver/simulation/solver_utils.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/solver/simulation/solver_utils.cpp b/src/solver/simulation/solver_utils.cpp index fc425ee40c..a9f539860e 100644 --- a/src/solver/simulation/solver_utils.cpp +++ b/src/solver/simulation/solver_utils.cpp @@ -18,9 +18,7 @@ static const std::string updateTimeFilename static std::ostream& toScientific(std::ostream& os) { - os << std::scientific; - os << std::setprecision(14); - return os; + return os << std::scientific << std::setprecision(14); } namespace Antares::Solver::Simulation