comparison env/lib/python3.9/site-packages/networkx/algorithms/traversal/tests/test_beamsearch.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 """Unit tests for the beam search functions."""
2
3 import networkx as nx
4
5
6 def identity(x):
7 return x
8
9
10 class TestBeamSearch:
11 """Unit tests for the beam search function."""
12
13 def test_narrow(self):
14 """Tests that a narrow beam width may cause an incomplete search."""
15 # In this search, we enqueue only the neighbor 3 at the first
16 # step, then only the neighbor 2 at the second step. Once at
17 # node 2, the search chooses node 3, since it has a higher value
18 # that node 1, but node 3 has already been visited, so the
19 # search terminates.
20 G = nx.cycle_graph(4)
21 edges = nx.bfs_beam_edges(G, 0, identity, width=1)
22 assert list(edges) == [(0, 3), (3, 2)]
23
24 def test_wide(self):
25 G = nx.cycle_graph(4)
26 edges = nx.bfs_beam_edges(G, 0, identity, width=2)
27 assert list(edges) == [(0, 3), (0, 1), (3, 2)]