Skip to content

Commit

Permalink
Small code improvement in solver_utils.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes committed Dec 13, 2023
1 parent e004c82 commit 21df56e
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/solver/simulation/solver_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21df56e

Please sign in to comment.