Add error check to kruskals
This commit is contained in:
parent
bc1609c549
commit
b526c648c4
@ -2,7 +2,7 @@ from sys import argv
|
||||
from pathlib import Path
|
||||
from math import sin, cos, pi
|
||||
|
||||
from common import printc, replaceContent
|
||||
from common import printc, printerr, replaceContent
|
||||
|
||||
class Matrix:
|
||||
""" Adjacency matrix which supports 0 and 1 """
|
||||
@ -127,6 +127,10 @@ class Graph:
|
||||
edges = []
|
||||
connected_subgraphs = [set(v) for v in self.nodes]
|
||||
|
||||
if not all(n in ''.join(x+y for x,y in self.edges) for n in self.nodes):
|
||||
printerr('Not all nodes are connected. There is no spanning tree to be made')
|
||||
return
|
||||
|
||||
def find_subgraph_containing(v):
|
||||
return [x for x in connected_subgraphs if v in x][0]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user