예제 #1
0
def test_graph():
    G = Graph()
    G.add_edge(1, 2, 3)
    G.add_edge(1, 3, 2)
    assert G.get_edge_weight(1, 2) == 3
    assert G.get_edge_weight(1, 3) == 2
    assert G.get_adjacent_nodes(1) == {2, 3}
예제 #2
0
def draw_vis_graph(vertices: List[List[float]], g: Graph) -> None:
    """
    Draw the visibility graph of the vertices in a polygon
    :param vertices: List[List[float]]], list of vertices
    :param g: Graph, the graph computed from create_vis_graph or create_vis_graph_with_holes
    :return: None
    """
    for node in list(g.get_nodes()):
        for neighbor in list(g.get_adjacent_nodes(node)):
            v1 = vertices[node]
            v2 = vertices[neighbor]
            plt.plot([v1[0], v2[0]], [v1[1], v2[1]], color='r', linewidth=0.5)
            if node != 30:
                plt.text(v1[0] + 0.5, v1[1], str(node))
            if neighbor != 30:
                plt.text(v2[0] + 0.5, v2[1], str(neighbor))