d23p2 use pivoting

This commit is contained in:
2024-12-22 23:20:51 -08:00
parent 1f78001bd2
commit 5bb285d7e1

View File

@@ -16,13 +16,14 @@ func readInput(_ filePath: String) throws -> Network {
func bronkerbosch(
_ network: Network, r: Set<String>, p: Set<String>, x: Set<String>
) -> Set<String>? {
if p.count == 0 && x.count == 0 {
return r
if p.count == 0 {
return x.count == 0 ? r : nil
}
var maxClique: Set<String>? = nil
var nextP = p
var nextX = x
for v in p {
let u = p.union(x).first! // can also choose highest degree node
for v in p.subtracting(network[u]!) {
if let clique = bronkerbosch(network,
r: r.union([v]),
p: nextP.intersection(network[v]!),