Mage: Symplify checker.

mesh
Pierre-Antoine Rouby 2023-06-23 14:16:23 +02:00
parent c7d6605cd6
commit 4416f0d37e
1 changed files with 11 additions and 33 deletions

View File

@ -4,7 +4,6 @@ import time
from queue import Queue
from tools import flatten
from functools import reduce
from PyQt5.QtCore import QCoreApplication
@ -64,21 +63,18 @@ class MageNetworkGraphChecker(AbstractModelChecker):
if current is None:
continue
# Cut potential infinite loop on graph cycle
if current in visited:
continue
related_edges = list(
filter(
lambda e: e.node1 == current or e.node2 == current,
edges
)
)
# Get next node(s) to visite
nexts = flatten(
map(
lambda e: [e.node1, e.node2],
related_edges
filter(
lambda e: e.node1 == current or e.node2 == current,
edges
)
)
)
@ -89,10 +85,7 @@ class MageNetworkGraphChecker(AbstractModelChecker):
visited.add(current)
if len(visited) != len(nodes):
if "ok" in summary:
summary = "network_connectivity"
else:
summary = summary + "|" + "network_connectivity"
summary = "network_connectivity"
status = STATUS.ERROR
return summary, status
@ -106,21 +99,9 @@ class MageNetworkGraphChecker(AbstractModelChecker):
graph.edges()
)
)
# Get all related nodes
nodes = list(
set(
flatten(
map(
lambda e: [e.node1, e.node2],
edges
)
)
)
)
for edge in edges:
# Visite graph
# Visite graph starting from EDGE source node (INITIAL)
q = Queue()
initial = edge.node1
q.put(initial)
@ -131,6 +112,7 @@ class MageNetworkGraphChecker(AbstractModelChecker):
if current is None:
continue
# Cut potential infinite loop on subgraph cycle
if current in visited:
continue
@ -149,20 +131,16 @@ class MageNetworkGraphChecker(AbstractModelChecker):
)
)
# The initial node cannot be visited a second time where visite
# started by this node, otherelse there is a cycle in the graph
# The initial node cannot be visited a second time,
# otherelse there is a cycle in the graph
if initial in nexts:
if "ok" in summary:
summary = "cycle_detected"
else:
summary = summary + "|" + "cycle_detected"
summary = "cycle_detected"
status = STATUS.ERROR
return summary, status
for n in nexts:
q.put(n)
# Visited node
visited.add(current)
return summary, status