Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Dec 20, 2024
1 parent 11c120e commit f100200
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
32 changes: 19 additions & 13 deletions src/libs/antares/study/parts/short-term-storage/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)

for (auto* section = ini.firstSection; section; section = section->next)
{
AdditionalConstraints constraint;
constraint.name = section->name.c_str();
AdditionalConstraints additional_constraints;
additional_constraints.name = section->name.c_str();
for (auto* property = section->firstProperty; property; property = property->next)
{
const std::string key = property->key;
Expand All @@ -100,15 +100,15 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
// TODO do i have to transform the name to id? TransformNameIntoID
std::string clusterName;
value.to<std::string>(clusterName);
constraint.cluster_id = transformNameIntoID(clusterName);
additional_constraints.cluster_id = transformNameIntoID(clusterName);
}
else if (key == "variable")
{
value.to<std::string>(constraint.variable);
value.to<std::string>(additional_constraints.variable);
}
else if (key == "operator")
{
value.to<std::string>(constraint.operatorType);
value.to<std::string>(additional_constraints.operatorType);
}
else if (key == "hours")
{
Expand All @@ -129,6 +129,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
hoursStr.end(),
groupRegex);
auto groupsEnd = std::sregex_iterator();
unsigned int localIndex = 0;
for (auto it = groupsBegin; it != groupsEnd; ++it)
{
// Extract the contents of the square brackets
Expand All @@ -142,17 +143,20 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
int hourVal = std::stoi(hour);
hourSet.insert(hourVal);
}

constraint.hours.push_back(hourSet); // Add this group to the `hours` vector
// Add this group to the `hours` vec
additional_constraints.constraints.push_back(
{.hours = hourSet, .localIndex = localIndex});
++localIndex;
}
}

// try to read the rhs
loadFile(parent_path / ("rhs_" + constraint.name + ".txt"), constraint.rhs);
fillIfEmpty(constraint.rhs, 0.0);
loadFile(parent_path / ("rhs_" + additional_constraints.name + ".txt"),
additional_constraints.rhs);
fillIfEmpty(additional_constraints.rhs, 0.0);
}

if (auto [ok, error_msg] = constraint.validate(); !ok)
if (auto [ok, error_msg] = additional_constraints.validate(); !ok)
{
logs.error() << "Invalid constraint in section: " << section->name;
logs.error() << error_msg;
Expand All @@ -161,8 +165,10 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)

auto it = std::find_if(storagesByIndex.begin(),
storagesByIndex.end(),
[&constraint](const STStorageCluster& cluster)
{ return cluster.id == constraint.cluster_id; });
[&additional_constraints](const STStorageCluster& cluster)
{
return cluster.id == additional_constraints.cluster_id;
});
if (it == storagesByIndex.end())
{
logs.warning() << " from file " << pathIni;
Expand All @@ -172,7 +178,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
}
else
{
it->additional_constraints.push_back(constraint);
it->additional_constraints.push_back(additional_constraints);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,19 @@ void ShortTermStorageCumulation::add(int pays)
// var = injectionEfficiency * injection - withdrawalEfficiency * withdrawal for Netting
auto constraintHelper = cumulationConstraintFromVariable(
additional_constraints.variable);
for (auto& constraint: additional_constraints.constraints)
for (const auto& [hours, globalIndex, localIndex]: additional_constraints.constraints)
{
namer.ShortTermStorageCumulation(constraintHelper->name() +,
builder.data.nombreDeContraintes,
storage.name,
additional_constraints.name);
namer.ShortTermStorageCumulation(
constraintHelper->name() + std::to_string(localIndex),
builder.data.nombreDeContraintes,
storage.name,
additional_constraints.name);
const auto index = storage.clusterGlobalIndex;
data.CorrespondanceCntNativesCntOptimHebdomadaires
.ShortTermStorageCumulation[additional_constraints.globalIndex]
.ShortTermStorageCumulation[globalIndex]
= builder.data.nombreDeContraintes;

for (const auto& hour: additional_constraints.hours)
for (const auto& hour: hours)
{
builder.updateHourWithinWeek(hour - 1);
constraintHelper->build(builder, index, storage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ int OPT_DecompteDesVariablesEtDesContraintesDuProblemeAOptimiser(PROBLEME_HEBDO*
}
if (!storage.additional_constraints.empty())
{
ProblemeAResoudre->NombreDeContraintes += storage.additional_constraints.size();
for (const auto& additional_constraints: storage.additional_constraints)
{
ProblemeAResoudre->NombreDeContraintes += additional_constraints.constraints
.size();
}
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions src/solver/optimisation/opt_gestion_second_membre_cas_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include <numeric>

#include "antares/solver/simulation/sim_structure_probleme_economique.h"

double OPT_SommeDesPminThermiques(const PROBLEME_HEBDO*, int, uint);
Expand Down Expand Up @@ -47,17 +49,32 @@ static void shortTermStorageCumulationRHS(
const std::vector<::ShortTermStorage::AREA_INPUT>& shortTermStorageInput,
int numberOfAreas,
std::vector<double>& SecondMembre,
const CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondancesDesContraintesHebdomadaires)
const CORRESPONDANCES_DES_CONTRAINTES_HEBDOMADAIRES& CorrespondancesDesContraintesHebdomadaires,
int weekFirstHour)
{
for (int areaIndex = 0; areaIndex < numberOfAreas; areaIndex++)
{
for (auto& storage: shortTermStorageInput[areaIndex])
{
for (const auto& constraint: storage.additional_constraints)
for (const auto& additional_constraints: storage.additional_constraints)
{
int cnt = CorrespondancesDesContraintesHebdomadaires
for (const auto& constraint: additional_constraints.constraints)
{
const int cnt = CorrespondancesDesContraintesHebdomadaires
.ShortTermStorageCumulation[constraint.globalIndex];
SecondMembre[cnt] = constraint.rhs;

SecondMembre[cnt] = std::accumulate(constraint.hours.begin(),
constraint.hours.end(),
0.0,
[weekFirstHour, &additional_constraints
](
const double sum,
const int hour)
{
return sum + additional_constraints.rhs[
weekFirstHour + hour - 1];
});
}
}
}
}
Expand Down Expand Up @@ -395,11 +412,11 @@ void OPT_InitialiserLeSecondMembreDuProblemeLineaire(PROBLEME_HEBDO* problemeHeb
}
}
}

shortTermStorageCumulationRHS(problemeHebdo->ShortTermStorage,
problemeHebdo->NombreDePays,
ProblemeAResoudre->SecondMembre,
problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires);
problemeHebdo->CorrespondanceCntNativesCntOptimHebdomadaires,
weekFirstHour);
if (problemeHebdo->OptimisationAvecCoutsDeDemarrage)
{
OPT_InitialiserLeSecondMembreDuProblemeLineaireCoutsDeDemarrage(problemeHebdo,
Expand Down
2 changes: 1 addition & 1 deletion src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void importShortTermStorages(
toInsert.additional_constraints = st.additional_constraints;
for (auto& additional_constraints: toInsert.additional_constraints)
{
for (auto& [_, globalIndex]: additional_constraints.constraints)
for (auto& [_, globalIndex,__]: additional_constraints.constraints)
{
globalIndex = clusterCumulativeConstraintGlobalIndex;
++clusterCumulativeConstraintGlobalIndex;
Expand Down

0 comments on commit f100200

Please sign in to comment.