Skip to content

Commit

Permalink
Small code improvement in solver_utils.cpp (#1824)
Browse files Browse the repository at this point in the history
* Small code improvement in solver_utils.cpp

* Simplify a bit more
  • Loading branch information
flomnes authored Dec 13, 2023
1 parent e004c82 commit 21a61b3
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/solver/simulation/solver_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21a61b3

Please sign in to comment.