I'm trying to implement a code of improvement of Karger's algorithm for finding a min-cut in a graph. I've an array of vertices and a matrix M, where M_ij are numbers of edges betwen vertices i and j. All algorithm uses a double recursion, if number of vertices isn't smaller than 6 vertices. But how I should solve it?
cuts=[]
def rekursion(M, vertices, n):
global cuts
t = len(vertices)
if t<=6:
n, vertices0, M0 = min_cut_part(M, vertices, 2, n) #makes Karger's algorithm till 2 vertices remains
cuts.append(int(max(map(max, M0)))) #adds the only none-zero element of matrix, which is actually a cut
return cuts
else:
t = int(1+t/np.sqrt(2))
n, vertices1, M1 = min_cut_part(M, vertices, t, n)
n, vertices2, M2 = min_cut_part(M, vertices, t, n)
rekursion(M1, vrcholy1, n)
rekursion(M2, vrcholy2, n)
def fast_min_cut(edges):
n, verices, M = matrix_vertices(edges) #creates a matrix representing edges
rekursion(M, vertices, n)
print("cuts:",cuts)
print("min-cut:",min(cuts))
I already found out, that I must use global cuts
. But still if I run a code, the result is as follows:result Probably the recursion always use the same inter-graph..
Please, would you help me, how to solve it?