Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small code improvement in solver_utils.cpp #1824

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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