From 4c8d40757daea5cc20537f9061252da93f36b0d3 Mon Sep 17 00:00:00 2001 From: Guillaume PIERRE Date: Wed, 18 Dec 2024 11:35:55 +0100 Subject: [PATCH] New hydro remix : improve comparison between 2 std::vector --- src/solver/simulation/hydro-remix-new.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/solver/simulation/hydro-remix-new.cpp b/src/solver/simulation/hydro-remix-new.cpp index 081cfb6663..ccb85ece18 100644 --- a/src/solver/simulation/hydro-remix-new.cpp +++ b/src/solver/simulation/hydro-remix-new.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -56,6 +55,13 @@ int find_max_index(const std::vector& G_plus_H, return max_idx; } +static bool isLessThan(const std::vector& a, const std::vector& b) +{ + std::vector a_minus_b; + std::ranges::transform(a, b, std::back_inserter(a_minus_b), std::minus()); + return std::ranges::all_of(a_minus_b, [](double d) { return d <= 0.; }); +} + static void checkInputCorrectness(const std::vector& G, const std::vector& H, const std::vector& D, @@ -100,20 +106,14 @@ static void checkInputCorrectness(const std::vector& G, } // Hydro production < Pmax - for (int h = 0; h < H.size(); h++) + if (!isLessThan(H, P_max)) { - if (H[h] > P_max[h]) - { - throw std::invalid_argument(msg_prefix + "H not smaller than Pmax everywhere"); - } + throw std::invalid_argument(msg_prefix + "H not smaller than Pmax everywhere"); } // Hydro production > Pmin - for (int h = 0; h < H.size(); h++) + if (!isLessThan(P_min, H)) { - if (H[h] < P_min[h]) - { - throw std::invalid_argument(msg_prefix + "H not greater than Pmin everywhere"); - } + throw std::invalid_argument(msg_prefix + "H not greater than Pmin everywhere"); } }