public static Set getNeighbors(int vertex, List<Set> allSets) { Set neighbors = new Set(); for (int i = 0; i < allSets[vertex - 1].Size; i++) neighbors.insert(allSets[vertex - 1][i]); return neighbors; }
public static bool compareEqual(Set a, Set b) { bool isEqual = true; if (a.Size != b.Size) return false; for (int i = 0; i < a.Size; i++) { if (a[i] != b[i]) isEqual = false; } return isEqual; }
//public static int numOfRowsAndCols; public static void findMaximalCliques(Set R, Set P, Set X, ref List<Set> cliqueSets, List<Set> adjacentVertices, int numOfRowsAndCols) { if (P.isEmpty() && X.isEmpty()) { Set newSet = new Set(numOfRowsAndCols); for (int i = 0; i < R.Size; i++) newSet.insert(1, R[i] - 1); if (cliqueSets.Count == 0) // if empty cliqueSets.Add(newSet); bool inClique = false; for (int i = 0; i < cliqueSets.Count; i++) { if (Set.compareEqual(cliqueSets[i], newSet)) { inClique = true; break; } } if (!inClique) cliqueSets.Add(newSet); return; } for (int i = 0; i < P.Size; i++) { int vertex = P[i]; Set v = new Set(); Set neighbors = Set.getNeighbors(vertex, adjacentVertices); v.insert(vertex); findMaximalCliques(Set.unionSets(R, v), Set.intersectionSets(P, neighbors), Set.intersectionSets(X, neighbors), ref cliqueSets, adjacentVertices, numOfRowsAndCols); X = Set.unionSets(X, v); } }
public static Set intersectionSets(Set setA, Set setB) { Set newSet = new Set(); for (int i = 0; i < setA.Size; i++) { bool inSet = false; for (int j = 0; j < setB.Size; j++) { if (setA[i] == setB[j]) { inSet = true; break; } } if (inSet) newSet.insert(setA[i]); } return newSet; }
public Set relativeComplement(Set setB) { Set newSet = new Set(); for (int i = 0; i < Size; i++) { bool inSet = false; for (int j = 0; j < setB.Size; j++) { if (setArray[i] == setB[j]) { inSet = true; break; } } if (!inSet) newSet.insert(setArray[i]); } return newSet; }