Skip to content

Commit a6a0dec

Browse files
authored
Merge pull request #1445 from compas-dev/graph_astar_fix
2 parents 8fb5ecb + 835efff commit a6a0dec

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Changed
1515

16+
* Fixed call to `astar_shortest_path` in `Graph.shortest_path`.
17+
1618
### Removed
1719

1820

src/compas/datastructures/graph/graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ def shortest_path(self, u, v):
12041204
:meth:`compas.topology.astar_shortest_path`
12051205
12061206
"""
1207-
return astar_shortest_path(self.adjacency, u, v)
1207+
return astar_shortest_path(self, u, v)
12081208

12091209
# --------------------------------------------------------------------------
12101210
# Default attributes

tests/compas/datastructures/test_graph.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,38 @@ def test_graph_data2():
117117
assert Graph.validate_data(other.__data__)
118118

119119

120+
def test_shortest_path():
121+
graph = Graph()
122+
graph.add_edge(1, 2)
123+
graph.add_edge(2, 3)
124+
graph.add_edge(3, 4)
125+
graph.add_edge(5, 6)
126+
127+
# Test shortest path from node 1 to node 4
128+
path = graph.shortest_path(1, 4)
129+
assert path == [1, 2, 3, 4]
130+
131+
# Test shortest path from node 1 to node 3
132+
path = graph.shortest_path(1, 3)
133+
assert path == [1, 2, 3]
134+
135+
# Test shortest path from node 2 to node 4
136+
path = graph.shortest_path(2, 4)
137+
assert path == [2, 3, 4]
138+
139+
# Test shortest path from node 4 to node 1
140+
path = graph.shortest_path(4, 1)
141+
assert path == [4, 3, 2, 1]
142+
143+
# Test shortest path from node 5 to node 6
144+
path = graph.shortest_path(5, 6)
145+
assert path == [5, 6]
146+
147+
# Test shortest path from node 3 to node 5 (should be None)
148+
path = graph.shortest_path(3, 5)
149+
assert path is None
150+
151+
120152
# ==============================================================================
121153
# Properties
122154
# ==============================================================================

0 commit comments

Comments
 (0)