Skip to content

Commit

Permalink
remove unused var and apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Dec 16, 2024
1 parent 81c2ab4 commit 2d129d8
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@
#include <string>
#include <vector>

namespace Antares::Data::ShortTermStorage {
struct AdditionalConstraint {
std::string name;
std::string cluster_id;
std::string variable;
std::string operatorType;
std::vector<int> hours;
double rhs;
namespace Antares::Data::ShortTermStorage
{
struct AdditionalConstraint
{
std::string name;
std::string cluster_id;
std::string variable;
std::string operatorType;
std::vector<int> hours;
double rhs;

unsigned int globalIndex = 0;
unsigned int globalIndex = 0;

bool validate() const;
};
bool validate() const;
};
} // namespace Antares::Data::ShortTermStorage
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,31 @@

#include <antares/inifile/inifile.h>

#include "AdditionalConstraint.h"
#include "properties.h"
#include "series.h"
#include "AdditionalConstraint.h"

namespace Antares::Data::ShortTermStorage {
class STStorageCluster {
public:
bool enabled() const;
namespace Antares::Data::ShortTermStorage
{
class STStorageCluster
{
public:
bool enabled() const;

bool validate() const;
bool validate() const;

bool loadFromSection(const IniFile::Section &section);
bool loadFromSection(const IniFile::Section& section);

bool loadSeries(const std::filesystem::path &folder) const;
bool loadSeries(const std::filesystem::path& folder) const;

void saveProperties(IniFile &ini) const;
void saveProperties(IniFile& ini) const;

bool saveSeries(const std::string &path) const;
bool saveSeries(const std::string& path) const;

std::string id;
std::string id;

std::shared_ptr<Series> series = std::make_shared<Series>();
mutable Properties properties;
std::vector<AdditionalConstraint> additional_constraints;
};
std::shared_ptr<Series> series = std::make_shared<Series>();
mutable Properties properties;
std::vector<AdditionalConstraint> additional_constraints;
};
} // namespace Antares::Data::ShortTermStorage
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,37 @@
#include <filesystem>
#include <string>

#include "cluster.h"
#include "AdditionalConstraint.h"
#include "cluster.h"

namespace Antares::Data::ShortTermStorage {
class STStorageInput {
public:
bool validate() const;
namespace Antares::Data::ShortTermStorage
{
class STStorageInput
{
public:
bool validate() const;

/// 1. Read list.ini
bool createSTStorageClustersFromIniFile(const std::filesystem::path &path);
/// 1. Read list.ini
bool createSTStorageClustersFromIniFile(const std::filesystem::path& path);

/// 2. Read ALL series
bool loadSeriesFromFolder(const std::filesystem::path &folder) const;
/// 2. Read ALL series
bool loadSeriesFromFolder(const std::filesystem::path& folder) const;

/// Number of enabled ST storages, ignoring disabled ST storages
std::size_t count() const;
/// Number of enabled ST storages, ignoring disabled ST storages
std::size_t count() const;

bool LoadConstraintsFromIniFile(const std::filesystem::path &filePath
);
bool LoadConstraintsFromIniFile(const std::filesystem::path& filePath);

/// erase disabled cluster from the vector
uint removeDisabledClusters();
/// erase disabled cluster from the vector
uint removeDisabledClusters();

bool saveToFolder(const std::string &folder) const;
bool saveToFolder(const std::string& folder) const;

bool saveDataSeriesToFolder(const std::string &folder) const;
bool saveDataSeriesToFolder(const std::string& folder) const;

std::vector<STStorageCluster> storagesByIndex;
std::vector<STStorageCluster> storagesByIndex;

/// Number cumulative - constraint
std::size_t cumulativeConstraintCount() const;
};
/// Number cumulative - constraint
std::size_t cumulativeConstraintCount() const;
};
} // namespace Antares::Data::ShortTermStorage
8 changes: 4 additions & 4 deletions src/libs/antares/study/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ static void StudyRuntimeInfosInitializeAllAreas(Study& study, StudyRuntimeInfos&
r.thermalPlantTotalCountMustRun += area.thermal.list.enabledAndMustRunCount();

r.shortTermStorageCount += area.shortTermStorage.count();
r.shortTermStorageCumulativeConstraintCount += area.shortTermStorage.
cumulativeConstraintCount();
r.shortTermStorageCumulativeConstraintCount += area.shortTermStorage
.cumulativeConstraintCount();
}
}

Expand Down Expand Up @@ -365,8 +365,8 @@ bool StudyRuntimeInfos::loadFromStudy(Study& study)
logs.info() << " thermal clusters: " << thermalPlantTotalCount;
logs.info() << " thermal clusters (must-run): " << thermalPlantTotalCountMustRun;
logs.info() << " short-term storages: " << shortTermStorageCount;
logs.info() << " short-term storage cumulative constraints count: " <<
shortTermStorageCumulativeConstraintCount;
logs.info() << " short-term storage cumulative constraints count: "
<< shortTermStorageCumulativeConstraintCount;
logs.info() << " binding constraints: "
<< study.bindingConstraints.activeConstraints().size();
logs.info() << " geographic trimming:" << (gd.geographicTrimming ? "true" : "false");
Expand Down
6 changes: 2 additions & 4 deletions src/solver/optimisation/constraints/Group1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ ShortTermStorageData Group1::GetShortTermStorageData()

ShortTermStorageCumulativeConstraintData Group1::GetShortTermStorageCumulativeConstraintData()
{
return {
problemeHebdo_->CorrespondanceCntNativesCntOptim,
return {problemeHebdo_->CorrespondanceCntNativesCntOptim,
problemeHebdo_->ShortTermStorage,
problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires
};
problemeHebdo_->CorrespondanceCntNativesCntOptimHebdomadaires};
}

FlowDissociationData Group1::GetFlowDissociationData()
Expand Down
79 changes: 42 additions & 37 deletions src/solver/optimisation/constraints/ShortTermStorageCumulation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* Copyright 2007-2024, RTE (https://www.rte-france.com)
* See AUTHORS.txt
* SPDX-License-Identifier: MPL-2.0
* This file is part of Antares-Simulator,
Expand All @@ -23,25 +23,28 @@
#include "antares/solver/optimisation/constraints/ShortTermStorageCumulation.h"

void ShortTermStorageCumulation::Injection(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input
){
const ::ShortTermStorage::PROPERTIES& input)
{
builder.ShortTermStorageInjection(index, 1.0);
}
}

void ShortTermStorageCumulation::Withdrawal(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input
){
builder.ShortTermStorageWithdrawal(index, 1.0);}
void ShortTermStorageCumulation::Netting(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input){
const ::ShortTermStorage::PROPERTIES& input)
{
builder.ShortTermStorageWithdrawal(index, 1.0);
}

void ShortTermStorageCumulation::Netting(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input)
{
builder.ShortTermStorageInjection(index, input.injectionEfficiency)
.ShortTermStorageWithdrawal(index, -input.withdrawalEfficiency);
}

builder.ShortTermStorageInjection(index, input.injectionEfficiency ).
ShortTermStorageWithdrawal(index, -input.withdrawalEfficiency);
}
auto getMemberFunction = [](const std::string& name)
-> std::pair<std::string, void (ShortTermStorageCumulation::*)(unsigned int,
const ::ShortTermStorage::PROPERTIES&
)>
-> std::pair<std::string,
void (ShortTermStorageCumulation::*)(unsigned int,
const ::ShortTermStorage::PROPERTIES&)>
{
if (name == "withdrawal")
{
Expand All @@ -58,49 +61,51 @@ auto getMemberFunction = [](const std::string& name)
return {"", nullptr}; // Return null if no match
};


char ConvertSign(const std::string& sign){
if (sign == "greater") {
char ConvertSign(const std::string& sign)
{
if (sign == "greater")
{
return '>';
}
else if (sign == "less") {
return '<';
}
else {
return '=';
}
else if (sign == "less")
{
return '<';
}
else
{
return '=';
}
}

void ShortTermStorageCumulation::add(int pays){

void ShortTermStorageCumulation::add(int pays)
{
ConstraintNamer namer(builder.data.NomDesContraintes);
namer.UpdateArea(builder.data.NomsDesPays[pays]);

for (const auto& storage: data.ShortTermStorage[pays])
{
// TODO global index for constraints for data.CorrespondanceCntNativesCntOptimHebdomadaires.ShortTermStorageCumulation[index]
// TODO global index for constraints for
// data.CorrespondanceCntNativesCntOptimHebdomadaires.ShortTermStorageCumulation[index]
for (const auto& constraint: storage.additional_constraints)
{
//sum (var[h]) sign rhs, h in list provied by user
auto [constraintType,memberFunction] = getMemberFunction(constraint.variable);
// sum (var[h]) sign rhs, h in list provied by user
auto [constraintType, memberFunction] = getMemberFunction(constraint.variable);
namer.ShortTermStorageCumulation(constraintType,
builder.data.nombreDeContraintes,
storage.name,
constraint.name
);
constraint.name);
const auto index = storage.clusterGlobalIndex;
//TODO
data.CorrespondanceCntNativesCntOptimHebdomadaires.ShortTermStorageCumulation[constraint
.globalIndex]
= builder.data.nombreDeContraintes;
// TODO
data.CorrespondanceCntNativesCntOptimHebdomadaires
.ShortTermStorageCumulation[constraint.globalIndex]
= builder.data.nombreDeContraintes;

for (const auto& hour: constraint.hours)
{
builder.updateHourWithinWeek(hour - 1);
(this->*memberFunction)(index, storage);
}
builder.SetOperator(ConvertSign(constraint.operatorType))
.build();
builder.SetOperator(ConvertSign(constraint.operatorType)).build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,17 @@
class ShortTermStorageCumulation: private ConstraintFactory
{
public:
ShortTermStorageCumulation(ConstraintBuilder& builder, ShortTermStorageCumulativeConstraintData& data):
ShortTermStorageCumulation(ConstraintBuilder& builder,
ShortTermStorageCumulativeConstraintData& data):
ConstraintFactory(builder),
data(data)
{
}

void add(int pays);
void Injection(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input);
void Withdrawal(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input);
void Netting(unsigned int index,
const ::ShortTermStorage::PROPERTIES& input);
void Injection(unsigned int index, const ::ShortTermStorage::PROPERTIES& input);
void Withdrawal(unsigned int index, const ::ShortTermStorage::PROPERTIES& input);
void Netting(unsigned int index, const ::ShortTermStorage::PROPERTIES& input);

private:
ShortTermStorageCumulativeConstraintData& data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@ static void shortTermStorageLevelsRHS(
}

static void shortTermStorageCumulationRHS(
const std::vector<::ShortTermStorage::AREA_INPUT>& shortTermStorageInput,
int numberOfAreas,
std::vector<double>& SecondMembre,
const CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES&
CorrespondancesDesContraintesHebdomadaires)
const std::vector<::ShortTermStorage::AREA_INPUT>& shortTermStorageInput,
int numberOfAreas,
std::vector<double>& SecondMembre,
const CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondancesDesContraintesHebdomadaires)
{
for (int areaIndex = 0; areaIndex < numberOfAreas; areaIndex++)
{
for (auto& storage: shortTermStorageInput[areaIndex])
{
for (const auto& constraint: storage.additional_constraints)
{
int cnt = CorrespondancesDesContraintesHebdomadaires.ShortTermStorageCumulation
[constraint.globalIndex];
int cnt = CorrespondancesDesContraintesHebdomadaires
.ShortTermStorageCumulation[constraint.globalIndex];
SecondMembre[cnt] = constraint.rhs;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/solver/optimisation/opt_rename_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,10 @@ void ConstraintNamer::ShortTermStorageCumulation(const std::string& constraint_t
const std::string& short_term_name,
const std::string& constraint_name)
{
targetUpdater_.UpdateTargetAtIndex(BuildName(constraint_type,
LocationIdentifier(area_, AREA) + SEPARATOR
+ "ShortTermStorage" + "<" + short_term_name
+ ">",
ShortTermStorageCumulationIdentifier(
constraint_name)),
constraint);
targetUpdater_.UpdateTargetAtIndex(
BuildName(constraint_type,
LocationIdentifier(area_, AREA) + SEPARATOR + "ShortTermStorage" + "<"
+ short_term_name + ">",
ShortTermStorageCumulationIdentifier(constraint_name)),
constraint);
}
6 changes: 2 additions & 4 deletions src/solver/simulation/sim_alloc_probleme_hebdo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,8 @@ void SIM_AllocationLinks(PROBLEME_HEBDO& problem, const uint linkCount, unsigned
void SIM_AllocationShortermStorageCumulation(PROBLEME_HEBDO& problem,
const Antares::Data::Study& study)
{
problem.CorrespondanceCntNativesCntOptimHebdomadaires
.ShortTermStorageCumulation.assign(
study.runtime.shortTermStorageCumulativeConstraintCount,
0);
problem.CorrespondanceCntNativesCntOptimHebdomadaires.ShortTermStorageCumulation
.assign(study.runtime.shortTermStorageCumulativeConstraintCount, 0);
}

void SIM_AllocationConstraints(PROBLEME_HEBDO& problem,
Expand Down

0 comments on commit 2d129d8

Please sign in to comment.