def worker(landmarks, graph, graph_coords, pids, out_q, counter):
     """ The worker function, invoked in a process. 'nums' is a
         list of numbers to factor. The results are placed in
         a dictionary that's pushed to a queue.
     """
     lm_est = {}
     for lm_id, lm_coord in landmarks:
         lm_est[lm_id] = {}
         x, y = lm_coord
         for pid, coord in graph_coords.items():
             lm_est[lm_id][pid] = haversine(x, y, coord[0], coord[1])
     qtree = point_dict_to_quadtree(graph_coords, multiquadtree=True)
     lm_dists = defaultdict(list)
     l = len(graph_coords)
     for pid in pids:
         counter.value += 1
         print counter.value, '/', l, ':', pid
         for landmark, _ in landmarks:
             try:
                 d = lm_exact_dist(pid, landmark, graph, graph_coords,
                                   lm_est)
             except KeyError:
                 d = None
             lm_dists[pid].append(d)
     out_q.put(lm_dists)
def main():
    graph, graph_coords = load_graph()
    origin = 37.772614,-122.423798
    k = 16
    qtree = point_dict_to_quadtree(graph_coords, multiquadtree=True)
    landmarks = planar_landmark_selection(k, origin, graph_coords, graph, qtree)
    # create a quadtree that can hold multiple items per point
    
    landmarks = zip([find_closest_node(l, qtree) for l in landmarks], landmarks)
    lm_dists = mp_landmark_distances(landmarks, graph, graph_coords, 8)
    with open('lm_dists_2.j', 'w') as fp:
        fp.write(json.dumps(lm_dists))
def main():
    graph, graph_coords = load_graph()
    origin = 37.772614, -122.423798
    k = 16
    qtree = point_dict_to_quadtree(graph_coords, multiquadtree=True)
    landmarks = planar_landmark_selection(k, origin, graph_coords, graph,
                                          qtree)
    # create a quadtree that can hold multiple items per point

    landmarks = zip([find_closest_node(l, qtree) for l in landmarks],
                    landmarks)
    lm_dists = mp_landmark_distances(landmarks, graph, graph_coords, 8)
    with open('lm_dists_2.j', 'w') as fp:
        fp.write(json.dumps(lm_dists))
def landmark_distances(landmarks, graph, graph_coords):
    lm_est = {}
    for lm_id, lm_coord in landmarks:
        lm_est[lm_id] = {}
        x, y = lm_coord
        for pid, coord in graph_coords.items():
            lm_est[lm_id][pid] = haversine(x, y, coord[0], coord[1])
    qtree = point_dict_to_quadtree(graph_coords, multiquadtree=True)
    lm_dists = defaultdict(list)
    l = len(graph_coords)
    for i, pid in enumerate(graph_coords):
        print i, '/', l, ':', pid
        for landmark, _ in landmarks:
            try:
                d = lm_exact_dist(pid, landmark, graph, graph_coords, lm_est)
            except KeyError:
                d = None
            lm_dists[pid].append(d)
    return lm_dists
def landmark_distances(landmarks, graph, graph_coords):
    lm_est = {}
    for lm_id, lm_coord in landmarks:
        lm_est[lm_id] = {}
        x,y = lm_coord
        for pid, coord in graph_coords.iteritems():
            lm_est[lm_id][pid] = haversine(x, y, coord[0], coord[1])
    qtree = point_dict_to_quadtree(graph_coords, multiquadtree=True)
    lm_dists = defaultdict(list)
    l = len(graph_coords)
    for i, pid in enumerate(graph_coords):
        print i, '/', l, ':', pid
        for landmark, _ in landmarks:
            try:
                d = lm_exact_dist(pid, landmark, graph, graph_coords, lm_est)
            except KeyError:
                d = None
            lm_dists[pid].append(d)
    return lm_dists
 def worker(landmarks, graph, graph_coords, pids, out_q, counter):
     """ The worker function, invoked in a process. 'nums' is a
         list of numbers to factor. The results are placed in
         a dictionary that's pushed to a queue.
     """
     lm_est = {}
     for lm_id, lm_coord in landmarks:
         lm_est[lm_id] = {}
         x,y = lm_coord
         for pid, coord in graph_coords.iteritems():
             lm_est[lm_id][pid] = haversine(x, y, coord[0], coord[1])
     qtree = point_dict_to_quadtree(graph_coords, multiquadtree=True)
     lm_dists = defaultdict(list)
     l = len(graph_coords)
     for pid in pids:
         counter.value += 1
         print counter.value, '/', l, ':', pid
         for landmark, _ in landmarks:
             try:
                 d = lm_exact_dist(pid, landmark, graph, graph_coords, lm_est)
             except KeyError:
                 d = None
             lm_dists[pid].append(d)
     out_q.put(lm_dists)