Add error check to kruskals

master
Oystein Kristoffer Tveit 2021-05-17 23:37:23 +02:00
parent bc1609c549
commit b526c648c4
1 changed files with 5 additions and 1 deletions

View File

@ -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]