Пример #1
0
    suitability_graph.append_graph(graph)

    suitability_graph.extend_suitable_regions(seed, generator)
    suitability_graph.extend_suitable_regions(seed, generator)

    regions = suitability_graph.get_suitable_regions(generator)

    # suitability_graph.contract_suitable_regions(generator)

    # paths = []
    # for t in terminals:
    #     _, paths_t = dijkstra(suitability_graph, t, [poi], consider_node_weights=False)
    #     paths.append(paths_t[poi])

    # _, paths_poi = suitability_graph.compute_shortest(poi, terminals)
    suitability_graph.compute_dist_paths(origins=[poi], destinations=terminals)
    paths = [
        suitability_graph.paths[tuple(sorted([t, poi]))] for t in terminals
    ]

    tree = SuitabilityGraph()
    for p in paths:
        tree.append_path(p, suitability_graph)

    ngh = NetworkXGraphHelper(suitability_graph)
    ngh.draw_graph(
        special_nodes=[(terminals, None, None), ([poi], None, None)],
        # subgraphs_1=[r for _, (r, _, _, _, _, _) in regions.iteritems()],
        special_subgraphs=[(tree, None)],
        print_node_labels=False)
Пример #2
0
if __name__ == '__main__':

    m = 30
    n = 30
    seed = 0

    generator = SuitableNodeWeightGenerator()
    graph = GridDigraphGenerator().generate(m,
                                            n,
                                            node_weighted=True,
                                            node_weight_generator=generator,
                                            seed=seed)

    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(graph)
    suitability_graph.compute_dist_paths(compute_paths=False)

    pois = [265, 312]
    hot_spots = suitability_graph.get_suitable_nodes(generator,
                                                     excluded_nodes=pois)
    nodes_left_rh = list(
        set(suitability_graph.keys()).difference(pois).difference(hot_spots))
    ind = np.random.choice(a=len(nodes_left_rh), size=30, replace=False)
    terminals = [nodes_left_rh[i] for i in ind]

    hot_spots = set(
        suitability_graph.keys()).difference(terminals).difference(pois)

    for awareness in np.arange(0.0, 1.1, 0.1):
        hb = HotspotBased(suitability_graph,
                          terminals,
Пример #3
0
        print("seed:", seed)
        for msns in range(len(ms)):
            print("nodes:", ms[msns] * ns[msns])
            graph = GridDigraphGenerator().generate(
                ms[msns],
                ns[msns],
                node_weighted=True,
                node_weight_generator=generator,
                seed=seed)
            suitability_graph = SuitabilityGraph()
            suitability_graph.append_graph(graph)
            hotspots = suitability_graph.get_suitable_nodes(generator)

            start_time = time.clock()
            suitability_graph.compute_dist_paths(origins=hotspots,
                                                 destinations=hotspots,
                                                 compute_paths=False)
            print "compute", time.clock() - start_time, "# hotspots:", len(
                hotspots)

            for num_seats in capacity:
                # suitability_graph.extend_suitable_regions(seed, generator)
                # hotspots = suitability_graph.get_suitable_nodes(generator)
                # print i, "# hotspots:", len(hotspots)
                for num_terminals in nums_terminals:
                    new_terminals = set()
                    for sample in range(num_samples):
                        graph_temp = SuitabilityGraph()
                        graph_temp.append_graph(suitability_graph)
                        graph_temp.dist = dict(suitability_graph.dist)
                        graph_temp.pairs_dist_paths = set(
Пример #4
0
    seed = 1
    m = n = 10

    gh = GridDigraphGenerator()
    graph = gh.generate(m,
                        n,
                        edge_weighted=False,
                        node_weighted=True,
                        node_weight_generator=generator,
                        seed=seed)

    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(graph)

    suitability_graph.extend_suitable_regions(seed, generator)
    suitability_graph.extend_suitable_regions(seed, generator)

    regions = suitability_graph.get_suitable_regions(generator)

    suitability_graph.contract_suitable_regions(generator)

    ngh = NetworkXGraphHelper(suitability_graph)
    ngh.draw_graph(print_node_labels=True)

    suitability_graph.compute_dist_paths(origins=[53], destinations=[65, 86])
    print suitability_graph.dist[(53, 65)], suitability_graph.paths[(53, 65)]
    print suitability_graph.dist[(53, 86)], suitability_graph.paths[(53, 86)]

    suitability_graph.compute_dist_paths(origins=[28], destinations=[72])
    print suitability_graph.dist[(28, 72)], suitability_graph.paths[(28, 72)]