def test_multigraph(): G = nx.cycle_graph(4) M = nx.MultiGraph(G.edges()) M.add_edges_from(G.edges()) M.remove_edge(1, 2) A, B = nx.kernighan_lin_bisection(M) assert_partition_equal([A, B], [{0, 1}, {2, 3}])
def test_too_many_blocks(): G = nx.barbell_graph(3, 0) partition = ({0, 1}, {2}, {3, 4, 5}) nx.kernighan_lin_bisection(G, partition)
def test_non_disjoint_partition(): G = nx.barbell_graph(3, 0) partition = ({0, 1, 2}, {2, 3, 4, 5}) nx.kernighan_lin_bisection(G, partition)
def test_partition(): G = nx.barbell_graph(3, 0) C = nx.kernighan_lin_bisection(G) assert_partition_equal(C, [{0, 1, 2}, {3, 4, 5}])
def kernighan_lin(G): kl = nx.kernighan_lin_bisection(G,partition=2) print(kl)