Commit 4416f0d3 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Mage: Symplify checker.

Showing with 11 additions and 33 deletions
+11 -33
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment