Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop' into feature/hy…
Browse files Browse the repository at this point in the history
…dro-remix-integration
  • Loading branch information
guilpier-code committed Jan 10, 2025
2 parents b30fa67 + 874612d commit a6776ec
Show file tree
Hide file tree
Showing 44 changed files with 1,409 additions and 192 deletions.
File renamed without changes.
12 changes: 12 additions & 0 deletions docs/user-guide/solver/static-modeler/04-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@ _**This section is under construction**_

> _**Note:**_ You can find more information on this parameter [here](../03-appendix.md#details-on-the-include-exportmps-parameter).
---
#### include-export-solutions
- **Expected value:** `true` or `false`
- **Required:** no
- **Default value:** `false`
- **Usage:** set to `true` to activate writing the raw optimization results, that is
- For each variable, optimal values (saved in output/output-name/optimal-values-y-w--optim-nb-z.txt) and reduced costs (saved in output/output-name/reduced-costs-y-w--optim-nb-z.txt)
- each constraint, the marginal cost is saved in output/output-name/marinal-costs-y-w--optim-nb-z.txt
where y is the year number (starting from 1), w is the week number (starting from 1) and z is the optimization index (1 or 2).

This is an advanced option intended to help developers and advanced users better understand their simulation results.

---
#### include-split-exported-mps
[//]: # (TODO: document this parameter, seems to belong to another category)
Expand Down
2 changes: 1 addition & 1 deletion src/format-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ fi
if ! [ -x "$(command -v clang-format)" ]; then
echo 'Warning: clang-format is not installed. Skipping' >&2
else
echo "$SOURCE_FILES" | xargs clang-format -i --verbose
echo "$SOURCE_FILES" | xargs clang-format -style=file:../.clang-format -i --verbose
fi
4 changes: 2 additions & 2 deletions src/libs/antares/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ set(SRC_STUDY_PART_SHORT_TERM_STORAGE
parts/short-term-storage/series.cpp
include/antares/study/parts/short-term-storage/series.h
include/antares/study/parts/short-term-storage/cluster.h
include/antares/study/parts/short-term-storage/AdditionalConstraint.h
include/antares/study/parts/short-term-storage/additionalConstraints.h
parts/short-term-storage/cluster.cpp
parts/short-term-storage/AdditionalConstraint.cpp
parts/short-term-storage/additionalConstraints.cpp
)
source_group("study\\part\\short-term-storage" FILES ${SRC_STUDY_PART_SHORT_TERM_SOTRAGE})

Expand Down
10 changes: 6 additions & 4 deletions src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,12 +1194,14 @@ bool AreaList::loadFromFolder(const StudyLoadOptions& options)

if (fs::exists(stsFolder))
{
for (const auto& [id, area]: areas)
for (const auto& area: areas | std::views::values)
{
fs::path folder = stsFolder / "clusters" / area->id.c_str();
fs::path cluster_folder = stsFolder / "clusters" / area->id.c_str();
ret = area->shortTermStorage.createSTStorageClustersFromIniFile(cluster_folder)
&& ret;

ret = area->shortTermStorage.createSTStorageClustersFromIniFile(folder) && ret;
ret = area->shortTermStorage.LoadConstraintsFromIniFile(folder) && ret;
const auto constraints_folder = stsFolder / "constraints" / area->id.c_str();
ret = area->shortTermStorage.loadAdditionalConstraints(constraints_folder) && ret;
}
}
else
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/study/include/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ class Parameters final
//! Enum to define unfeasible problem behavior \see UnfeasibleProblemBehavior
UnfeasibleProblemBehavior unfeasibleProblemBehavior;

bool exportSolutions;
} include;

struct Compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,46 @@
#pragma once
#include <set>
#include <string>
#include <vector>

namespace Antares::Data::ShortTermStorage
{

struct AdditionalConstraint
class SingleAdditionalConstraint
{
public:
std::set<int> hours;
unsigned int globalIndex = 0;
unsigned int localIndex = 0;
bool isValidHoursRange() const;
};

struct AdditionalConstraints
{
std::string name;
std::string cluster_id;
std::string variable;
std::string operatorType;
std::set<int> hours;
double rhs;
bool enabled = true;
std::vector<double> rhs;

unsigned int globalIndex = 0;
std::vector<SingleAdditionalConstraint> constraints;

struct ValidateResult
{
bool ok;
std::string error_msg;
};

// Number of enabled constraints
std::size_t enabledConstraints() const;

ValidateResult validate() const;

private:
bool isValidVariable() const;
bool isValidOperatorType() const;
bool isValidHoursRange() const;

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

#include <antares/inifile/inifile.h>

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

Expand All @@ -51,6 +51,6 @@ class STStorageCluster

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

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

namespace Antares::Data::ShortTermStorage
Expand All @@ -42,7 +41,7 @@ class STStorageInput
/// Number of enabled ST storages, ignoring disabled ST storages
std::size_t count() const;

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

/// erase disabled cluster from the vector
uint removeDisabledClusters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ class Series

bool loadFile(const std::filesystem::path& folder, std::vector<double>& vect);
bool writeVectorToFile(const std::string& path, const std::vector<double>& vect);

void fillIfEmpty(std::vector<double>& v, double value);
} // namespace Antares::Data::ShortTermStorage
12 changes: 12 additions & 0 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ void Parameters::reset()

include.exportMPS = mpsExportStatus::NO_EXPORT;
include.exportStructure = false;
include.exportSolutions = false;
namedProblems = false;

include.unfeasibleProblemBehavior = UnfeasibleProblemBehavior::ERROR_MPS;
Expand Down Expand Up @@ -721,6 +722,11 @@ static bool SGDIntLoadFamily_Optimization(Parameters& d,
return true;
}

if (key == "include-export-solutions")
{
return value.to<bool>(d.include.exportSolutions);
}

if (key == "include-exportstructure")
{
return value.to<bool>(d.include.exportStructure);
Expand Down Expand Up @@ -1769,6 +1775,10 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options)
{
logs.info() << " :: ignoring hurdle costs";
}
if (!include.exportSolutions)
{
logs.info() << " :: ignoring solution export";
}

logs.info() << " :: solver " << options.optOptions.ortoolsSolver
<< " is used for problem resolution";
Expand Down Expand Up @@ -1888,7 +1898,9 @@ void Parameters::saveToINI(IniFile& ini) const
section->add("include-primaryreserve", include.reserve.primary);

section->add("include-exportmps", mpsExportStatusToString(include.exportMPS));

section->add("include-exportstructure", include.exportStructure);
section->add("include-export-solutions", include.exportSolutions);

// Unfeasible problem behavior
section->add("include-unfeasible-problem-behavior",
Expand Down
1 change: 1 addition & 0 deletions src/libs/antares/study/parameters/adq-patch-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ void AdqPatchParams::addExcludedVariables(std::vector<std::string>& out) const
out.emplace_back("LOLP CSR");
out.emplace_back("MAX MRG CSR");
out.emplace_back("OV. COST CSR");
out.emplace_back("MRG. PRICE CSR");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
** You should have received a copy of the Mozilla Public Licence 2.0
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/
#include "antares/study/parts/short-term-storage/AdditionalConstraint.h"

#include "antares/study/parts/short-term-storage/additionalConstraints.h"

#include <algorithm>

namespace Antares::Data::ShortTermStorage
{
AdditionalConstraint::ValidateResult AdditionalConstraint::validate() const
AdditionalConstraints::ValidateResult AdditionalConstraints::validate() const
{
if (cluster_id.empty())
{
Expand All @@ -39,27 +42,39 @@ AdditionalConstraint::ValidateResult AdditionalConstraint::validate() const
return {false, "Invalid operator type. Must be 'less', 'equal', or 'greater'."};
}

if (!isValidHoursRange())
if (!isValidHours())
{
return {false, "Hours set contains invalid values. Must be between 1 and 168."};
return {false, "Hours sets contains invalid values. Must be between 1 and 168."};
}

return {true, ""};
}

bool AdditionalConstraint::isValidHoursRange() const
bool SingleAdditionalConstraint::isValidHoursRange() const
{
// `hours` is a sorted set; begin() gives the smallest and prev(end()) gives the largest.
return !hours.empty() && *hours.begin() >= 1 && *std::prev(hours.end()) <= 168;
}

bool AdditionalConstraint::isValidVariable() const
bool AdditionalConstraints::isValidHours() const
{
return std::ranges::all_of(constraints,
[](const auto& constraint)
{ return constraint.isValidHoursRange(); });
}

bool AdditionalConstraints::isValidVariable() const
{
return variable == "injection" || variable == "withdrawal" || variable == "netting";
}

bool AdditionalConstraint::isValidOperatorType() const
bool AdditionalConstraints::isValidOperatorType() const
{
return operatorType == "less" || operatorType == "equal" || operatorType == "greater";
}

std::size_t AdditionalConstraints::enabledConstraints() const
{
return enabled ? constraints.size() : 0;
}
} // namespace Antares::Data::ShortTermStorage
Loading

0 comments on commit a6776ec

Please sign in to comment.