Implement progress tracking for clique finding

Introduces a mechanism for tracking progress during clique finding operations. This includes implementing a progress bar state management system, handling visibility checks, and integrating progress reporting into the clique finding logic and result processing.
This commit is contained in:
Eric Coissac committed 2026-11-03 09:26:29 +11:00
1 parent db2b398dd0
commit 1d692d7e0b
5 files changed
+141 -1

No files matched your search

+7
View File
@@ -21,6 +21,10 @@ type CliqueOptions struct {
Workers int
// Seed seeds the random vertex orders of the restarts.
Seed int64
// Progress, if set, is called with the size of the best clique each time a
// larger one is found. Calls are serialized and made while a lock is held:
// it must return quickly and must not call FindClique.
Progress func(best int)
}
// CliqueResult is the outcome of FindClique.
@@ -68,6 +72,9 @@ func FindClique(ctx context.Context, n int, filter NeighborFilter, target int, o
mutex.Lock()
if len(clique) > len(best) {
best = append(best[:0], clique...)
if opts.Progress != nil {
opts.Progress(len(best))
}
}
mutex.Unlock()
}
+20
View File
@@ -141,3 +141,23 @@ func TestFindCliqueTimeout(t *testing.T) {
t.Fatalf("invalid best clique %v", r.Clique)
}
}
func TestFindCliqueProgress(t *testing.T) {
adj := randomGraph(rand.New(rand.NewSource(4)), 40, 0.7)
var seen []int
r := FindClique(context.Background(), 40, matrixFilter(adj), 5, CliqueOptions{
Progress: func(best int) { seen = append(seen, best) },
})
if !r.Reached {
t.Fatalf("size 5 should be reached: %+v", r)
}
if len(seen) == 0 || seen[len(seen)-1] != len(r.Clique) {
t.Fatalf("progress %v does not end at the clique size %d", seen, len(r.Clique))
}
for i := 1; i < len(seen); i++ {
if seen[i] <= seen[i-1] {
t.Fatalf("progress must be strictly increasing: %v", seen)
}
}
}