Skip to content

Commit 5c9cbbb

Browse files
authored
Merge branch 'main' into perf/closest-vectorized
2 parents a5d1285 + ffb259d commit 5c9cbbb

14 files changed

Lines changed: 307 additions & 228 deletions

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
pytest --cov=pgraph --cov-report=xml:coverage.xml
7777
coverage report
7878
- name: Upload coverage to Codecov
79-
uses: codecov/codecov-action@v7
79+
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
8080
with:
8181
files: ./coverage.xml
8282
verbose: true

‎.github/workflows/dependabot-auto-merge.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v3
16+
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
build/
12
docs/build
23
dist/
34
*.code-workspace

‎docs/llms_intro.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
pgraph is a pure-Python package of graph classes: directed and undirected graphs of vertices connected by edges, with edge costs and path planning (breadth-first, uniform-cost and A*). Vertices can be *embedded*, given a coordinate in a space of any dimension; edge costs then come from a distance metric (L2, L1, SE2 or your own), and the graph can be queried spatially, plotted and exported. Self-loops and parallel edges are allowed. It requires Python 3.9 or later and depends on NumPy, Matplotlib and spatialmath-python. Install with `pip install pgraph-python`; import it as `pgraph`.
22

3+
## When to use it
4+
5+
Reach for pgraph when a program needs a **small, explicit graph with path planning**: vertices with optional coordinates, directed or undirected edges with costs, and breadth-first, uniform-cost or A* search, plus nearest-vertex queries, plotting and export. It suits roadmaps, grid and lattice planners, pose graphs and teaching examples where you want the vertex and edge objects themselves, not just an adjacency structure. `import pgraph` loads only NumPy.
6+
7+
It is not a large-scale graph analytics package (use `networkx` for centrality, community detection or hundreds of algorithms; `igraph` or `graph-tool` for very large graphs), and it has no weighted-matching or flow algorithms.
8+
39
## Quick start
410

511
```python
@@ -18,6 +24,16 @@ g.plot()
1824
g.highlight_path(path)
1925
```
2026

27+
## Recipes
28+
29+
- **Shortest path between two named places**: build a `UGraph`, `add_vertex` for each place with its coordinate and `name=`, `add_edge` between neighbours, then `path, length, _ = g.path_Astar("start", "goal")`.
30+
- **Plan on a grid**: add one vertex per cell and an edge to each neighbour, with `cost=` if the cells differ; `path_BFS` gives the fewest steps, `path_Astar` the cheapest.
31+
- **Find the vertex nearest a point**: `v, dist = g.closest(point)`; `g.near(point, radius)` for all within a radius.
32+
- **Check whether two places are connected**: `g.samecomponent(v1, v2)`, or `g.nc` for the number of components.
33+
- **Get the adjacency or Laplacian matrix**: `g.adjacency()`, `g.laplacian()`, as NumPy arrays.
34+
- **Draw the graph and the route**: `g.plot()`, then `g.highlight_path(path)`.
35+
- **Export for GraphViz or Mermaid**: `g.export("graph.dot")` or `g.export("graph.mmd")`.
36+
2137
## Key points
2238

2339
- **Classes.** `UGraph` (undirected) and `DGraph` (directed) share the base class `Graph`, which is concrete: `Graph(directed=True)` is a `DGraph`. There is one `Vertex` class for both and one `Edge` class. `UVertex` and `DVertex` are deprecated aliases of `Vertex`. Constructor arguments are keyword-only: `UGraph(dim=2, metric="L2", heuristic=None, vertex_class=None, edge_class=None, verbose=False)`; `UGraph(2)` is a `TypeError`.

‎examples/create_json.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
del info['y']
1616
del info['dbne']
1717
del info['utmzone']
18-
try:
19-
del info['dgoal']
20-
except:
21-
pass
18+
info.pop('dgoal', None) # not every place has one
2219
info['utm'] = [info['utm'][0] / 1000, info['utm'][1] / 1000]
2320

2421
routes = []

