Skip to content

Commit

Permalink
New hydro remix : improve comparison between 2 std::vector<double>
Browse files Browse the repository at this point in the history
  • Loading branch information
guilpier-code committed Dec 18, 2024
1 parent f3708e2 commit 4c8d407
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/solver/simulation/hydro-remix-new.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <algorithm>
#include <array>
#include <ranges>
#include <stdexcept>
#include <vector>
Expand Down Expand Up @@ -56,6 +55,13 @@ int find_max_index(const std::vector<double>& G_plus_H,
return max_idx;
}

static bool isLessThan(const std::vector<double>& a, const std::vector<double>& b)
{
std::vector<double> a_minus_b;
std::ranges::transform(a, b, std::back_inserter(a_minus_b), std::minus<double>());
return std::ranges::all_of(a_minus_b, [](double d) { return d <= 0.; });
}

static void checkInputCorrectness(const std::vector<double>& G,
const std::vector<double>& H,
const std::vector<double>& D,
Expand Down Expand Up @@ -100,20 +106,14 @@ static void checkInputCorrectness(const std::vector<double>& 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");
}
}

Expand Down

0 comments on commit 4c8d407

Please sign in to comment.