ogdf-py 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/.github/workflows/build-publish.yml +8 -3
  2. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/.github/workflows/ci.yml +2 -2
  3. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/CHANGELOG.md +18 -0
  4. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/PKG-INFO +3 -3
  5. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/README.md +2 -2
  6. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/docs/coverage.md +40 -12
  7. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/docs/getting-started.md +1 -1
  8. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/docs/index.md +1 -1
  9. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/pyproject.toml +1 -1
  10. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/__init__.py +1 -1
  11. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/bind_algorithms.cpp +248 -0
  12. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/bind_layouts.cpp +107 -1
  13. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/tests/test_algorithms.py +188 -0
  14. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/tests/test_layouts.py +58 -0
  15. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/uv.lock +1 -1
  16. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/.gitignore +0 -0
  17. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/CMakeLists.txt +0 -0
  18. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/LICENSE +0 -0
  19. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/Makefile +0 -0
  20. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/README.md +0 -0
  21. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/_common.py +0 -0
  22. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/algorithms_visual.py +0 -0
  23. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/gallery.py +0 -0
  24. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/generators_zoo.py +0 -0
  25. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/io_roundtrip.py +0 -0
  26. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/layouts_gallery.py +0 -0
  27. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/run_all.py +0 -0
  28. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/demos/styling_showcase.py +0 -0
  29. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/mkdocs.yml +0 -0
  30. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/scripts/bootstrap_ogdf.py +0 -0
  31. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/_core.cpp +0 -0
  32. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/bind_generators.cpp +0 -0
  33. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/bind_graph.cpp +0 -0
  34. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/bind_io.cpp +0 -0
  35. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/bindings.h +0 -0
  36. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/src/ogdf/py.typed +0 -0
  37. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/tests/test_generators.py +0 -0
  38. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/tests/test_ogdf.py +0 -0
  39. {ogdf_py-0.2.0 → ogdf_py-0.3.0}/tests/test_styling.py +0 -0
@@ -22,9 +22,9 @@ concurrency:
22
22
  cancel-in-progress: true
23
23
 
24
24
  env:
25
- # Build CPython 3.10-3.13; skip musllinux (OGDF is bootstrapped on
25
+ # Build CPython 3.10-3.14; skip musllinux (OGDF is bootstrapped on
26
26
  # manylinux/glibc) and PyPy.
27
- CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-*"
27
+ CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-*"
28
28
  CIBW_SKIP: "*-musllinux_* pp*"
29
29
  # Clone + build OGDF once per platform before building any wheels. On Linux
30
30
  # this runs inside the manylinux container (git present; install cmake).
@@ -32,6 +32,9 @@ env:
32
32
  (command -v cmake >/dev/null 2>&1 || pipx install cmake) &&
33
33
  python3 scripts/bootstrap_ogdf.py
34
34
  CIBW_BEFORE_ALL_MACOS: python3 scripts/bootstrap_ogdf.py
35
+ # windows-latest ships git, CMake, and MSVC; the bootstrap builds OGDF with
36
+ # the MSVC toolchain.
37
+ CIBW_BEFORE_ALL_WINDOWS: python scripts/bootstrap_ogdf.py
35
38
  # Exercise each wheel end-to-end (import + layouts + I/O).
36
39
  CIBW_TEST_REQUIRES: pytest
37
40
  CIBW_TEST_COMMAND: pytest {project}/tests -v
@@ -75,6 +78,8 @@ jobs:
75
78
  - os: macos-14
76
79
  arch: arm64
77
80
  macos_target: "11.0"
81
+ - os: windows-latest
82
+ arch: AMD64
78
83
  env:
79
84
  MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos_target }}
80
85
  steps:
@@ -82,7 +87,7 @@ jobs:
82
87
 
83
88
  # Cache the cloned+built OGDF per platform/arch so reruns skip the build.
84
89
  - name: Cache OGDF
85
- uses: actions/cache@v4
90
+ uses: actions/cache@v6
86
91
  with:
87
92
  path: thirdparty/ogdf
88
93
  key: ogdf-${{ runner.os }}-${{ matrix.arch }}-${{ hashFiles('scripts/bootstrap_ogdf.py') }}
@@ -24,7 +24,7 @@ jobs:
24
24
  # Cache the cloned+built OGDF so most runs skip the ~2 min build.
25
25
  # Keyed on the bootstrap script (which pins the OGDF tag).
26
26
  - name: Cache OGDF
27
- uses: actions/cache@v4
27
+ uses: actions/cache@v6
28
28
  with:
29
29
  path: thirdparty/ogdf
30
30
  key: ogdf-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/bootstrap_ogdf.py') }}
@@ -71,7 +71,7 @@ jobs:
71
71
  # windows-latest ships git, CMake, and MSVC; the bootstrap builds OGDF
72
72
  # with the MSVC toolchain into thirdparty/ogdf/build/Release.
73
73
  - name: Cache OGDF
74
- uses: actions/cache@v4
74
+ uses: actions/cache@v6
75
75
  with:
76
76
  path: thirdparty/ogdf
77
77
  key: ogdf-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('scripts/bootstrap_ogdf.py') }}
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.3.0]
10
+
11
+ ### Added
12
+
13
+ - Planar layouts: `FPPLayout`, `PlanarStraightLayout`, `PlanarDrawLayout`, and `MixedModelLayout` - straight-line and mixed-model planar grid drawings, completing the planar-drawing family alongside `SchnyderLayout`. Each validates that the input is a simple planar graph with at least 3 nodes.
14
+
15
+ - Shortest paths: `a_star_search`, point-to-point A* with an optional admissible heuristic; returns the path length and edges, or `None` if the target is unreachable.
16
+
17
+ - Crossing minimization: `crossing_number` (heuristic minimum crossings via the subgraph planarizer) and `insert_edges` (routes a chosen set of edges through the otherwise-planar rest of the graph and returns, per edge, the original edges it crosses).
18
+
19
+ - Flow / cut and connectivity: `min_st_cut` (directed or undirected s-t minimum cut, returning the value and the cut edges) and `node_connectivity` / `edge_connectivity` (global and local/Menger k-connectivity).
20
+
21
+ - Documentation: expanded the coverage checklist with a priority roadmap.
22
+
9
23
  ## [0.2.0]
10
24
 
11
25
  ### Added
@@ -24,10 +38,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
24
38
 
25
39
  - Predicates and small algorithms: `is_two_edge_connected`, `is_regular`, `is_arborescence`, `triangulate`, `make_bimodal`, and `bfs_distances` (unweighted single-source distances).
26
40
 
41
+ - Windows support: the release workflow now builds Windows (AMD64) wheels alongside Linux and macOS, and the wheel matrix covers CPython 3.10-3.14.
42
+
27
43
  ### Fixed
28
44
 
29
45
  - Removed the persistent CMake `build-dir` from `pyproject.toml`. Sharing it between editable installs and wheel builds could leave stale objects, so a `uv build --wheel` sometimes omitted recently-added functions. Each build now uses a fresh directory (OGDF is prebuilt, so this stays fast).
30
46
 
47
+ - MSVC build: replaced the non-standard `M_PI` (undefined on MSVC) with an explicit constant so the extension compiles on Windows.
48
+
31
49
  ## [0.1.1]
32
50
 
33
51
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ogdf-py
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Python bindings for the Open Graph Drawing Framework (OGDF), built with nanobind.
5
5
  Keywords: nanobind,python,extension
