Skip to content

Commit

Permalink
re-add the func that only takes a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
payetvin committed Feb 17, 2025
1 parent 9460ac2 commit 8cffb84
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/libs/antares/utils/include/antares/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ double round(double d, unsigned precision);
double ceilDiv(double numerator, double denominator);
double floorDiv(double numerator, double denominator);

bool checkAllElementsIdenticalOrOne(std::vector<unsigned> w);
bool checkAllElementsIdenticalOrOne(std::vector<std::pair<unsigned, std::string>>& p);

} // namespace Utils
Expand Down
6 changes: 6 additions & 0 deletions src/libs/antares/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ double floorDiv(double numerator, double denominator)
return std::floor(std::round(numerator / denominator * largeValue) / largeValue);
}

bool checkAllElementsIdenticalOrOne(std::vector<unsigned> w)
{
auto first_one = std::remove(w.begin(), w.end(), 1); // Reject all 1 to the end
return std::adjacent_find(w.begin(), first_one, std::not_equal_to<uint>()) == first_one;
}

bool checkAllElementsIdenticalOrOne(std::vector<std::pair<unsigned, std::string>>& p)
{
// Reject all 1 to the end
Expand Down
15 changes: 4 additions & 11 deletions src/solver/simulation/timeseries-numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,12 @@ class IntraModalConsistencyChecker
bool IntraModalConsistencyChecker::checkTSconsistency()
{
logs.info() << "Checking intra-modal correlation: " << tsTitle_;
std::vector<std::pair<unsigned, std::string>> listNumberTS;
std::vector<unsigned> listNumberTS;
for (auto i = study_.areas.begin(); i != study_.areas.end(); ++i)
{
const Area& area = *(i->second);
vector<uint> areaNumberTSList = tsCounter_->getAreaTimeSeriesNumber(area);
listNumberTS.reserve(listNumberTS.size() + areaNumberTSList.size());
for (const auto& ts: areaNumberTSList)
{
listNumberTS.push_back({ts, ""});
}
std::vector<unsigned> areaNumberTSList = tsCounter_->getAreaTimeSeriesNumber(area);
listNumberTS.insert(listNumberTS.end(), areaNumberTSList.begin(), areaNumberTSList.end());
}

if (!Utils::checkAllElementsIdenticalOrOne(listNumberTS))
Expand All @@ -226,10 +222,7 @@ bool IntraModalConsistencyChecker::checkTSconsistency()
return false;
}
// At this point, all elements are identical or 1
nbTimeseries_ = std::ranges::max_element(listNumberTS,
[](const auto& a, const auto& b)
{ return a.first < b.first; })
->first;
nbTimeseries_ = *(std::ranges::max_element(listNumberTS));

return true;
}
Expand Down

0 comments on commit 8cffb84

Please sign in to comment.