def countOptRowSums(A, num_sets, cover=0): if cover == 0: S = SetCoverProblem(A, num_sets) cover_sets = S.get_cover_sets("glpk") else: cover_sets = filter(lambda S : S & cover != 0, get_sets(num_sets)) newA = [[0 for i in range(len(cover_sets))] for a in A] for i in range(len(A)): a = A[i] for j in range(len(cover_sets)): s = cover_sets[j] newA[i][j] = A[i][s] optRowSums = row_sums(newA) return [optRowSums.count(i) for i in range(1, len(cover_sets) + 1)]
def countOptColUniqueSums(A, numSets, cover=0): if cover == 0: S = SetCoverProblem(A, numSets) cover_sets = S.get_cover_sets("glpk") else: cover_sets = filter(lambda S : S & cover != 0, get_sets(num_sets)) newA = [[0 for i in range(len(cover_sets))] for a in A] for i in range(len(A)): a = A[i] for j in range(len(cover_sets)): s = cover_sets[j] newA[i][j] = A[i][s] uniquelyCovered = [a for a in newA if sum(a) == 1] for i in range(len(cover_sets)): k = 0 for a in uniquelyCovered: if a[i] == 1: k += 1 print k