‎examples/roads.ipynb‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -187,35 +187,35 @@
187187
"name": "stdout",
188188
"output_type": "stream",
189189
"text": [
190-
"Edge{[Camooweal] -- [Mount Isa], cost=188}\n",
191-
"Edge{[Mount Isa] -- [Cloncurry], cost=118}\n",
192-
"Edge{[Cloncurry] -- [Hughenden], cost=401}\n",
193-
"Edge{[Cloncurry] -- [Winton], cost=350}\n",
194-
"Edge{[Hughenden] -- [Charters Towers], cost=248}\n",
195-
"Edge{[Charters Towers] -- [Townsville], cost=135}\n",
196-
"Edge{[Townsville] -- [Mackay], cost=388}\n",
197-
"Edge{[Mackay] -- [Rockhampton], cost=334}\n",
198-
"Edge{[Mackay] -- [Emerald], cost=384}\n",
199-
"Edge{[Rockhampton] -- [Brisbane], cost=682}\n",
200-
"Edge{[Rockhampton] -- [Emerald], cost=270}\n",
201-
"Edge{[Brisbane] -- [Roma], cost=482}\n",
202-
"Edge{[Roma] -- [Charleville], cost=266}\n",
203-
"Edge{[Charleville] -- [Blackall], cost=305}\n",
204-
"Edge{[Blackall] -- [Barcaldine], cost=106}\n",
205-
"Edge{[Blackall] -- [Windorah], cost=530}\n",
206-
"Edge{[Barcaldine] -- [Emerald], cost=307}\n",
207-
"Edge{[Barcaldine] -- [Hughenden], cost=500}\n",
208-
"Edge{[Barcaldine] -- [Longreach], cost=106}\n",
209-
"Edge{[Longreach] -- [Windorah], cost=311}\n",
210-
"Edge{[Longreach] -- [Winton], cost=180}\n",
211-
"Edge{[Winton] -- [Hughenden], cost=216}\n",
212-
"Edge{[Winton] -- [Boulia], cost=363}\n",
213-
"Edge{[Winton] -- [Windorah], cost=487}\n",
214-
"Edge{[Boulia] -- [Mount Isa], cost=304}\n",
215-
"Edge{[Boulia] -- [Bedourie], cost=194}\n",
216-
"Edge{[Bedourie] -- [Birdsville], cost=193}\n",
217-
"Edge{[Birdsville] -- [Windorah], cost=380}\n",
218-
"Edge{[Bedourie] -- [Windorah], cost=411}\n"
190+
"Edge{[Camooweal] ↔ [Mount Isa], cost=188}\n",
191+
"Edge{[Mount Isa] ↔ [Cloncurry], cost=118}\n",
192+
"Edge{[Cloncurry] ↔ [Hughenden], cost=401}\n",
193+
"Edge{[Cloncurry] ↔ [Winton], cost=350}\n",
194+
"Edge{[Hughenden] ↔ [Charters Towers], cost=248}\n",
195+
"Edge{[Charters Towers] ↔ [Townsville], cost=135}\n",
196+
"Edge{[Townsville] ↔ [Mackay], cost=388}\n",
197+
"Edge{[Mackay] ↔ [Rockhampton], cost=334}\n",
198+
"Edge{[Mackay] ↔ [Emerald], cost=384}\n",
199+
"Edge{[Rockhampton] ↔ [Brisbane], cost=682}\n",
200+
"Edge{[Rockhampton] ↔ [Emerald], cost=270}\n",
201+
"Edge{[Brisbane] ↔ [Roma], cost=482}\n",
202+
"Edge{[Roma] ↔ [Charleville], cost=266}\n",
203+
"Edge{[Charleville] ↔ [Blackall], cost=305}\n",
204+
"Edge{[Blackall] ↔ [Barcaldine], cost=106}\n",
205+
"Edge{[Blackall] ↔ [Windorah], cost=530}\n",
206+
"Edge{[Barcaldine] ↔ [Emerald], cost=307}\n",
207+
"Edge{[Barcaldine] ↔ [Hughenden], cost=500}\n",
208+
"Edge{[Barcaldine] ↔ [Longreach], cost=106}\n",
209+
"Edge{[Longreach] ↔ [Windorah], cost=311}\n",
210+
"Edge{[Longreach] ↔ [Winton], cost=180}\n",
211+
"Edge{[Winton] ↔ [Hughenden], cost=216}\n",
212+
"Edge{[Winton] ↔ [Boulia], cost=363}\n",
213+
"Edge{[Winton] ↔ [Windorah], cost=487}\n",
214+
"Edge{[Boulia] ↔ [Mount Isa], cost=304}\n",
215+
"Edge{[Boulia] ↔ [Bedourie], cost=194}\n",
216+
"Edge{[Bedourie] ↔ [Birdsville], cost=193}\n",
217+
"Edge{[Birdsville] ↔ [Windorah], cost=380}\n",
218+
"Edge{[Bedourie] ↔ [Windorah], cost=411}\n"
219219
]
220220
}
221221
],

‎posegraph.py‎

Lines changed: 0 additions & 105 deletions
This file was deleted.

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = ["spatialmath-python", "numpy>=2.0", "matplotlib"]
3939
"Homepage" = "https://github.com/petercorke/pgraph-python"
4040
"Bug Tracker" = "https://github.com/petercorke/pgraph-python/issues"
4141
"Documentation" = "https://petercorke.github.io/pgraph-python"
42+
"llms.txt" = "https://petercorke.github.io/pgraph-python/llms.txt"
4243
"GitHub Source" = "https://github.com/petercorke/pgraph-python"
4344
"Changelog" = "https://github.com/petercorke/pgraph-python/blob/main/CHANGELOG.md"
4445
"Coverage" = "https://codecov.io/gh/petercorke/pgraph-python"

0 commit comments

Comments
 (0)