6
6
  Author-Email: Shakeeb Alireza <shakfu@users.noreply.github.com>
@@ -70,9 +70,9 @@ n = ogdf.connected_components(g, component) # -> number of components
70
70
 
71
71
  - **Attributes:** `GraphAttributes` with coordinates, size, labels, and full styling (colors, shapes, fill patterns, stroke, edge arrows, and bends).
72
72
 
73
- - **Layouts:** `SugiyamaLayout` (layered), `FMMMLayout` / `GEMLayout` / `SpringEmbedderKK` / `MultilevelLayout` (force-directed), `StressMinimization` / `PivotMDS` (stress/MDS), `PlanarizationLayout` (with optional orthogonal routing), `SchnyderLayout` (planar straight-line), `TreeLayout` / `RadialTreeLayout` / `BalloonLayout`, `CircularLayout`, `LinearLayout` (arc diagram), `TutteLayout` (convex planar), and `DominanceLayout` / `VisibilityLayout` (upward, for DAGs).
73
+ - **Layouts:** `SugiyamaLayout` (layered), `FMMMLayout` / `GEMLayout` / `SpringEmbedderKK` / `MultilevelLayout` (force-directed), `StressMinimization` / `PivotMDS` (stress/MDS), `PlanarizationLayout` (with optional orthogonal routing), `SchnyderLayout` / `FPPLayout` / `PlanarStraightLayout` / `PlanarDrawLayout` / `MixedModelLayout` (planar straight-line and mixed-model), `TreeLayout` / `RadialTreeLayout` / `BalloonLayout`, `CircularLayout`, `LinearLayout` (arc diagram), `TutteLayout` (convex planar), and `DominanceLayout` / `VisibilityLayout` (upward, for DAGs).
74
74
 
75
- - **Algorithms:** connectivity and structure tests (`is_connected`, `is_biconnected`, `is_bipartite`, `is_acyclic`, `is_planar`, ...), components, cut vertices and bridges, separation pairs and SPQR-tree summary, topological numbering, shortest paths (`dijkstra`, `bellman_ford`), minimum spanning tree, maximum flow, minimum-cost flow, global minimum cut, matching (bipartite and maximum-weight), node coloring, minimum Steiner tree, maximal planar subgraph, and planar embedding.
75
+ - **Algorithms:** connectivity and structure tests (`is_connected`, `is_biconnected`, `is_bipartite`, `is_acyclic`, `is_planar`, ...), node/edge k-connectivity (`node_connectivity`, `edge_connectivity`), components, cut vertices and bridges, separation pairs and SPQR-tree summary, topological numbering, shortest paths (`dijkstra`, `bellman_ford`, `a_star_search`), minimum spanning tree, maximum flow, minimum-cost flow, global minimum cut and s-t minimum cut (`min_st_cut`), matching (bipartite and maximum-weight), node coloring, minimum Steiner tree, planar embedding, maximal planar subgraph, crossing minimization (`crossing_number`), and edge-insertion routing (`insert_edges`).
76
76
 
77
77
  - **Generators:** classic graphs (complete, bipartite, wheel, cube, grid, Petersen, circulant, k-partite, globe, lattice), graph products (cartesian, tensor, strong, lexicographical), operations (union, complement, suspension), and random models (Erdos-Renyi, regular, planar, triconnected, Watts-Strogatz, preferential attachment, Chung-Lu, Waxman, geometric, series-parallel DAG, hierarchy).
78
78
 
@@ -51,9 +51,9 @@ n = ogdf.connected_components(g, component) # -> number of components
51
51
 
52
52
  - **Attributes:** `GraphAttributes` with coordinates, size, labels, and full styling (colors, shapes, fill patterns, stroke, edge arrows, and bends).
53
53
 
54
- - **Layouts:** `SugiyamaLayout` (layered), `FMMMLayout` / `GEMLayout` / `SpringEmbedderKK` / `MultilevelLayout` (force-directed), `StressMinimization` / `PivotMDS` (stress/MDS), `PlanarizationLayout` (with optional orthogonal routing), `SchnyderLayout` (planar straight-line), `TreeLayout` / `RadialTreeLayout` / `BalloonLayout`, `CircularLayout`, `LinearLayout` (arc diagram), `TutteLayout` (convex planar), and `DominanceLayout` / `VisibilityLayout` (upward, for DAGs).
54
+ - **Layouts:** `SugiyamaLayout` (layered), `FMMMLayout` / `GEMLayout` / `SpringEmbedderKK` / `MultilevelLayout` (force-directed), `StressMinimization` / `PivotMDS` (stress/MDS), `PlanarizationLayout` (with optional orthogonal routing), `SchnyderLayout` / `FPPLayout` / `PlanarStraightLayout` / `PlanarDrawLayout` / `MixedModelLayout` (planar straight-line and mixed-model), `TreeLayout` / `RadialTreeLayout` / `BalloonLayout`, `CircularLayout`, `LinearLayout` (arc diagram), `TutteLayout` (convex planar), and `DominanceLayout` / `VisibilityLayout` (upward, for DAGs).
55
55
 
56
- - **Algorithms:** connectivity and structure tests (`is_connected`, `is_biconnected`, `is_bipartite`, `is_acyclic`, `is_planar`, ...), components, cut vertices and bridges, separation pairs and SPQR-tree summary, topological numbering, shortest paths (`dijkstra`, `bellman_ford`), minimum spanning tree, maximum flow, minimum-cost flow, global minimum cut, matching (bipartite and maximum-weight), node coloring, minimum Steiner tree, maximal planar subgraph, and planar embedding.
56
+ - **Algorithms:** connectivity and structure tests (`is_connected`, `is_biconnected`, `is_bipartite`, `is_acyclic`, `is_planar`, ...), node/edge k-connectivity (`node_connectivity`, `edge_connectivity`), components, cut vertices and bridges, separation pairs and SPQR-tree summary, topological numbering, shortest paths (`dijkstra`, `bellman_ford`, `a_star_search`), minimum spanning tree, maximum flow, minimum-cost flow, global minimum cut and s-t minimum cut (`min_st_cut`), matching (bipartite and maximum-weight), node coloring, minimum Steiner tree, planar embedding, maximal planar subgraph, crossing minimization (`crossing_number`), and edge-insertion routing (`insert_edges`).
57
57
 
58
58
  - **Generators:** classic graphs (complete, bipartite, wheel, cube, grid, Petersen, circulant, k-partite, globe, lattice), graph products (cartesian, tensor, strong, lexicographical), operations (union, complement, suspension), and random models (Erdos-Renyi, regular, planar, triconnected, Watts-Strogatz, preferential attachment, Chung-Lu, Waxman, geometric, series-parallel DAG, hierarchy).
59
59
 
@@ -2,9 +2,33 @@
2
2
 
3
3
  This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living checklist: `ogdf-py` is a **curated subset**, so most of OGDF is intentionally excluded.
4
4
 
