Пример #1
0
        mst_terminals_mc.get_edges())

    # suitable_nodes = suitability_graph.get_suitable_nodes(generator, excluded_nodes=terminals)
    # closures_edges = set()
    # msts_edges = set()
    # for sn in suitable_nodes:
    #     t_sn = list(terminals)
    #     t_sn.append(sn)
    #     t_sn_mc = suitability_graph.build_metric_closure(t_sn)
    #     mst_t_sn_mc = Prim(t_sn_mc).spanning_tree()
    #     closures_edges.update(t_sn_mc.get_edges())
    #     msts_edges.update(mst_t_sn_mc.get_edges())
    # ee = closures_edges - msts_edges
    # excluded_edges.update(ee)

    suitability_mc = suitability_graph.build_suitability_metric_closure(
        generator, terminals, excluded_edges)
    dr = Dreyfus(suitability_mc)
    st, cost = dr.steiner_tree(terminals, consider_terminals=False)
    steiner_tree = suitability_graph.build_subgraph_from_metric_closure(st)
    elapsed_time = time.clock() - start_time

    cost, node_cost = steiner_tree.compute_total_weights(terminals)

    special_subgraphs = [(r, "#00FF00")
                         for _, (r, _, _, _, _, _) in regions.iteritems()]
    special_subgraphs.append((steiner_tree, "#FF0000"))

    ngh = NetworkXGraphHelper(suitability_graph)
    ngh.draw_graph(special_nodes=[(terminals, None, None)],
                   special_subgraphs=special_subgraphs,
                   title_1="Dreyfus (metric closure), seed = " + str(seed),
Пример #2
0
if __name__ == '__main__':

    generator = SuitableNodeWeightGenerator()

    seed = 0
    m = n = 40

    gh = GridDigraphGenerator()

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

    terminals = [0, 90]
    poi = 55

    terminals_poi = list(terminals)
    terminals_poi.append(poi)

    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(node_weighted)
    exclusive = suitability_graph.build_suitability_metric_closure(
        generator, terminals_poi)

    ngh = NetworkXGraphHelper(exclusive)
    ngh.draw_graph(print_node_labels=True)
Пример #3
0
                                node_weighted=True,
                                node_weight_generator=generator,
                                seed=seed)

    terminals = [288, 315, 231, 312, 111, 609, 645, 434, 654, 469, 186]

    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(node_weighted)

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

    regions = suitability_graph.get_suitable_regions(generator)

    start_time = time.clock()
    suitability_mc = suitability_graph.build_suitability_metric_closure(
        generator, terminals)
    rs = RaywardSmith(suitability_mc, terminals)
    st = rs.steiner_tree()
    steiner_tree = suitability_graph.build_subgraph_from_metric_closure(st)
    elapsed_time = time.clock() - start_time

    cost, node_cost = steiner_tree.compute_total_weights(terminals)

    ngh = NetworkXGraphHelper(suitability_graph)
    ngh.draw_graph(
        nodes_2=terminals,
        subgraphs_1=[r for _, (r, _, _) in regions.iteritems()],
        subgraphs_2=[steiner_tree],
        node_weight_generator=generator,
        title_1="Rayward-Smith (metric closure), seed = " + str(seed),
        title_2="Cost: " + str(cost - node_cost) + ", elapsed time: " +