From c2c1667a7356837af331eb2757b2edc3427fbb36 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Fri, 7 Jul 2023 14:45:34 +0200 Subject: [PATCH] Network: If there is only one edge, select it as current reach. --- src/Model/Network/Graph.py | 15 +++++++++++++++ src/Model/River.py | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/Model/Network/Graph.py b/src/Model/Network/Graph.py index 0f432495..e2d549fb 100644 --- a/src/Model/Network/Graph.py +++ b/src/Model/Network/Graph.py @@ -29,6 +29,14 @@ class Graph(object): def edges(self): return self._edges + def enable_edges(self): + return list( + filter( + lambda e: e.is_enable(), + self._edges + ) + ) + def edges_names(self): return list(map(lambda e: e.name, self._edges)) @@ -38,6 +46,13 @@ class Graph(object): def edges_counts(self): return len(self._edges) + def enable_edges_counts(self): + return reduce( + lambda acc, e: acc + 1 if e.is_enable() else acc, + self._edges, + 0 + ) + def is_node_exists(self, node_name): return reduce( lambda acc, n: (acc or (n.name == node_name)), diff --git a/src/Model/River.py b/src/Model/River.py index 9f5505ad..cbc86f19 100644 --- a/src/Model/River.py +++ b/src/Model/River.py @@ -336,9 +336,16 @@ class River(Graph, SQLSubModel): return self._parameters[solver] def has_current_reach(self): + if self.enable_edges_counts() == 1: + return True + return self._current_reach is not None def current_reach(self): + ee = self.enable_edges() + if len(ee) == 1: + return ee[0] + return self._current_reach def set_current_reach(self, reach): -- GitLab