ruvector-mincut 2.0.6

World's first subpolynomial dynamic min-cut: self-healing networks, AI optimization, real-time graph analysis
Documentation
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# Troubleshooting Guide

[← Back to Index]README.md | [Previous: API Reference]07-api-reference.md

---

## Quick Diagnosis Flowchart

```mermaid
flowchart TD
    A[Issue Encountered] --> B{Type of Issue?}

    B -->|Compilation| C[Compilation Errors]
    B -->|Runtime| D[Runtime Errors]
    B -->|Performance| E[Performance Issues]
    B -->|Results| F[Unexpected Results]

    C --> C1[Check feature flags]
    C --> C2[Version compatibility]
    C --> C3[Missing dependencies]

    D --> D1[Memory issues]
    D --> D2[Edge not found]
    D --> D3[Graph disconnected]

    E --> E1[Algorithm selection]
    E --> E2[Graph size tuning]
    E --> E3[Caching strategies]

    F --> F1[Verify graph construction]
    F --> F2[Check edge weights]
    F --> F3[Understand approximation]
```

---

## 1. Compilation Errors

### Feature Flag Issues

**Error**: `use of undeclared type MonitorBuilder`

```
error[E0433]: failed to resolve: use of undeclared type `MonitorBuilder`
```

**Solution**: Enable the `monitoring` feature:

```toml
[dependencies]
ruvector-mincut = { version = "0.2", features = ["monitoring"] }
```

---

**Error**: `use of undeclared type CompactCoreState`

**Solution**: Enable the `agentic` feature:

```toml
[dependencies]
ruvector-mincut = { version = "0.2", features = ["agentic"] }
```

---

### Feature Flag Reference

| Type/Feature | Required Feature Flag |
|--------------|----------------------|
| `MonitorBuilder`, `MinCutMonitor` | `monitoring` |
| `CompactCoreState`, `BitSet256` | `agentic` |
| `SparseGraph` | `approximate` |
| SIMD optimizations | `simd` |
| WASM support | `wasm` |

### Version Compatibility

**Error**: `the trait bound is not satisfied`

Check your dependency versions are compatible:

```toml
[dependencies]
ruvector-mincut = "0.2"
ruvector-core = "0.1.2"   # Must be compatible
ruvector-graph = "0.1.2"  # If using integration feature
```

---

## 2. Runtime Errors

### EdgeExists Error

**Error**: `EdgeExists(1, 2)` when inserting an edge

```rust
// ❌ This will fail - edge already exists
mincut.insert_edge(1, 2, 1.0)?;
mincut.insert_edge(1, 2, 2.0)?;  // Error!
```

**Solution**: Check if edge exists first, or delete before reinserting:

```rust
// ✅ Option 1: Delete first
let _ = mincut.delete_edge(1, 2);  // Ignore if not found
mincut.insert_edge(1, 2, 2.0)?;

// ✅ Option 2: Check existence (if your API supports it)
if !mincut.has_edge(1, 2) {
    mincut.insert_edge(1, 2, 1.0)?;
}
```

### EdgeNotFound Error

**Error**: `EdgeNotFound(3, 4)` when deleting

```rust
// ❌ Edge doesn't exist
mincut.delete_edge(3, 4)?;  // Error!
```

**Solution**: Use pattern matching to handle gracefully:

```rust
// ✅ Handle gracefully
match mincut.delete_edge(3, 4) {
    Ok(new_cut) => println!("New min cut: {}", new_cut),
    Err(MinCutError::EdgeNotFound(_, _)) => {
        println!("Edge already removed, continuing...");
    }
    Err(e) => return Err(e.into()),
}
```

### Disconnected Graph

**Issue**: Min cut value is 0

```rust
let mincut = MinCutBuilder::new()
    .with_edges(vec![
        (1, 2, 1.0),
        (3, 4, 1.0),  // Separate component!
    ])
    .build()?;

assert_eq!(mincut.min_cut_value(), 0.0);  // Zero because disconnected
```

**Solution**: Ensure your graph is connected, or handle disconnected case:

```rust
if !mincut.is_connected() {
    println!("Warning: Graph has {} components",
             mincut.component_count());
    // Handle each component separately
}
```

---

## 3. Performance Issues

### Slow Insert/Delete Operations

**Symptom**: Operations taking longer than expected

```mermaid
graph LR
    A[Slow Operations] --> B{Check Graph Size}
    B -->|< 10K vertices| C[Normal - check algorithm]
    B -->|10K-100K| D[Consider approximate mode]
    B -->|> 100K| E[Use ApproxMinCut]
```

**Solutions**:

1. **Use approximate mode for large graphs**:
```rust
// Instead of exact mode
let mincut = MinCutBuilder::new()
    .approximate(0.1)  // 10% approximation
    .with_edges(edges)
    .build()?;
```

2. **Use batch operations**:
```rust
// ❌ Slow - many individual operations
for (u, v, w) in edges {
    mincut.insert_edge(u, v, w)?;
}

// ✅ Fast - batch operation
mincut.batch_insert_edges(&edges);
```

3. **For worst-case guarantees, use PolylogConnectivity**:
```rust
// O(log³ n) worst-case per operation
let mut conn = PolylogConnectivity::new();
for (u, v) in edges {
    conn.insert_edge(u, v);
}
```

### Memory Issues

**Symptom**: High memory usage or OOM errors

**Solutions**:

1. **Use approximate mode** (reduces edges via sparsification):
```rust
let mincut = MinCutBuilder::new()
    .approximate(0.1)  // Sparsifies to O(n log n / ε²) edges
    .build()?;
```

2. **For WASM/embedded, use compact structures**:
```rust
#[cfg(feature = "agentic")]
{
    // 6.7KB per core - verified at compile time
    let state = CompactCoreState::new();
}
```

3. **Process in batches for very large graphs**:
```rust
// Process graph in chunks
for chunk in graph_chunks.iter() {
    let partial = MinCutBuilder::new()
        .with_edges(chunk)
        .build()?;
    // Aggregate results
}
```

### Query Performance

**Symptom**: `min_cut_value()` is slow

**Explanation**: First query triggers computation; subsequent queries are O(1):

```rust
let mincut = MinCutBuilder::new()
    .with_edges(edges)
    .build()?;

// First query - triggers full computation
let cut1 = mincut.min_cut_value();  // May take time

// Subsequent queries - O(1) cached
let cut2 = mincut.min_cut_value();  // Instant
```

---

## 4. Unexpected Results

### Min Cut Value Seems Wrong

**Checklist**:

1. **Verify edge weights are correct**:
```rust
// Weight matters! This is different from weight 1.0
mincut.insert_edge(1, 2, 10.0)?;
```

2. **Check for duplicate edges** (weights accumulate):
```rust
// These DON'T accumulate - second insert fails
mincut.insert_edge(1, 2, 5.0)?;
mincut.insert_edge(1, 2, 5.0)?;  // Error: EdgeExists
```

3. **Understand the cut definition**:
```rust
// Min cut = minimum total weight of edges to remove
// to disconnect the graph
let result = mincut.min_cut();
println!("Cut value: {}", result.value);
println!("Cut edges: {:?}", result.cut_edges);
```

### Approximate Results Vary

**Issue**: Different runs give different results

**Explanation**: Approximate mode uses randomized sparsification:

```rust
// Results may vary slightly between builds
let mincut1 = MinCutBuilder::new()
    .approximate(0.1)
    .with_edges(edges.clone())
    .build()?;

let mincut2 = MinCutBuilder::new()
    .approximate(0.1)
    .with_edges(edges)
    .build()?;

// Values are within (1±ε) of true min cut
// but may differ from each other
```

**Solution**: Use a fixed seed if reproducibility is needed:

```rust
let approx = ApproxMinCut::new(ApproxMinCutConfig {
    epsilon: 0.1,
    num_samples: 3,
    seed: 42,  // Fixed seed for reproducibility
});
```

### Partition Looks Unbalanced

**Issue**: One side of partition has most vertices

**Explanation**: Minimum cut doesn't guarantee balanced partitions:

```rust
let result = mincut.min_cut();
let (s, t) = result.partition.unwrap();

// This is valid - min cut found the minimum edges to cut
// Partition balance is NOT a constraint
println!("Partition sizes: {} vs {}", s.len(), t.len());
```

**Solution**: For balanced partitions, use `GraphPartitioner`:

```rust
use ruvector_mincut::GraphPartitioner;

let partitioner = GraphPartitioner::new(graph, 2);
let balanced = partitioner.partition();  // More balanced
```

---

## 5. WASM-Specific Issues

### WASM Build Fails

**Error**: `wasm32 target not installed`

```bash
# Install the target
rustup target add wasm32-unknown-unknown

# Build with wasm-pack
wasm-pack build --target web
```

### WASM Memory Limits

**Issue**: WASM running out of memory

**Solution**: Use compact structures and limit graph size:

```rust
// Maximum recommended for WASM
const MAX_WASM_VERTICES: usize = 50_000;

if vertices.len() > MAX_WASM_VERTICES {
    // Use approximate mode or process in chunks
    let mincut = MinCutBuilder::new()
        .approximate(0.2)  // More aggressive sparsification
        .build()?;
}
```

### Web Worker Integration

**Issue**: Main thread blocking

**Solution**: Run min-cut computation in Web Worker:

```javascript
// worker.js
import init, { WasmMinCut } from 'ruvector-mincut-wasm';

self.onmessage = async (e) => {
    await init();
    const mincut = new WasmMinCut();
    // ... compute
    self.postMessage({ result: mincut.min_cut_value() });
};
```

---

## 6. Node.js-Specific Issues

### Native Module Build Fails

**Error**: `node-gyp` or `napi` build errors

```bash
# Ensure build tools are installed
# On Ubuntu/Debian:
sudo apt-get install build-essential

# On macOS:
xcode-select --install

# On Windows:
npm install --global windows-build-tools
```

### Module Not Found

**Error**: `Cannot find module 'ruvector-mincut-node'`

```bash
# Rebuild native modules
npm rebuild

# Or reinstall
rm -rf node_modules
npm install
```

---

## 7. Common Patterns That Cause Issues

### Anti-Pattern: Not Handling Errors

```rust
// ❌ Panics on error
let cut = mincut.insert_edge(1, 2, 1.0).unwrap();

// ✅ Handle errors properly
let cut = mincut.insert_edge(1, 2, 1.0)
    .map_err(|e| {
        eprintln!("Insert failed: {}", e);
        e
    })?;
```

### Anti-Pattern: Rebuilding Instead of Updating

```rust
// ❌ Slow - rebuilds entire structure
for update in updates {
    let mincut = MinCutBuilder::new()
        .with_edges(all_edges_including_update)
        .build()?;
}

// ✅ Fast - incremental updates
let mut mincut = MinCutBuilder::new()
    .with_edges(initial_edges)
    .build()?;

for (u, v, w) in updates {
    mincut.insert_edge(u, v, w)?;
}
```

### Anti-Pattern: Ignoring Feature Requirements

```rust
// ❌ Compiles but panics at runtime if feature not enabled
#[cfg(feature = "monitoring")]
let monitor = MonitorBuilder::new().build();

// ✅ Proper feature gating
#[cfg(feature = "monitoring")]
{
    let monitor = MonitorBuilder::new().build();
    // Use monitor
}
#[cfg(not(feature = "monitoring"))]
{
    println!("Monitoring not available - enable 'monitoring' feature");
}
```

---

## 8. Getting Help

### Debug Information

When reporting issues, include:

```rust
// Print diagnostic info
println!("ruvector-mincut version: {}", ruvector_mincut::VERSION);
println!("Graph: {} vertices, {} edges",
         mincut.num_vertices(),
         mincut.num_edges());
println!("Algorithm stats: {:?}", mincut.stats());
```

### Resources

| Resource | URL |
|----------|-----|
| GitHub Issues | [github.com/ruvnet/ruvector/issues]https://github.com/ruvnet/ruvector/issues |
| Documentation | [docs.rs/ruvector-mincut]https://docs.rs/ruvector-mincut |
| Discord | [ruv.io/discord]https://ruv.io/discord |
| Stack Overflow | Tag: `ruvector` |

### Minimal Reproducible Example

When reporting bugs, provide:

```rust
use ruvector_mincut::{MinCutBuilder, MinCutError};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Minimal code that reproduces the issue
    let mincut = MinCutBuilder::new()
        .with_edges(vec![
            // Your specific edges
        ])
        .build()?;

    // The operation that fails
    let result = mincut.min_cut_value();

    println!("Result: {}", result);
    Ok(())
}
```

---

## Quick Reference: Error Codes

| Error | Cause | Solution |
|-------|-------|----------|
| `EdgeExists(u, v)` | Duplicate edge insertion | Delete first or check existence |
| `EdgeNotFound(u, v)` | Deleting non-existent edge | Use pattern matching |
| `InvalidWeight` | Zero or negative weight | Use positive weights |
| `GraphTooLarge` | Exceeds memory limits | Use approximate mode |
| `NotConnected` | Graph has multiple components | Check connectivity first |

---

<div align="center">

**Still stuck?** [Open an issue](https://github.com/ruvnet/ruvector/issues/new) with your code and error message.

[← Back to Index](README.md)

</div>