5
- **Legend:** `[x]` = bound and available in Python, `[ ]` = not (yet) bound.
5
+ **Legend:** `[x]` = bound and available in Python, `[ ]` = not (yet) bound. Unbound items scheduled for the next additions may be tagged `**(priority)**`; see the [Priority roadmap](#priority-roadmap).
6
6
 
7
- **Scope rationale.** The binding targets OGDF's genuine differentiators for Python users - **graph drawing** and **planarity** - plus a **core set of common graph algorithms** (even where these overlap networkx/scipy) for a self-contained experience. Exotic or specialized algorithms, and large subsystems (clustering, UML, hypergraphs, upward planarity), are excluded unless there is concrete demand. Contributions that move an item from `[ ]` to `[x]` are welcome.
7
+ **Scope rationale.** The binding targets OGDF's genuine differentiators for Python users - **graph drawing** and **planarity** - plus a **core set of common graph algorithms** (even where these overlap networkx/scipy) for a self-contained experience. Because that common-algorithm core is explicitly in scope, canonical routines users reach for next to what is already bound - notably **A\*** (alongside `dijkstra`/`bellman_ford`) - are treated as in-scope gaps to close, not as exotic exclusions. That said, the core covers algorithms OGDF actually implements well: **PageRank** is intentionally omitted because OGDF only ships an undirected, [0, 1]-normalized variant that is degree-dominated and not the canonical directed measure (see below). Genuinely exotic or specialized algorithms, and large subsystems (clustering, UML, hypergraphs, cluster planarity, SEFE), are excluded unless there is concrete demand. Contributions that move an item from `[ ]` to `[x]` are welcome.
8
+
9
+ ## Priority roadmap
10
+
11
+ Highest-value gaps given the drawing + planarity focus and the common-algorithm core. Tiers 1 and 2 are complete; nothing is currently scheduled. Future priorities, when chosen, are tagged `**(priority)**` in the sections below.
12
+
13
+ **Done (Tier 1):**
14
+
15
+ 1. **Planar straight-line grid layouts** - `FPPLayout`, `PlanarStraightLayout`, `PlanarDrawLayout`, `MixedModelLayout`, completing the planar-drawing family alongside `SchnyderLayout`.
16
+
17
+ 2. **Common shortest-path gap** - `a_star_search`. (PageRank was evaluated and dropped: OGDF's `BasicPageRank` is undirected and [0, 1]-normalized, so it is degree-dominated and not canonical directed PageRank - little unique value over `node.degree`. Directed PageRank is left to networkx/igraph rather than hand-rolled here.)
18
+
19
+ 3. **Crossing number** - `crossing_number`, the heuristic minimum computed by the subgraph planarizer, now a standalone call rather than a hidden step in `PlanarizationLayout`.
20
+
21
+ **Done (Tier 2):**
22
+
23
+ 4. **s-t min cut** (`min_st_cut`, directed or undirected) and **k-connectivity** (`node_connectivity`, `edge_connectivity`, global and local) - completing the flow/cut and connectivity families that were only partially bound.
24
+
25
+ **Done (Tier 2, follow-on):**
26
+
27
+ 5. **Edge-insertion routing** (`insert_edges`) - routes a chosen set of edges through the rest of the graph (which must be planar once they are removed) and returns, per edge, the original edges it crosses. Uses the variable-embedding inserter with no remove-reinsert, so crossings are attributed cleanly to the inserted edges rather than re-routed across the whole drawing.
28
+
29
+ **Not scheduled:**
30
+
31
+ - Planarity depth: combinatorial embedding + dual graph, upward planarity testing, planar separators.
8
32
 
9
33
  ## Graph model and attributes
10
34
 
@@ -56,17 +80,17 @@ This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living
56
80
 
57
81
  - [x] `RadialTreeLayout`
58
82
 
59
- - [ ] `BertaultLayout`
83
+ - [ ] `BertaultLayout` (deprioritized: five force-directed layouts already bound)
60
84
 
61
- - [ ] `DavidsonHarelLayout`
85
+ - [ ] `DavidsonHarelLayout` (deprioritized: force-directed, marginal over existing)
62
86
 
63
87
  - [x] `MultilevelLayout` / `ModularMultilevelMixer`
64
88
 
65
- - [ ] `FastMultipoleEmbedder`
89
+ - [ ] `FastMultipoleEmbedder` (deprioritized: FMMM already covers large-graph force layout)
66
90
 
67
- - [ ] `NodeRespecterLayout`
91
+ - [ ] `NodeRespecterLayout` (bind on demand: only distinct hook is respecting real node sizes to avoid overlap)
68
92
 
69
- - [ ] `PlanarStraightLayout` / `PlanarDrawLayout` / `FPPLayout`
93
+ - [x] Planar straight-line grid layouts: `FPPLayout`, `PlanarStraightLayout`, `PlanarDrawLayout`, `MixedModelLayout` (companions to `SchnyderLayout`)
70
94
 
71
95
  - [x] `TutteLayout`
72
96
 
@@ -100,6 +124,8 @@ This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living
100
124
 
101
125
  - [x] Triconnectivity: separation pair (`separation_pair`) and SPQR-tree summary (`spqr_tree_summary`)
102
126
 
127
+ - [x] node/edge k-connectivity values, global and local/Menger (`node_connectivity`, `edge_connectivity`)
128
+
103
129
  - [ ] BC-trees / decomposition
104
130
 
105
131
  ### Planarity
@@ -110,7 +136,9 @@ This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living
110
136
 
111
137
  - [x] Maximal planar subgraph (`maximal_planar_subgraph`)
112
138
 
113
- - [ ] Edge insertion / crossing minimization (as standalone API)
139
+ - [x] Crossing number (`crossing_number`, heuristic via subgraph planarizer + edge insertion)
140
+
141
+ - [x] Edge insertion routing (`insert_edges`, routes edges through the fixed planar rest and returns the edges each one crosses)
114
142
 
115
143
  - [ ] Upward planarity testing
116
144
 
@@ -120,7 +148,7 @@ This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living
120
148
 
121
149
  - [x] `dijkstra` (single-source, weighted)
122
150
 
123
- - [ ] A* search
151
+ - [x] A* search (`a_star_search`, point-to-point; optional admissible heuristic)
124
152
 
125
153
  - [x] Bellman-Ford (`bellman_ford`, negative weights)
126
154
 
@@ -138,7 +166,7 @@ This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living
138
166
 
139
167
  - [x] Min-cost flow (`min_cost_flow`, Reinelt)
140
168
 
141
- - [ ] Min s-t cut variants
169
+ - [x] s-t min cut, directed or undirected (`min_st_cut`, returns value and cut edges; companion to global `min_cut` + `max_flow`)
142
170
 
143
171
  - [ ] Nagamochi-Ibaraki min cut
144
172
 
@@ -154,13 +182,13 @@ This page tracks what OGDF functionality is exposed by `ogdf-py`. It is a living
154
182
 
155
183
  - [ ] Other coloring heuristics (Berger-Rompel, Johnson, Wigderson, ...)
156
184
 
157
- ### Excluded algorithm families
185
+ ### Specialized / excluded algorithm families
158
186
 
159
187
  - [x] Steiner trees (`steiner_tree`, Mehlhorn; OGDF has ~9 implementations)
160
188
 
161
189
  - [ ] Graph spanners (Baswana-Sen, Berman, Elkin-Neiman, ...)
162
190
 
163
- - [ ] PageRank
191
+ - [ ] PageRank (OGDF's `BasicPageRank` is undirected and min-max normalized to [0, 1] - degree-dominated and not canonical directed PageRank; use networkx/igraph for the standard measure)
164
192
 
165
193
  - [ ] Voronoi diagrams / convex hull
166
194
 
@@ -8,7 +8,7 @@
8
8
  pip install ogdf-py
9
9
  ```
10
10
 
11
- Wheels are available for Linux (x86_64, aarch64) and macOS (x86_64, arm64) on CPython 3.10-3.13. On other platforms pip falls back to the source distribution, which builds OGDF from source at install time (needs `git`, a C++17 compiler, and network access; Windows source builds are not supported).
11
+ Wheels are available for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (AMD64) on CPython 3.10-3.14. On platforms without a matching wheel, pip falls back to the source distribution, which builds OGDF from source at install time; this needs `git`, a C++17 compiler (MSVC works), CMake, and network access.
12
12
 
13
13
  ### From source
14
14
 
@@ -10,7 +10,7 @@ This is a **curated subset** of OGDF, not a full wrapper: enough to build graphs
10
10
  pip install ogdf-py
11
11
  ```
12
12
 
13
- Binary wheels are published for Linux (x86_64, aarch64) and macOS (x86_64, arm64) on CPython 3.10-3.13.
13
+ Binary wheels are published for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (AMD64) on CPython 3.10-3.14.
14
14
 
15
15
  ## Example
16
16
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ogdf-py"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "Python bindings for the Open Graph Drawing Framework (OGDF), built with nanobind."
5
5
  readme = "README.md"
6
6
  license = { text = "MIT" }
@@ -19,4 +19,4 @@ from ogdf import _core
19
19
  from ogdf._core import * # noqa: F403
20
20
 
21
21
  __all__ = [name for name in dir(_core) if not name.startswith("_")]
22
- __version__ = "0.2.0"
22
+ __version__ = "0.3.0"
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include <nanobind/stl/string.h>
11
11
 
12
+ #include <functional>
12
13
  #include <stdexcept>
13
14
  #include <unordered_map>
14
15
  #include <unordered_set>
@@ -18,7 +19,10 @@
18
19
  #include <ogdf/basic/extended_graph_alg.h>
19
20
  #include <ogdf/basic/simple_graph_alg.h>
20
21
  #include <ogdf/decomposition/StaticSPQRTree.h>
22
+ #include <ogdf/graphalg/AStarSearch.h>
23
+ #include <ogdf/graphalg/ConnectivityTester.h>
21
24
  #include <ogdf/graphalg/Dijkstra.h>
25
+ #include <ogdf/graphalg/MinSTCutMaxFlow.h>
22
26
  #include <ogdf/graphalg/Matching.h>
23
27
  #include <ogdf/graphalg/MatchingBlossomV.h>
24
28
  #include <ogdf/graphalg/MaxFlowGoldbergTarjan.h>
@@ -28,6 +32,10 @@
28
32
  #include <ogdf/graphalg/NodeColoringRecursiveLargestFirst.h>
29
33
  #include <ogdf/graphalg/ShortestPathAlgorithms.h>
30
34
  #include <ogdf/planarity/MaximalPlanarSubgraphSimple.h>
35
+ #include <ogdf/planarity/PlanRep.h>
36
+ #include <ogdf/planarity/PlanRepLight.h>
37
+ #include <ogdf/planarity/SubgraphPlanarizer.h>
38
+ #include <ogdf/planarity/VariableEmbeddingInserter.h>
31
39
  #include <ogdf/graphalg/ShortestPathWithBFM.h>
32
40
  #include <ogdf/graphalg/steiner_tree/EdgeWeightedGraph.h>
33
41
  #include <ogdf/graphalg/steiner_tree/EdgeWeightedGraphCopy.h>
@@ -70,6 +78,60 @@ void register_algorithms(nb::module_& m) {
70
78
  m.def("is_regular", [](const Graph& g, int d) { return isRegular(g, d); },
71
79
  "graph"_a, "degree"_a, "True if every node has degree d.");
72
80
 
81
+ // ---------------------------------------------------------------- //
82
+ // k-connectivity (node / edge) //
83
+ // ---------------------------------------------------------------- //
84
+ auto global_connectivity = [](const Graph& g, bool node_conn,
85
+ bool directed) {
86
+ if (g.numberOfNodes() < 2) {
87
+ return 0; // connectivity of the trivial graph is 0 by convention
88
+ }
89
+ NodeArray<NodeArray<int>> conn(g);
90
+ for (node v : g.nodes) {
91
+ conn[v].init(g);
92
+ }
93
+ ConnectivityTester ct(node_conn, directed);
94
+ return ct.computeConnectivity(g, conn);
95
+ };
96
+ auto local_connectivity = [](const Graph& g, node s, node t, bool node_conn,
97
+ bool directed) {
98
+ if (s == t) {
99
+ throw std::invalid_argument("source and target must differ");
100
+ }
101
+ ConnectivityTester ct(node_conn, directed);
102
+ return ct.computeConnectivity(g, s, t);
103
+ };
104
+ m.def("node_connectivity",
105
+ [global_connectivity](const Graph& g, bool directed) {
106
+ return global_connectivity(g, true, directed);
107
+ },
108
+ "graph"_a, "directed"_a = false,
109
+ "Global node (vertex) connectivity: the minimum number of nodes whose "
110
+ "removal disconnects the graph. Returns 0 for a graph with fewer than "
111
+ "two nodes.");
112
+ m.def("node_connectivity",
113
+ [local_connectivity](const Graph& g, node s, node t, bool directed) {
114
+ return local_connectivity(g, s, t, true, directed);
115
+ },
116
+ "graph"_a, "source"_a, "target"_a, "directed"_a = false,
117
+ "Local node connectivity: the maximum number of internally "
118
+ "node-disjoint source-to-target paths (Menger).");
119
+ m.def("edge_connectivity",
120
+ [global_connectivity](const Graph& g, bool directed) {
121
+ return global_connectivity(g, false, directed);
122
+ },
123
+ "graph"_a, "directed"_a = false,
124
+ "Global edge connectivity: the minimum number of edges whose removal "
125
+ "disconnects the graph. Returns 0 for a graph with fewer than two "
126
+ "nodes.");
127
+ m.def("edge_connectivity",
128
+ [local_connectivity](const Graph& g, node s, node t, bool directed) {
129
+ return local_connectivity(g, s, t, false, directed);
130
+ },
131
+ "graph"_a, "source"_a, "target"_a, "directed"_a = false,
132
+ "Local edge connectivity: the maximum number of edge-disjoint "
133
+ "source-to-target paths (Menger).");
134
+
73
135
  // ---------------------------------------------------------------- //
74
136
  // Components (return count; write ids into the output array) //
75
137
  // ---------------------------------------------------------------- //
@@ -183,6 +245,28 @@ void register_algorithms(nb::module_& m) {
183
245
  "graph"_a, "weight"_a,
184
246
  "Global minimum cut value (Stoer-Wagner) for an undirected weighted "
185
247
  "graph.");
248
+ m.def("min_st_cut",
249
+ [](const Graph& g, const EdgeArray<double>& weight, node s, node t,
250
+ bool directed) {
251
+ // Cut edges are those leaving the source side; treatAsUndirected
252
+ // is the inverse of `directed`. With directed=True the cut value
253
+ // equals the directed max flow (max-flow min-cut duality).
254
+ List<edge> cut;
255
+ MinSTCutMaxFlow<double> mc(/*treatAsUndirected=*/!directed);
256
+ mc.call(g, weight, s, t, cut);
257
+ double value = 0.0;
258
+ nb::list edges;
259
+ for (edge e : cut) {
260
+ value += weight[e];
261
+ edges.append(nb::cast(e, nb::rv_policy::reference));
262
+ }
263
+ return nb::make_tuple(value, edges);
264
+ },
265
+ "graph"_a, "weight"_a, "source"_a, "sink"_a, "directed"_a = true,
266
+ "Minimum s-t cut. Returns (cut_value, [cut_edges]) where the edges "
267
+ "are those crossing from the source side to the sink side. With "
268
+ "`directed` (the default) the value equals the directed maximum flow "
269
+ "from source to sink; set it False to treat edges as undirected.");
186
270
 
187
271
  // ---------------------------------------------------------------- //
188
272
  // Matching //
@@ -291,6 +375,50 @@ void register_algorithms(nb::module_& m) {
291
375
  "integer (possibly negative) edge lengths. Returns False if a "
292
376
  "negative cycle exists; writes distances into `distance`.");
293
377
 
378
+ // ---------------------------------------------------------------- //
379
+ // A* search (point-to-point shortest path) //
380
+ // ---------------------------------------------------------------- //
381
+ m.def("a_star_search",
382
+ [](const Graph& g, const EdgeArray<double>& cost, node source,
383
+ node target, bool directed,
384
+ nb::object heuristic) -> nb::object {
385
+ // The heuristic is an optional Python callable node -> float; a
386
+ // zero heuristic makes A* equivalent to Dijkstra.
387
+ std::function<double(node)> h = [](node) { return 0.0; };
388
+ if (!heuristic.is_none()) {
389
+ h = [heuristic](node v) {
390
+ return nb::cast<double>(
391
+ heuristic(nb::cast(v, nb::rv_policy::reference)));
392
+ };
393
+ }
394
+ NodeArray<edge> predecessor(g);
395
+ double length = AStarSearch<double>(directed).call(
396
+ g, cost, source, target, predecessor, h);
397
+ // predecessor[target] is null when no path exists (unless the
398
+ // target is the source itself, a zero-length path).
399
+ if (source != target && predecessor[target] == nullptr) {
400
+ return nb::none();
401
+ }
402
+ List<edge> reversed;
403
+ for (node v = target; v != source;) {
404
+ edge e = predecessor[v];
405
+ reversed.pushFront(e);
406
+ v = e->opposite(v);
407
+ }
408
+ nb::list path;
409
+ for (edge e : reversed) {
410
+ path.append(nb::cast(e, nb::rv_policy::reference));
411
+ }
412
+ return nb::make_tuple(length, path);
413
+ },
414
+ "graph"_a, "cost"_a, "source"_a, "target"_a, "directed"_a = false,
415
+ "heuristic"_a = nb::none(),
416
+ "A* shortest path from `source` to `target` with non-negative edge "
417
+ "costs. `heuristic` is an optional callable mapping a node to an "
418
+ "admissible lower-bound distance to the target (a zero heuristic "
419
+ "reduces A* to Dijkstra). Returns (length, [path_edges]) or None if "
420
+ "the target is unreachable.");
421
+
294
422
  // ---------------------------------------------------------------- //
295
423
  // General maximum-weight matching (Blossom V) //
296
424
  // ---------------------------------------------------------------- //
@@ -398,6 +526,126 @@ void register_algorithms(nb::module_& m) {
398
526
  "Return the edges removed to obtain a maximal planar subgraph. An "
399
527
  "empty list means the graph is already planar.");
400
528
 
529
+ // ---------------------------------------------------------------- //
530
+ // Crossing minimization //
531
+ // ---------------------------------------------------------------- //
532
+ m.def("crossing_number",
533
+ [](const Graph& g, int permutations) {
534
+ if (permutations < 1) {
535
+ throw std::invalid_argument("permutations must be >= 1");
536
+ }
537
+ // PlanRep copies the input graph, so `g` is not modified. The
538
+ // planarizer works one connected component at a time; sum the
539
+ // per-component crossing counts.
540
+ PlanRep pr(g);
541
+ SubgraphPlanarizer sp;
542
+ sp.permutations(permutations);
543
+ int total = 0;
544
+ for (int cc = 0; cc < pr.numberOfCCs(); ++cc) {
545
+ int crossings = 0;
546
+ sp.call(pr, cc, crossings);
547
+ total += crossings;
548
+ }
549
+ return total;
550
+ },
551
+ "graph"_a, "permutations"_a = 1,
552
+ "Heuristic minimum number of edge crossings (subgraph planarizer). "
553
+ "Returns 0 for a planar graph. `permutations` sets the number of "
554
+ "randomized restarts of the edge-insertion phase; more restarts can "
555
+ "lower the count at higher cost. Does not modify the graph.");
556
+
557
+ // ---------------------------------------------------------------- //
558
+ // Edge insertion (routing with crossings) //
559
+ // ---------------------------------------------------------------- //
560
+ m.def("insert_edges",
561
+ [](const Graph& g, nb::list edges) {
562
+ // Deduplicate the requested edges, preserving the caller's order.
563
+ List<edge> want;
564
+ std::unordered_set<edge> seen;
565
+ for (auto handle : edges) {
566
+ edge e = nb::cast<edge>(handle);
567
+ if (seen.insert(e).second) {
568
+ want.pushBack(e);
569
+ }
570
+ }
571
+
572
+ PlanRep pr(g);
573
+ VariableEmbeddingInserter inserter;
574
+
575
+ nb::list result; // list of (edge, [crossed edges in order])
576
+ for (int cc = 0; cc < pr.numberOfCCs(); ++cc) {
577
+ pr.initCC(cc);
578
+ PlanRepLight prl(pr);
579
+ prl.initCC(cc);
580
+
581
+ // Restrict the requested edges to this component.
582
+ List<edge> here;
583
+ for (edge e : want) {
584
+ if (prl.copy(e) != nullptr) {
585
+ here.pushBack(e);
586
+ }
587
+ }
588
+ if (here.empty()) {
589
+ continue;
590
+ }
591
+
592
+ // Remove them so `prl` holds the planar subgraph, then insert
593
+ // them back with crossings.
594
+ for (edge e : here) {
595
+ prl.delEdge(prl.copy(e));
596
+ }
597
+ if (!isPlanar(prl)) {
598
+ throw std::invalid_argument(
599
+ "the graph minus the given edges must be planar");
600
+ }
601
+
602
+ Array<edge> to_insert(here.size());
603
+ int i = 0;
604
+ for (edge e : here) {
605
+ to_insert[i++] = e;
606
+ }
607
+ if (!Module::isSolution(inserter.callEx(prl, to_insert))) {
608
+ throw std::runtime_error("edge insertion failed");
609
+ }
610
+
611
+ // Each inserted edge becomes a chain of copy edges; every
612
+ // node shared by two consecutive chain edges is a crossing
613
+ // dummy. The other original edge through that dummy is the
614
+ // edge being crossed.
615
+ for (edge e : here) {
616
+ nb::list route;
617
+ edge prev = nullptr;
618
+ for (edge ce : prl.chain(e)) {
619
+ if (prev != nullptr) {
620
+ node v = (ce->source() == prev->source() ||
621
+ ce->source() == prev->target())
622
+ ? ce->source()
623
+ : ce->target();
624
+ for (adjEntry adj : v->adjEntries) {
625
+ edge other = prl.original(adj->theEdge());
626
+ if (other != nullptr && other != e) {
627
+ route.append(nb::cast(
628
+ other, nb::rv_policy::reference));
629
+ break;
630
+ }
631
+ }
632
+ }
633
+ prev = ce;
634
+ }
635
+ result.append(nb::make_tuple(
636
+ nb::cast(e, nb::rv_policy::reference), route));
637
+ }
638
+ }
639
+ return result;
640
+ },
641
+ "graph"_a, "edges"_a,
642
+ "Route the given edges through the rest of the graph, which must be "
643
+ "planar once those edges are removed. Returns a list of "
644
+ "(edge, [crossed_edges]) pairs: for each requested edge, the original "
645
+ "edges it crosses, in order from the edge's source to its target. An "
646
+ "edge inserted without crossings maps to an empty list. Uses the "
647
+ "variable-embedding inserter; does not modify the graph.");
648
+
401
649
  // ---------------------------------------------------------------- //
402
650
  // Triconnectivity / SPQR //
403
651
  // ---------------------------------------------------------------- //
@@ -4,6 +4,7 @@
4
4
 
5
5
  #include <cmath>
6
6
  #include <stdexcept>
7
+ #include <string>
7
8
 
8
9
  #include <ogdf/basic/GraphAttributes.h>
9
10
  #include <ogdf/basic/geometry.h>
@@ -23,6 +24,10 @@
23
24
  #include <ogdf/misclayout/LinearLayout.h>
24
25
  #include <ogdf/orthogonal/OrthoLayout.h>
25
26
  #include <ogdf/planarity/PlanarizationLayout.h>
27
+ #include <ogdf/planarlayout/FPPLayout.h>
28
+ #include <ogdf/planarlayout/MixedModelLayout.h>
29
+ #include <ogdf/planarlayout/PlanarDrawLayout.h>
30
+ #include <ogdf/planarlayout/PlanarStraightLayout.h>
26
31
  #include <ogdf/planarlayout/SchnyderLayout.h>
27
32
  #include <ogdf/tree/RadialTreeLayout.h>
28
33
  #include <ogdf/tree/TreeLayout.h>
@@ -37,6 +42,8 @@ using namespace nb::literals;
37
42
  // NaNs). Seed distinct positions on a circle when no initial layout is present,
38
43
  // while leaving any user-provided layout untouched.
39
44
  static void seed_circle_if_degenerate(GraphAttributes& ga) {
45
+ // M_PI is non-standard and undefined on MSVC, so use an explicit constant.
46
+ constexpr double kPi = 3.14159265358979323846;
40
47
  const Graph& g = ga.constGraph();
41
48
  for (node v : g.nodes) {
42
49
  if (ga.x(v) != 0.0 || ga.y(v) != 0.0) {
@@ -50,13 +57,35 @@ static void seed_circle_if_degenerate(GraphAttributes& ga) {
50
57
  const double radius = 10.0 * n;
51
58
  int i = 0;
52
59
  for (node v : g.nodes) {
53
- const double angle = 2.0 * M_PI * i / n;
60
+ const double angle = 2.0 * kPi * i / n;
54
61
  ga.x(v) = radius * std::cos(angle);
55
62
  ga.y(v) = radius * std::sin(angle);
56
63
  ++i;
57
64
  }
58
65
  }
59
66
 
67
+ // The planar grid layouts (FPP, PlanarStraight, PlanarDraw, MixedModel) require
68
+ // a simple planar graph with at least 3 nodes; OGDF augments connectivity
69
+ // internally but assumes planarity and simplicity. Guard here so bad input
70
+ // raises a clear Python error instead of tripping an assertion or running into
71
+ // undefined behaviour in a release build.
72
+ static void require_simple_planar(const GraphAttributes& ga, const char* name) {
73
+ const Graph& g = ga.constGraph();
74
+ if (g.numberOfNodes() < 3) {
75
+ throw std::invalid_argument(std::string(name) +
76
+ " requires at least 3 nodes");
77
+ }
78
+ if (!isSimpleUndirected(g)) {
79
+ throw std::invalid_argument(std::string(name) +
80
+ " requires a simple graph (no self-loops or "
81
+ "parallel edges)");
82
+ }
83
+ if (!isPlanar(g)) {
84
+ throw std::invalid_argument(std::string(name) +
85
+ " requires a planar graph");
86
+ }
87
+ }
88
+
60
89
  void register_layouts(nb::module_& m) {
61
90
  // --- enums used by layout configuration --- //
62
91
  nb::enum_<Orientation>(m, "Orientation")
@@ -230,6 +259,83 @@ void register_layouts(nb::module_& m) {
230
259
  "Compute a Schnyder straight-line planar grid layout (requires a "
231
260
  "simple planar graph with at least 3 nodes).");
232
261
 
262
+ // Straight-line planar grid drawing (de Fraysseix, Pach, Pollack). Like
263
+ // Schnyder, draws a simple planar graph without crossings on an integer
264
+ // grid.
265
+ nb::class_<FPPLayout>(m, "FPPLayout")
266
+ .def(nb::init<>())
267
+ .def("call",
268
+ [](FPPLayout& l, GraphAttributes& g) {
269
+ require_simple_planar(g, "FPPLayout");
270
+ l.call(g);
271
+ },
272
+ "graph_attributes"_a,
273
+ "Compute a de Fraysseix-Pach-Pollack straight-line planar grid "
274
+ "layout (requires a simple planar graph with at least 3 nodes).")
275
+ .def("set_separation",
276
+ [](FPPLayout& l, double x) { l.separation(x); }, "value"_a,
277
+ "Minimum distance between nodes.");
278
+
279
+ // Planar straight-line drawing with an augmentation/shelling-order pipeline.
280
+ nb::class_<PlanarStraightLayout>(m, "PlanarStraightLayout")
281
+ .def(nb::init<>())
282
+ .def("call",
283
+ [](PlanarStraightLayout& l, GraphAttributes& g) {
284
+ require_simple_planar(g, "PlanarStraightLayout");
285
+ l.call(g);
286
+ },
287
+ "graph_attributes"_a,
288
+ "Compute a straight-line planar grid layout (requires a simple "
289
+ "planar graph with at least 3 nodes).")
290
+ .def("set_separation",
291
+ [](PlanarStraightLayout& l, double x) { l.separation(x); },
292
+ "value"_a, "Minimum distance between nodes.")
293
+ .def("set_size_optimization",
294
+ [](PlanarStraightLayout& l, bool b) { l.sizeOptimization(b); },
295
+ "value"_a, "Try to reduce the grid size.")
296
+ .def("set_base_ratio",
297
+ [](PlanarStraightLayout& l, double x) { l.baseRatio(x); },
298
+ "value"_a, "Fraction of external-face nodes placed on the base "
299
+ "line.");
300
+
301
+ // Planar straight-line drawing tuned for a more balanced aspect ratio.
302
+ nb::class_<PlanarDrawLayout>(m, "PlanarDrawLayout")
303
+ .def(nb::init<>())
304
+ .def("call",
305
+ [](PlanarDrawLayout& l, GraphAttributes& g) {
306
+ require_simple_planar(g, "PlanarDrawLayout");
307
+ l.call(g);
308
+ },
309
+ "graph_attributes"_a,
310
+ "Compute a straight-line planar grid layout (requires a simple "
311
+ "planar graph with at least 3 nodes).")
312
+ .def("set_separation",
313
+ [](PlanarDrawLayout& l, double x) { l.separation(x); }, "value"_a,
314
+ "Minimum distance between nodes.")
315
+ .def("set_size_optimization",
316
+ [](PlanarDrawLayout& l, bool b) { l.sizeOptimization(b); },
317
+ "value"_a, "Try to reduce the grid size.")
318
+ .def("set_base_ratio",
319
+ [](PlanarDrawLayout& l, double x) { l.baseRatio(x); }, "value"_a,
320
+ "Fraction of external-face nodes placed on the base line.");
321
+
322
+ // Mixed-model planar layout: orthogonal-style routing with nodes drawn as
323
+ // boxes. Produces higher-quality planar drawings than the pure grid
324
+ // algorithms.
325
+ nb::class_<MixedModelLayout>(m, "MixedModelLayout")
326
+ .def(nb::init<>())
327
+ .def("call",
328
+ [](MixedModelLayout& l, GraphAttributes& g) {
329
+ require_simple_planar(g, "MixedModelLayout");
330
+ l.call(g);
331
+ },
332
+ "graph_attributes"_a,
333
+ "Compute a mixed-model planar layout (requires a simple planar "
334
+ "graph with at least 3 nodes).")
335
+ .def("set_separation",
336
+ [](MixedModelLayout& l, double x) { l.separation(x); }, "value"_a,
337
+ "Minimum distance between nodes.");
338
+
233
339
  // Radial tree drawing (concentric levels). Requires a tree.
234
340
  nb::enum_<RadialTreeLayout::RootSelectionType>(m, "RadialRootSelection")
235
341
  .value("SOURCE", RadialTreeLayout::RootSelectionType::Source)
@@ -146,6 +146,32 @@ def test_min_cut():
146
146
  assert ogdf.min_cut(c, weight) == 2.0
147
147
 
148
148
 
149
+ def test_min_st_cut_matches_max_flow():
150
+ g = ogdf.Graph()
151
+ s, a, t = g.new_node(), g.new_node(), g.new_node()
152
+ e1 = g.new_edge(s, a)
153
+ e2 = g.new_edge(a, t)
154
+ e3 = g.new_edge(s, t)
155
+ cap = ogdf.EdgeArrayDouble(g)
156
+ cap[e1], cap[e2], cap[e3] = 3.0, 2.0, 5.0
157
+ value, edges = ogdf.min_st_cut(g, cap, s, t)
158
+ # Max-flow min-cut duality: the cut value equals the max flow (7).
159
+ flow = ogdf.EdgeArrayDouble(g)
160
+ assert value == ogdf.max_flow(g, cap, s, t, flow) == 7.0
161
+ # The min cut severs a->t (2) and s->t (5); the cut-edge weights sum to it.
162
+ assert sum(cap[e] for e in edges) == value
163
+ assert {e.index for e in edges} == {e2.index, e3.index}
164
+
165
+
166
+ def test_min_st_cut_undirected():
167
+ # Two parallel-in-series paths between s and t; undirected cut is 2.
168
+ c, nodes = cycle(4) # s - x - t - y - s
169
+ weight = ogdf.EdgeArrayDouble(c, 1.0)
170
+ value, edges = ogdf.min_st_cut(c, weight, nodes[0], nodes[2], directed=False)
171
+ assert value == 2.0
172
+ assert len(list(edges)) == 2
173
+
174
+
149
175
  # --- matching --- #
150
176
  def test_maximal_matching():
151
177
  g, nodes = path(5)
@@ -362,3 +388,165 @@ def test_bfs_distances():
362
388
  dist = ogdf.NodeArrayInt(g)
363
389
  ogdf.bfs_distances(g, nodes[0], dist)
364
390
  assert [dist[v] for v in nodes] == [0, 1, 2, 3, 4]
391
+
392
+
393
+ # --- A* search --- #
394
+ def test_a_star_search_path():
395
+ g, nodes = path(5) # a-b-c-d-e
396
+ cost = ogdf.EdgeArrayDouble(g, 2.0)
397
+ length, edges = ogdf.a_star_search(g, cost, nodes[0], nodes[4])
398
+ assert length == 8.0 # 4 hops * 2.0
399
+ edges = list(edges)
400
+ assert len(edges) == 4
401
+ # The returned edges form a walk from source to target.
402
+ assert edges[0].source.index == nodes[0].index
403
+ assert edges[-1].target.index == nodes[4].index
404
+
405
+
406
+ def test_a_star_search_unreachable():
407
+ g = ogdf.Graph()
408
+ a, b = g.new_node(), g.new_node() # no edge between them
409
+ assert ogdf.a_star_search(g, ogdf.EdgeArrayDouble(g, 1.0), a, b) is None
410
+
411
+
412
+ def test_a_star_search_admissible_heuristic_is_optimal():
413
+ # A shortcut edge must win even with a (zero) heuristic supplied. An
414
+ # admissible heuristic never changes the optimal length.
415
+ g = ogdf.Graph()
416
+ n = [g.new_node() for _ in range(4)]
417
+ e_long = [g.new_edge(n[i], n[i + 1]) for i in range(3)] # 0-1-2-3
418
+ e_short = g.new_edge(n[0], n[3]) # direct shortcut
419
+ cost = ogdf.EdgeArrayDouble(g)
420
+ for e in e_long:
421
+ cost[e] = 1.0
422
+ cost[e_short] = 2.0 # 2.0 < 3.0 for the long path
423
+ length, edges = ogdf.a_star_search(g, cost, n[0], n[3], False, lambda v: 0.0)
424
+ assert length == 2.0
425
+ assert [e.index for e in edges] == [e_short.index]
426
+
427
+
428
+ # --- crossing number --- #
429
+ def test_crossing_number_planar_is_zero():
430
+ g = ogdf.Graph()
431
+ ogdf.random_planar_connected_graph(g, 15, 25)
432
+ assert ogdf.crossing_number(g) == 0
433
+
434
+
435
+ def test_crossing_number_k5():
436
+ k5 = ogdf.Graph()
437
+ ogdf.complete_graph(k5, 5) # crossing number of K5 is 1
438
+ assert ogdf.crossing_number(k5) == 1
439
+ assert k5.number_of_edges() == 10 # graph is not modified
440
+
441
+
442
+ def test_crossing_number_k6_at_least_three():
443
+ k6 = ogdf.Graph()
444
+ ogdf.complete_graph(k6, 6) # true crossing number is 3
445
+ # The planarizer yields a real drawing, so its count is >= the optimum.
446
+ assert ogdf.crossing_number(k6) >= 3
447
+
448
+
449
+ def test_crossing_number_rejects_bad_permutations():
450
+ g = ogdf.Graph()
451
+ ogdf.complete_graph(g, 5)
452
+ with pytest.raises(ValueError):
453
+ ogdf.crossing_number(g, 0)
454
+
455
+
456
+ # --- edge insertion (routing with crossings) --- #
457
+ def test_insert_edges_k5_single_crossing():
458
+ k5 = ogdf.Graph()
459
+ ogdf.complete_graph(k5, 5)
460
+ # Removing any single edge leaves a maximal planar graph; reinserting it
461
+ # forces exactly one crossing.
462
+ e = list(k5.edges())[0]
463
+ routes = ogdf.insert_edges(k5, [e])
464
+ assert len(routes) == 1
465
+ inserted, crossed = routes[0]
466
+ assert inserted.index == e.index
467
+ crossed = list(crossed)
468
+ assert len(crossed) == 1
469
+ # A valid drawing only crosses independent edges (no shared endpoint), and
470
+ # never the inserted edge itself.
471
+ endpoints = {e.source.index, e.target.index}
472
+ other = crossed[0]
473
+ assert other.index != e.index
474
+ assert endpoints.isdisjoint({other.source.index, other.target.index})
475
+ assert k5.number_of_edges() == 10 # graph unmodified
476
+
477
+
478
+ def test_insert_edges_matches_crossing_number_small():
479
+ for n in (5, 6):
480
+ g = ogdf.Graph()
481
+ ogdf.complete_graph(g, n)
482
+ removed = list(ogdf.maximal_planar_subgraph(g))
483
+ routes = ogdf.insert_edges(g, removed)
484
+ total = sum(len(list(c)) for _, c in routes)
485
+ # Insertion into the fixed planar subgraph is an upper bound on the
486
+ # crossing number; for these small complete graphs it is tight.
487
+ assert total == ogdf.crossing_number(g)
488
+ assert {ins.index for ins, _ in routes} == {e.index for e in removed}
489
+
490
+
491
+ def test_insert_edges_planar_no_crossings():
492
+ g = ogdf.Graph()
493
+ ogdf.random_planar_connected_graph(g, 12, 20)
494
+ e = list(g.edges())[0]
495
+ routes = ogdf.insert_edges(g, [e])
496
+ # Removing and reinserting one edge of a planar graph needs no crossings.
497
+ assert [len(list(c)) for _, c in routes] == [0]
498
+
499
+
500
+ def test_insert_edges_empty():
501
+ g = ogdf.Graph()
502
+ ogdf.complete_graph(g, 5)
503
+ assert list(ogdf.insert_edges(g, [])) == []
504
+
505
+
506
+ def test_insert_edges_rejects_non_planar_remainder():
507
+ k6 = ogdf.Graph()
508
+ ogdf.complete_graph(k6, 6)
509
+ # K6 minus a single edge is still non-planar, so the remainder is invalid.
510
+ with pytest.raises(ValueError):
511
+ ogdf.insert_edges(k6, [list(k6.edges())[0]])
512
+
513
+
514
+ # --- k-connectivity --- #
515
+ def test_global_connectivity_known_values():
516
+ c, _ = cycle(5) # a cycle is 2-node- and 2-edge-connected
517
+ assert ogdf.node_connectivity(c) == 2
518
+ assert ogdf.edge_connectivity(c) == 2
519
+
520
+ p, _ = path(4) # a path is 1-connected
521
+ assert ogdf.node_connectivity(p) == 1
522
+ assert ogdf.edge_connectivity(p) == 1
523
+
524
+ k4 = ogdf.Graph()
525
+ ogdf.complete_graph(k4, 4) # K4 is 3-connected
526
+ assert ogdf.node_connectivity(k4) == 3
527
+ assert ogdf.edge_connectivity(k4) == 3
528
+
529
+
530
+ def test_connectivity_trivial_graph_is_zero():
531
+ g = ogdf.Graph()
532
+ g.new_node() # a single node
533
+ assert ogdf.node_connectivity(g) == 0
534
+ assert ogdf.edge_connectivity(g) == 0
535
+
536
+
537
+ def test_local_connectivity_menger():
538
+ # Two internally disjoint s-t paths -> local connectivity 2.
539
+ g = ogdf.Graph()
540
+ s, t = g.new_node(), g.new_node()
541
+ mids = [g.new_node() for _ in range(2)]
542
+ for m in mids:
543
+ g.new_edge(s, m)
544
+ g.new_edge(m, t)
545
+ assert ogdf.node_connectivity(g, s, t) == 2
546
+ assert ogdf.edge_connectivity(g, s, t) == 2
547
+
548
+
549
+ def test_local_connectivity_rejects_same_node():
550
+ g, nodes = path(3)
551
+ with pytest.raises(ValueError):
552
+ ogdf.node_connectivity(g, nodes[0], nodes[0])
@@ -138,3 +138,61 @@ def test_balloon_rejects_disconnected():
138
138
  ga = ogdf.GraphAttributes(g)
139
139
  with pytest.raises(ValueError):
140
140
  ogdf.BalloonLayout().call(ga)
141
+
142
+
143
+ # --- planar grid layouts (require a simple planar graph, >= 3 nodes) --- #
144
+ @pytest.mark.parametrize(
145
+ "layout_cls",
146
+ [
147
+ ogdf.FPPLayout,
148
+ ogdf.PlanarStraightLayout,
149
+ ogdf.PlanarDrawLayout,
150
+ ogdf.MixedModelLayout,
151
+ ],
152
+ )
153
+ def test_planar_grid_layouts_no_crossings(layout_cls):
154
+ g = connected_graph(12, 18) # planar, connected, simple
155
+ nodes = list(g.nodes())
156
+ ga = ogdf.GraphAttributes(g)
157
+ layout_cls().call(ga)
158
+ coords = [(ga.x(v), ga.y(v)) for v in nodes]
159
+ assert all(x == x and y == y for x, y in coords) # no NaNs
160
+ # A planar drawing places every node at a distinct point.
161
+ assert len({(round(x, 3), round(y, 3)) for x, y in coords}) == len(nodes)
162
+ assert ga.bounding_box_width() > 0
163
+
164
+
165
+ @pytest.mark.parametrize(
166
+ "layout_cls",
167
+ [
168
+ ogdf.FPPLayout,
169
+ ogdf.PlanarStraightLayout,
170
+ ogdf.PlanarDrawLayout,
171
+ ogdf.MixedModelLayout,
172
+ ],
173
+ )
174
+ def test_planar_grid_layouts_reject_non_planar(layout_cls):
175
+ g = ogdf.Graph()
176
+ ogdf.complete_graph(g, 5) # K5 is not planar
177
+ ga = ogdf.GraphAttributes(g)
178
+ with pytest.raises(ValueError):
179
+ layout_cls().call(ga)
180
+
181
+
182
+ def test_planar_grid_layout_rejects_too_small():
183
+ g = ogdf.Graph()
184
+ g.new_edge(g.new_node(), g.new_node()) # 2 nodes -> below the minimum of 3
185
+ ga = ogdf.GraphAttributes(g)
186
+ with pytest.raises(ValueError):
187
+ ogdf.FPPLayout().call(ga)
188
+
189
+
190
+ def test_planar_grid_layout_setters():
191
+ g = connected_graph(10, 14)
192
+ ga = ogdf.GraphAttributes(g)
193
+ layout = ogdf.PlanarStraightLayout()
194
+ layout.set_separation(30.0)
195
+ layout.set_size_optimization(True)
196
+ layout.set_base_ratio(0.5)
197
+ layout.call(ga)
198
+ assert ga.bounding_box_width() > 0
@@ -943,7 +943,7 @@ wheels = [
943
943
 
944
944
  [[package]]
945
945
  name = "ogdf-py"
946
- version = "0.2.0"
946
+ version = "0.3.0"
947
947
  source = { editable = "." }
948
948
 
949
949
  [package.dev-dependencies]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes