예제 #1
0
def get_suitability_graph_from_session(request):
    graph = request.session['graph']
    suitability_graph = SuitabilityGraph()
    for node_id, (node_weight, adj_dict, data) in graph.iteritems():
        new_adj_dict = {int(neighbour): edge_cost for neighbour, edge_cost in adj_dict.iteritems()}
        suitability_graph[int(node_id)] = (node_weight, new_adj_dict, data)
    dist = {}
    for k, v in request.session['dist'].iteritems():
        k_ = k.split(",")
        dist[(long(k_[0]), long(k_[1]))] = v
    suitability_graph.dist = dist
    pairs = set()
    for k in request.session['pairs_dist_paths']:
        k_ = k.split(",")
        pairs.add((long(k_[0]), long(k_[1])))
    suitability_graph.pairs_dist_paths = pairs

    return suitability_graph
예제 #2
0
            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(
                            suitability_graph.pairs_dist_paths)
                        graph_temp.method_dist_paths = suitability_graph.method_dist_paths
                        print("sample:", sample)
                        terminals = np.random.choice(a=ms[msns] * ns[msns],
                                                     size=num_terminals +
                                                     max(nums_pois),
                                                     replace=False)
                        # while len(set(hotspots).intersection(terminals)) != 0:
                        #     terminals = np.random.choice(a=size * size, size=num_terminals + max(nums_pois), replace=False)
                        temp = set(hotspots)
                        temp.update(terminals)
                        start_time = time.clock()
                        graph_temp.update_dist_paths(temp, compute_paths=False)
                        print "update", time.clock() - start_time