mirror of https://gitlab.com/pamhyr/pamhyr2
Mage: Symplify checker.
parent
c7d6605cd6
commit
4416f0d37e
|
|
@ -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):
|
||||||
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):
|
||||||
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):
|
||||||
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):
|
||||||
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):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue