graph LR
0((0)) --- 1((1))
1 --- 2((2))
2 --- 3((3))
3 --- 0
style 0 fill:#bf616a,stroke:#2e3440,color:#fff
style 1 fill:#5e81ac,stroke:#2e3440,color:#fff
style 2 fill:#5e81ac,stroke:#2e3440,color:#fff
style 3 fill:#5e81ac,stroke:#2e3440,color:#fff
Removing vertex 0 breaks all cycles โ tree structure remains ๐ฒ
---
### ๐ Minimum Odd Cycle Cover
- Problem
Find minimum-weight vertices covering all **odd-length cycles**.
- Why It Matters ๐ง
An odd cycle indicates the graph is **non-bipartite**. Removing odd cycles makes the graph bipartite, enabling **MAX-CUT** approximations.
```cpp
while (true) {
auto cycles = bfs_cycles(graph, coverset);
if (cycles.empty()) break;
bool found = false;
for (auto& [info, p, c] : cycles) {
if ((depth(p) - depth(c)) % 2 == 0) { // โ odd cycle check
co_yield construct_cycle(info, p, c);
found = true; break;
}
}
if (!found) break;
}
```
---
### ๐งช Test: Square + Triangle
#### Graph Structure
graph TB
subgraph "Square (even cycle)"
0((0)) --- 1((1))
1 --- 2((2))
2 --- 3((3))
3 --- 0
end
subgraph "Triangle (odd cycle)"
4((4)) --- 5((5))
5 --- 6((6))
6 --- 4
end
style 0 fill:#5e81ac,stroke:#2e3440,color:#fff
style 1 fill:#5e81ac,stroke:#2e3440,color:#fff
style 2 fill:#5e81ac,stroke:#2e3440,color:#fff
style 3 fill:#5e81ac,stroke:#2e3440,color:#fff
style 4 fill:#bf616a,stroke:#2e3440,color:#fff
style 5 fill:#bf616a,stroke:#2e3440,color:#fff
style 6 fill:#bf616a,stroke:#2e3440,color:#fff
**Odd cycle cover** should pick from {4, 5, 6} only โ the square is bipartite! โ
---
### ๐งช Test: K5 Minimality
**Complete graph $K_5$** โ 5 vertices, all 10 edges.
graph LR
0((0)) --- 1((1))
0 --- 2((2))
0 --- 3((3))
0 --- 4((4))
1 --- 2
1 --- 3
1 --- 4
2 --- 3
2 --- 4
3 --- 4
style 0 fill:#5e81ac,stroke:#2e3440,color:#fff
style 1 fill:#5e81ac,stroke:#2e3440,color:#fff
style 2 fill:#5e81ac,stroke:#2e3440,color:#fff
style 3 fill:#bf616a,stroke:#2e3440,color:#fff
style 4 fill:#bf616a,stroke:#2e3440,color:#fff
**Minimal vertex cover** has 4 vertices (any 4 cover all edges).
Reverse-delete verifies: removing any single vertex uncovers some edge. โ
---
### ๐ Test Results Summary
| Test | Problem | Vertices | Cover Size | Cost | Status |
|------|---------|----------|-----------|------|--------|
| ๐บ Triangle | Vertex Cover | 3 | 2 | 2 | โ
|
| ๐ฒ Tree | Cycle Cover | 4 | 0 | 0 | โ
|
| ๐ฆ Square+๐บ Triangle | Odd Cycle Cover | 7 | ~1 (from triangle) | 1 | โ
|
| โญ K5 | Vertex Cover | 5 | 4 | 4 | โ
|
All tests pass with **xmake** build system. ๐๏ธ
---
### ๐ง Build & Test
```bash
### Configure and build with xmake
xmake f -c -y && xmake
### Run the test suite
cd build/windows/x64/release
./test_netlistx.exe --success
```
```
Test pd_cover basic .............. โ
Test min_vertex_cover simple ..... โ
Test minimal vertex cover tri .... โ
Test cycle cover tree ............ โ
Test odd cycle cover detection ... โ
Test post-processing minimality .. โ
```
---
class: nord-light, middle, center
## ๐ Summary & Takeaways
---
### ๐ฏ Key Takeaways
#### What We Learned
1. **Primal-Dual** is a powerful framework for covering problems
2. **Reverse-Delete** post-processing guarantees minimality
3. **Coroutine generators** enable correct lazy enumeration in C++20
#### Algorithmic Insights
- Dual variables (gaps) guide selection decisions
- Reverse order guarantees correct minimality checks
- Generator pattern prevents stale-violation bugs
#### Implementation Highlights
- C++20 `Generator