mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-11-09 09:24:41 +00:00
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:
1 parent
db2b398dd0
commit
1d692d7e0b
5 files changed
+141
-1
No files matched your search
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user