Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Fixed call to `astar_shortest_path` in `Graph.shortest_path`.

### Removed


Expand Down
2 changes: 1 addition & 1 deletion src/compas/datastructures/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ def shortest_path(self, u, v):
:meth:`compas.topology.astar_shortest_path`

"""
return astar_shortest_path(self.adjacency, u, v)
return astar_shortest_path(self, u, v)

# --------------------------------------------------------------------------
# Default attributes
Expand Down
32 changes: 32 additions & 0 deletions tests/compas/datastructures/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,38 @@ def test_graph_data2():
assert Graph.validate_data(other.__data__)


def test_shortest_path():
graph = Graph()
graph.add_edge(1, 2)
graph.add_edge(2, 3)
graph.add_edge(3, 4)
graph.add_edge(5, 6)

# Test shortest path from node 1 to node 4
path = graph.shortest_path(1, 4)
assert path == [1, 2, 3, 4]

# Test shortest path from node 1 to node 3
path = graph.shortest_path(1, 3)
assert path == [1, 2, 3]

# Test shortest path from node 2 to node 4
path = graph.shortest_path(2, 4)
assert path == [2, 3, 4]

# Test shortest path from node 4 to node 1
path = graph.shortest_path(4, 1)
assert path == [4, 3, 2, 1]

# Test shortest path from node 5 to node 6
path = graph.shortest_path(5, 6)
assert path == [5, 6]

# Test shortest path from node 3 to node 5 (should be None)
path = graph.shortest_path(3, 5)
assert path is None


# ==============================================================================
# Properties
# ==============================================================================
Expand Down
Loading