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