Пример #1
0
def test_bad_input3():
    g = Graph(from_list=[((1, 'b'), ('b', 1), 1)])
    try:
        _ = plot_2d(g)
        raise AssertionError
    except (ValueError, ImportError):
        pass
Пример #2
0
def test_bad_input():
    g = Graph(from_list=[
        (0, 1, 1),  # 3 edges:
    ])
    try:
        _ = plot_2d(g)
        raise AssertionError
    except (ValueError, ImportError):
        pass
Пример #3
0
def test_random_graph_3():
    g = random_xy_graph(200, x_max=800, y_max=400)  # a fully connected graph.
    dist, tour = tsp_greedy(g)

    # convert the route to a graph.
    g = Graph()

    a = tour[0]
    for b in tour[1:]:
        g.add_edge(a, b, xy_distance(a, b))
        a = b
    # add the link back to start.
    b = tour[0]
    g.add_edge(a, b, xy_distance(a, b))

    # add a red diamond for the starting point.
    if not visuals_enabled:
        return
    plt = plot_2d(g)
    start = tour[0:1]
    xs, ys = [c[0] for c in start], [c[1] for c in start]
    plt.plot(xs, ys, 'rD', clip_on=False)
    plt.show()
Пример #4
0
def test_random_graph_3():
    g = random_xy_graph(200, x_max=800, y_max=400)  # a fully connected graph.
    dist, tour = tsp(g)

    # convert the route to a graph.
    g = Graph()

    a = tour[0]
    for b in tour[1:]:
        g.add_edge(a, b, xy_distance(a, b))
        a = b
    # add the link back to start.
    b = tour[0]
    g.add_edge(a, b, xy_distance(a, b))

    # add a red diamond for the starting point.
    try:
        plt = plot_2d(g)
        start = tour[0:1]
        xs, ys = [c[0] for c in start], [c[1] for c in start]
        plt.plot(xs, ys, 'rD', clip_on=False)
        plt.show()
    except (ValueError, ImportError):
        pass