Skip to content

Commit

Permalink
#371 MarginCalculationLauncher::results_ becomes a map
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitri Baron <[email protected]>
  • Loading branch information
barondim committed Jan 24, 2024
1 parent 6fbb2bf commit 05cc168
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 194 deletions.
17 changes: 9 additions & 8 deletions sources/API/aggregatedResults/DYNAggrResXmlExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ XmlExporter::exportScenarioResultsToStream(const vector<SimulationResult>& resul


void
XmlExporter::exportLoadIncreaseResultsToFile(const vector<LoadIncreaseResult>& results, const string& filePath) const {
XmlExporter::exportLoadIncreaseResultsToFile(const std::map<double, LoadIncreaseResult>& results, const string& filePath) const {
ofstream file;
file.open(filePath.c_str(), std::ios::binary);
if (!file.is_open()) {
Expand All @@ -80,20 +80,21 @@ XmlExporter::exportLoadIncreaseResultsToFile(const vector<LoadIncreaseResult>& r
}

void
XmlExporter::exportLoadIncreaseResultsToStream(const vector<LoadIncreaseResult>& results, ostream& stream) const {
XmlExporter::exportLoadIncreaseResultsToStream(const std::map<double, LoadIncreaseResult>& results, ostream& stream) const {
FormatterPtr formatter = Formatter::createFormatter(stream, "http://www.rte-france.com/dynawo");

formatter->startDocument();
AttributeList attrs;
formatter->startElement("aggregatedResults", attrs);
for (size_t i=0, iEnd = results.size(); i < iEnd; i++) {

for (auto loadIncreaseResultIt = results.begin(); loadIncreaseResultIt != results.end(); ++loadIncreaseResultIt) {
const LoadIncreaseResult& result = loadIncreaseResultIt->second;
attrs.clear();
const DYNAlgorithms::LoadIncreaseResult& loadIncreaseRes = results[i];
attrs.add("loadLevel", loadIncreaseRes.getLoadLevel());
attrs.add("status", getStatusAsString(loadIncreaseRes.getStatus()));
attrs.add("loadLevel", result.getPreScenariosLoadIncreaseResult().getVariation());
attrs.add("status", getStatusAsString(result.getPreScenariosLoadIncreaseResult().getStatus()));
formatter->startElement("loadIncreaseResults", attrs);
if (loadIncreaseRes.getStatus() == DYNAlgorithms::CONVERGENCE_STATUS) {
appendScenarioResultsElement(loadIncreaseRes.getScenariosResults(), formatter);
if (result.getPreScenariosLoadIncreaseResult().getStatus() == DYNAlgorithms::CONVERGENCE_STATUS) {
appendScenarioResultsElement(result.getScenariosResults(), formatter);
}
formatter->endElement(); // loadIncreaseResults
}
Expand Down
4 changes: 2 additions & 2 deletions sources/API/aggregatedResults/DYNAggrResXmlExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class XmlExporter {
* @param results aggregated results to export
* @param filePath file where the results must be exported
*/
void exportLoadIncreaseResultsToFile(const std::vector<DYNAlgorithms::LoadIncreaseResult>& results, const std::string& filePath) const;
void exportLoadIncreaseResultsToFile(const std::map<double, DYNAlgorithms::LoadIncreaseResult>& results, const std::string& filePath) const;

/**
* @brief Export load increase results into a steam
*
* @param results aggregated results to export
* @param stream stream where the results must be exported
*/
void exportLoadIncreaseResultsToStream(const std::vector<DYNAlgorithms::LoadIncreaseResult>& results, std::ostream& stream) const;
void exportLoadIncreaseResultsToStream(const std::map<double, DYNAlgorithms::LoadIncreaseResult>& results, std::ostream& stream) const;

private:
/**
Expand Down
50 changes: 5 additions & 45 deletions sources/Common/DYNLoadIncreaseResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,14 @@

namespace DYNAlgorithms {

LoadIncreaseResult::LoadIncreaseResult():
status_(EXECUTION_PROBLEM_STATUS),
loadLevel_(-1.) { }

LoadIncreaseResult::~LoadIncreaseResult() { }

double
LoadIncreaseResult::getLoadLevel() const {
return loadLevel_;
}

void
LoadIncreaseResult::setLoadLevel(double loadLevel) {
loadLevel_ = loadLevel;
}

status_t
LoadIncreaseResult::getStatus() const {
return status_;
}

void
LoadIncreaseResult::setStatus(status_t status) {
status_ = status;
}

void
LoadIncreaseResult::resize(size_t nbScenarios) {
scenariosResults_.resize(nbScenarios);
LoadIncreaseResult::LoadIncreaseResult(const SimulationResult& preScenariosLoadIncreaseResult,
const size_t nbScenarios) :
preScenariosLoadIncreaseResult_(preScenariosLoadIncreaseResult) {
scenariosResults_.resize(nbScenarios);
}

SimulationResult&
LoadIncreaseResult::getScenarioResult(size_t idx) {
assert(idx < scenariosResults_.size());
return scenariosResults_[idx];
}

const std::vector<SimulationResult>&
LoadIncreaseResult::getScenariosResults() const {
return scenariosResults_;
}

std::vector<SimulationResult>::const_iterator LoadIncreaseResult::begin() const {
return scenariosResults_.begin();
}

std::vector<SimulationResult>::const_iterator LoadIncreaseResult::end() const {
return scenariosResults_.end();
return scenariosResults_.at(idx);
}

} // namespace DYNAlgorithms
65 changes: 6 additions & 59 deletions sources/Common/DYNLoadIncreaseResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,18 @@ namespace DYNAlgorithms {
class LoadIncreaseResult {
public:
/**
* @brief default constructor
* @brief constructor
*/
LoadIncreaseResult();
explicit LoadIncreaseResult(const SimulationResult& preScenariosLoadIncreaseResult, const size_t nbScenarios);

/**
* @brief default destructor
*/
~LoadIncreaseResult();

/**
* @brief get the load level of the load increase
* @return load level of the load increase
*/
double getLoadLevel() const;

/**
* @brief set the load level of the load increase
* @param loadLevel value to apply
*/
void setLoadLevel(double loadLevel);

/**
* @brief get the status of the load increase
* @return status of the load increase
*/
status_t getStatus() const;

/**
* @brief set the status of the load increase
* @param status value to apply
*/
void setStatus(status_t status);

SimulationResult getPreScenariosLoadIncreaseResult() const {
const SimulationResult& getPreScenariosLoadIncreaseResult() const {
return preScenariosLoadIncreaseResult_;
}

void setPreScenariosLoadIncreaseResult(const SimulationResult& preScenariosLoadIncreaseResult) {
preScenariosLoadIncreaseResult_ = preScenariosLoadIncreaseResult;
}

/**
* @brief specify the number of scenarios
* @param nbScenarios number of scenarios
*/
void resize(size_t nbScenarios);

/**
* @brief getter of the number of scenarios
* @return the number of scenarios
*/
size_t size() const {return scenariosResults_.size();}

/**
* @brief result getter
* @param idx id of the result
Expand All @@ -93,25 +52,13 @@ class LoadIncreaseResult {
* @brief getter for the results
* @return results associated to this load increase
*/
const std::vector<SimulationResult>& getScenariosResults() const;

/**
* @brief begin iterator on simulation results
* @return begin iterator on the first result
*/
std::vector<SimulationResult>::const_iterator begin() const;

/**
* @brief end iterator on simulation results
* @return end iterator on the first result
*/
std::vector<SimulationResult>::const_iterator end() const;
const std::vector<SimulationResult>& getScenariosResults() const {
return scenariosResults_;
}

private:
SimulationResult preScenariosLoadIncreaseResult_;
std::vector<SimulationResult> scenariosResults_; ///< list of scenario results
status_t status_; ///< status of the load increase
double loadLevel_; ///< value of the variation of the load increase
};

} // namespace DYNAlgorithms
Expand Down
10 changes: 5 additions & 5 deletions sources/Launcher/DYNComputeLoadVariationLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ ComputeLoadVariationLauncher::launch() {
simulation->setStopTime(job->getSimulationEntry()->getStopTime() - (100. - variation_)/100. * duration);
simulate(simulation, result);
}
LoadIncreaseResult loadResult;
loadResult.setLoadLevel(variation_);
loadResult.setStatus(result.getStatus());
std::vector<LoadIncreaseResult> results;
results.push_back(loadResult);
std::map<double, LoadIncreaseResult> results;
result.setVariation(variation_);
results.emplace(std::piecewise_construct,
std::forward_as_tuple(result.getVariation()),
std::forward_as_tuple(result, 0));
aggregatedResults::XmlExporter exporter;
exporter.exportLoadIncreaseResultsToFile(results, outputFileFullPath_);
std::cout << "End of load increase simulation status: " + getStatusAsString(result.getStatus()) << std::endl;
Expand Down
Loading

0 comments on commit 05cc168

Please sign in to comment.