Esempio n. 1
0
def run_bc(property_graph: PropertyGraph, input_args, source_node_file):
    property_name = "NewProp"
    start_node = input_args["source_node"]

    bc_plan = analytics.BetweennessCentralityPlan.level()

    n = 4
    if not source_node_file == "":
        if not os.path.exists(source_node_file):
            print(f"Source node file doesn't exist: {source_node_file}")
        sources = open(source_node_file, "r").readlines()

        for i in range(0, len(sources), n):
            sources_to_use = [int(i) for i in sources[i : i + n]]
            print(f"Using source: {sources_to_use}")
            with time_block("betweenness centrality"):
                analytics.betweenness_centrality(property_graph, property_name, sources_to_use, bc_plan)

            check_schema(property_graph, property_name)

            stats = analytics.BetweennessCentralityStatistics(property_graph, property_name)
            print(f"STATS:\n{stats}")
            property_graph.remove_node_property(property_name)
    else:
        sources = [start_node]
        with time_block("betweenness centrality"):
            analytics.betweenness_centrality(property_graph, property_name, sources, bc_plan)

        check_schema(property_graph, property_name)

        stats = analytics.BetweennessCentralityStatistics(property_graph, property_name)
        print(f"STATS:\n{stats}")
        property_graph.remove_node_property(property_name)
Esempio n. 2
0
def test_betweenness_centrality_level(property_graph: PropertyGraph):
    property_name = "NewProp"

    betweenness_centrality(property_graph, property_name, 16,
                           BetweennessCentralityPlan.level())

    node_schema: Schema = property_graph.node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    stats = BetweennessCentralityStatistics(property_graph, property_name)

    assert stats.min_centrality == 0
    assert stats.max_centrality == approx(8210.38)
    assert stats.average_centrality == approx(1.3645)
Esempio n. 3
0
def run_bc(property_graph: PropertyGraph, input_args, source_node_file,
           num_sources):
    property_name = "NewProp"
    start_node = input_args["source_node"]

    bc_plan = analytics.BetweennessCentralityPlan.level()

    if not source_node_file == "":
        if not os.path.exists(source_node_file):
            print(f"Source node file doesn't exist: {source_node_file}")
        with open(source_node_file, "r") as fi:
            sources = [int(l) for l in fi.readlines()]

        assert num_sources <= len(sources)
        runs = (len(sources) + num_sources - 1) // num_sources

        for run in range(0, runs):
            start_idx = (num_sources * run) % len(sources)
            rotated_sources = sources[start_idx:] + sources[:start_idx]
            sources = rotated_sources[:num_sources]

            print(f"Using sources: {sources}")
            with time_block("betweenness centrality"):
                analytics.betweenness_centrality(property_graph, property_name,
                                                 sources, bc_plan)

            check_schema(property_graph, property_name)

            stats = analytics.BetweennessCentralityStatistics(
                property_graph, property_name)
            print(f"STATS:\n{stats}")
            property_graph.remove_node_property(property_name)
    else:
        sources = [start_node]
        print(f"Using sources: {sources}")
        with time_block("betweenness centrality"):
            analytics.betweenness_centrality(property_graph, property_name,
                                             sources, bc_plan)

        check_schema(property_graph, property_name)

        stats = analytics.BetweennessCentralityStatistics(
            property_graph, property_name)
        print(f"STATS:\n{stats}")
        property_graph.remove_node_property(property_name)