-
Notifications
You must be signed in to change notification settings - Fork 590
Expand file tree
/
Copy pathbounded_instance_demo.rs
More file actions
73 lines (61 loc) · 2.29 KB
/
Copy pathbounded_instance_demo.rs
File metadata and controls
73 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Demonstration of BoundedInstance using DeterministicLocalKCut
//!
//! This example shows how to use the production BoundedInstance
//! implementation with the LocalKCut oracle.
use ruvector_mincut::prelude::*;
fn main() {
println!("BoundedInstance Demo");
println!("===================\n");
// Create a dynamic graph
let graph = DynamicGraph::new();
// Create a bounded instance for range [1, 5]
let mut instance = BoundedInstance::init(&graph, 1, 5);
println!("Created BoundedInstance with bounds: {:?}", instance.bounds());
// Add a simple path graph: 0 -- 1 -- 2
println!("\nAdding path graph: 0 -- 1 -- 2");
instance.apply_inserts(&[
(0, 0, 1),
(1, 1, 2),
]);
// Query the minimum cut
match instance.query() {
InstanceResult::ValueInRange { value, witness } => {
println!("Found cut with value: {}", value);
println!("Witness seed: {}", witness.seed());
println!("Witness cardinality: {}", witness.cardinality());
}
InstanceResult::AboveRange => {
println!("Cut value is above range");
}
}
// Add edge to form a cycle: 0 -- 1 -- 2 -- 0
println!("\nAdding edge to form cycle: 2 -- 0");
instance.apply_inserts(&[(2, 2, 0)]);
// Query again
match instance.query() {
InstanceResult::ValueInRange { value, witness } => {
println!("Found cut with value: {}", value);
println!("Witness seed: {}", witness.seed());
println!("Witness cardinality: {}", witness.cardinality());
}
InstanceResult::AboveRange => {
println!("Cut value is above range");
}
}
// Delete an edge to break the cycle
println!("\nDeleting edge: 1 -- 2");
instance.apply_deletes(&[(1, 1, 2)]);
// Query final state
match instance.query() {
InstanceResult::ValueInRange { value, witness } => {
println!("Found cut with value: {}", value);
println!("Witness seed: {}", witness.seed());
}
InstanceResult::AboveRange => {
println!("Cut value is above range");
}
}
// Get certificate
let cert = instance.certificate();
println!("\nCertificate has {} LocalKCut responses", cert.localkcut_responses.len());
}