Ejemplo n.º 1
0
    def test_generate_simple_random_graph_differ_vertices_num(self):
        """
        Test if exception raise if vertices number is
        different than length of points list.
        """
        points, execution_time = generate_point_positions(0.0, 1.0, 10)

        with pytest.raises(Exception):
            generate_simple_random_graph(5, 0.5, points)
Ejemplo n.º 2
0
    def test_generate_same_graph_with_kd_tree_2(self):
        """
        Check if kd tree generate same graph.
        """
        points, execution_time = generate_point_positions(0.0, 1.0, 15)

        g1, execution_time = generate_simple_random_graph(15, 0.3, points)
        g2, execution_time = generate_simple_random_graph(15, 0.3, points, True)

        for n in g1.nodes:
            assert sorted(list(g1.edges(n))) == sorted(list(g2.edges(n)))
Ejemplo n.º 3
0
    def test_generate_graph_with_no_given_vertices_list_1(self):
        """
        Check number of nodes in graph if no vertices list is
        given.
        """
        g, execution_time = generate_simple_random_graph(10, 0.1)

        assert len(list(g.nodes)) == 10
Ejemplo n.º 4
0
    def test_generate_graph_with_no_given_vertices_list_2(self):
        """
        Check number of nodes in graph if no vertices list is
        given. Check if all nodes are connected
        """
        g, execution_time = generate_simple_random_graph(10, 2)

        for n in g.nodes:
            assert len(list(g.edges(n))) == 9
Ejemplo n.º 5
0
    def test_generate_simple_random_graph_all_connections(self):
        """
        Check if all nodes are connected.
        """

        points = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]

        graph, execution_time = generate_simple_random_graph(4, 3, points)

        for n in graph.nodes:
            assert graph.degree[n] == 3
        assert len(graph.nodes) == 4
def generate_random_graph_command(command_args: List[str]) -> None:
    """
    Parse ``command_args`` and run simple generation with
    given number of vertices and radius. If given output
    file name save generate graph as png file

    Args:
        command_args: Argument to command.
    """

    parser = argparse.ArgumentParser()

    parser.add_argument(
        "--num", "-N", help="number of vertices", type=int, required=False, default=100
    )

    parser.add_argument(
        "--radius",
        "-R",
        help="radius - max distance between nodes",
        type=lambda x: check_radius(parser, x),
        required=False,
        default=0.1,
    )

    parser.add_argument(
        "--output",
        "-O",
        help="name of output file with graph",
        required=False,
        default=None,
    )

    # parse arguments
    args = parser.parse_args(command_args)

    # generate simple graph with given number of vertices and radius
    g = generate_simple_random_graph(args.num, args.radius)
    g = g[0]

    # draw graph
    pos = nx.get_node_attributes(g, "pos")
    nx.draw_networkx(g, pos, node_size=10, with_labels=False)

    # check if output argument given and save or show
    if args.output is None:
        plt.show()
    else:
        plt.savefig(args.output, format="png", dpi=300)