Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Dec 16, 2024
1 parent 2d129d8 commit 7fa9009
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,33 @@

#pragma once
#include <string>
#include <vector>
#include <set>

namespace Antares::Data::ShortTermStorage
{
struct AdditionalConstraint

struct AdditionalConstraint
{
std::string name;
std::string cluster_id;
std::string variable;
std::string operatorType;
std::vector<int> hours;
std::set<int> hours;
double rhs;

unsigned int globalIndex = 0;

bool validate() const;

bool isValidVariable() const;

bool isValidOperatorType() const;

bool isValidHoursRange() const;

mutable std::string error_message = "";

std::string getErrorMessage() const { return error_message; }

};
} // namespace Antares::Data::ShortTermStorage
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,44 @@ bool AdditionalConstraint::validate() const
{
if (cluster_id.empty())
{
error_message = "Cluster ID is empty.";
return false;
}

if (variable != "injection" && variable != "withdrawal" && variable != "netting")
if (!isValidVariable())
{
error_message = "Invalid variable type. Must be 'injection', 'withdrawal', or 'netting'.";
return false;
}

if (operatorType != "less" && operatorType != "equal" && operatorType != "greater")
if (!isValidOperatorType())
{
error_message = "Invalid operator type. Must be 'less', 'equal', or 'greater'.";
return false;
}

if (hours.empty() || *std::min_element(hours.begin(), hours.end()) < 1
|| *std::max_element(hours.begin(), hours.end()) > 168)
if (!isValidHoursRange())
{
error_message = "Hours set contains invalid values. Must be between 1 and 168.";
return false;
}

error_message.clear();
return true;
}

bool AdditionalConstraint::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 {
return variable == "injection" || variable == "withdrawal" || variable == "netting";
}

bool AdditionalConstraint::isValidOperatorType() const {
return operatorType == "less" || operatorType == "equal" || operatorType == "greater";
}
} // namespace Antares::Data::ShortTermStorage
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
while (std::getline(ss, hour, ','))
{
int hourVal = std::stoi(hour);
constraint.hours.push_back(hourVal);
constraint.hours.insert(hourVal);
}
}
else if (key == "rhs")
Expand All @@ -129,6 +129,7 @@ bool STStorageInput::LoadConstraintsFromIniFile(const fs::path& parent_path)
if (!constraint.validate())
{
logs.error() << "Invalid constraint in section: " << section->name;
logs.error() << constraint.getErrorMessage();
return false;
}

Expand Down

0 comments on commit 7fa9009

Please sign in to comment.