예제 #1
0
 def Ai(self, k, r, X, i):
     T = SuitabilityGraph()
     while k > 0:
         TBEST = SuitabilityGraph()
         for kprime in range(1, k + 1):
             for v in self.__nodes:
                 if i > 1:
                     Tprime = self.Ai(kprime, v, X, i - 1)
                     p = self.__paths[tuple(sorted([r, v]))]
                     Tprime.append_path(p, self.__graph)
                 else:
                     dists = {}
                     for t in self.__terminals:
                         dists[t] = self.__dist[tuple(sorted([v, t]))]
                     ord_term = sorted(dists.iteritems(),
                                       key=operator.itemgetter(1))
                     Tprime = SuitabilityGraph()
                     for j in range(kprime):
                         p = self.__paths[tuple(sorted([v,
                                                        ord_term[j][0]]))]
                         Tprime.append_path(p, self.__graph)
                 if self.d(TBEST) > self.d(Tprime):
                     TBEST = Tprime
         T.append_graph(TBEST)
         k -= len(set(TBEST.keys()).intersection(X))
         X = set(X).difference(TBEST.keys())
     return T
예제 #2
0
    # pois = [359, 834, 520, 378, 755, 616, 1, 435]
    # pois = [359, 834]
    # terminals = [123, 456, 463, 897, 506, 639, 343, 232, 564, 766, 138, 469, 800]

    suitability_graph = SuitabilityGraph()
    suitability_graph.append_graph(node_weighted)

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

    hotspots = suitability_graph.get_suitable_nodes(generator)

    terminals = np.random.choice(a=m * n, size=60, replace=False)
    while set(suitability_graph.keys()).intersection(terminals) != set(
            terminals) or set(hotspots).intersection(terminals) != set():
        terminals = np.random.choice(a=m * n, size=60, replace=False)

    pois = terminals[:15]
    terminals = terminals[15:]

    regions = suitability_graph.get_suitable_regions(generator)

    hb = HotspotBased(suitability_graph, terminals, pois)
    start_time = time.clock()
    forest, cost, _, _, _, _, _ = hb.steiner_forest(clone_hotspots=True,
                                                    get_lsv=False)
    elapsed_time = time.clock() - start_time

    ngh = NetworkXGraphHelper(suitability_graph)
예제 #3
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,
                          pois,
                          hot_spots=hot_spots)
        start_time = time.clock()
        forest, cost, gr, avg_dr, num_trees, avg_oc = hb.steiner_forest(
            get_lsv=False, max_wd=2.5, awareness=awareness)
        elapsed_time = time.clock() - start_time