Beispiel #1
0
def compute_coverage_map(grid_size = 100):
    swlat=34.018212
    swlng=-118.291716
    nelat=34.025296
    nelng=-118.279826
    videos = get_videos(swlat, swlng, nelat, nelng)

    map = np.ndarray(shape=(grid_size, grid_size), dtype=int)
    for video in videos:
        if IS_FROM_MEDIAQ:
            if video.properties['vid']:
                vid = str(video.properties['vid'])
                fovs = getFOVs(vid)

                if fovs and len(fovs) > 0:
                    for fov in fovs.features:
                        f = FOV(fov)
                        param = Params(200, swlat, swlng, nelat, nelng)
                        param.GRID_SIZE = grid_size
                        for cid in f.cellids(param):
                            cell_lat, cell_lng = cell_coord(cid, param)
                            if f.cover(cell_lat, cell_lng):
                                y_idx = cid/param.GRID_SIZE
                                x_idx = cid - y_idx*param.GRID_SIZE
                                # print x_idx, y_idx, map[x_idx][y_idx]
                                map[x_idx][y_idx] = map[x_idx][y_idx] + 1
        else:
            for f in video.fovs:
                param = Params(200, swlat, swlng, nelat, nelng)
                param.GRID_SIZE = grid_size
                for cid in f.cellids(param):
                    cell_lat, cell_lng = cell_coord(cid, param)
                    if f.cover(cell_lat, cell_lng):
                        y_idx = cid/param.GRID_SIZE
                        x_idx = cid - y_idx*param.GRID_SIZE
                        # print x_idx, y_idx, map[x_idx][y_idx]
                        map[x_idx][y_idx] = map[x_idx][y_idx] + 1

    fig, ax = plt.subplots()
    heatmap = ax.pcolor(map, cmap=plt.cm.Reds)
    plt.show()
    plt.close()
    np.savetxt("mediaq_coverage_heatmap.txt" , map, fmt='%i\t')
Beispiel #2
0
def compute_coverage_map(grid_size=100):
    swlat = 34.018212
    swlng = -118.291716
    nelat = 34.025296
    nelng = -118.279826
    videos = get_videos(swlat, swlng, nelat, nelng)

    map = np.ndarray(shape=(grid_size, grid_size), dtype=int)
    for video in videos:
        if IS_FROM_MEDIAQ:
            if video.properties['vid']:
                vid = str(video.properties['vid'])
                fovs = getFOVs(vid)

                if fovs and len(fovs) > 0:
                    for fov in fovs.features:
                        f = FOV(fov)
                        param = Params(200, swlat, swlng, nelat, nelng)
                        param.GRID_SIZE = grid_size
                        for cid in f.cellids(param):
                            cell_lat, cell_lng = cell_coord(cid, param)
                            if f.cover(cell_lat, cell_lng):
                                y_idx = cid / param.GRID_SIZE
                                x_idx = cid - y_idx * param.GRID_SIZE
                                # print x_idx, y_idx, map[x_idx][y_idx]
                                map[x_idx][y_idx] = map[x_idx][y_idx] + 1
        else:
            for f in video.fovs:
                param = Params(200, swlat, swlng, nelat, nelng)
                param.GRID_SIZE = grid_size
                for cid in f.cellids(param):
                    cell_lat, cell_lng = cell_coord(cid, param)
                    if f.cover(cell_lat, cell_lng):
                        y_idx = cid / param.GRID_SIZE
                        x_idx = cid - y_idx * param.GRID_SIZE
                        # print x_idx, y_idx, map[x_idx][y_idx]
                        map[x_idx][y_idx] = map[x_idx][y_idx] + 1

    fig, ax = plt.subplots()
    heatmap = ax.pcolor(map, cmap=plt.cm.Reds)
    plt.show()
    plt.close()
    np.savetxt("mediaq_coverage_heatmap.txt", map, fmt='%i\t')
Beispiel #3
0
def optimization(tree, fov_count, seed, param):
    np.random.seed(seed)
    fovs_file = re.sub(r"\.dat$", "", param.dataset) + ".txt"
    videos = read_data(fovs_file)

    fovs = []
    for v in videos:
        leaf_node = tree.leafCover(v.location())
        if leaf_node:
            v.size = np.random.zipf(param.ZIPFIAN_SKEW)
            if v.size > 20:
                v.size = 20
            v.fov_count = int(v.size)
            fovs = fovs + v.get_fovs()
        # else:
        #     print "not a leaf node", v.location()

    universe = Set([i for i in range(param.GRID_SIZE * param.GRID_SIZE)])
    all_sets = {}
    for i in range(len(fovs)):
        all_sets[i] = fovs[i].cellids(param)

    weights = {}
    count = 0
    last_weight = 0
    for item in universe:
        coord = cell_coord(item, param)
        # print coord
        leaf_node = tree.leafCover(coord)
        if leaf_node is not None:
            compute_urgency(leaf_node)
            boundary = np.array([[param.x_min, param.y_min], [param.x_max, param.y_max]])
            coverage_ratio = min(
                1, rect_area(boundary) / (param.GRID_SIZE * param.GRID_SIZE * rect_area(leaf_node.n_box))
            )
            weights[item] = leaf_node.urgency * coverage_ratio
            last_weight = weights[item]
        else:
            weights[item] = last_weight
            count = count + 1

    # print count
    # print universe
    # print all_sets
    # print fov_count
    # print weights

    start = time.time()

    covered_sets, covered_items, covered_weight = max_cover(universe, all_sets, fov_count, weights)
    print "time ", time.time() - start

    print covered_weight
    return covered_weight
Beispiel #4
0
def optimization(tree, fov_count, seed, param):
    np.random.seed(seed)
    fovs = read_image_data(param.dataset)

    universe = Set([i for i in range(param.GRID_SIZE*param.GRID_SIZE)])
    all_sets = {}
    for i in range(len(fovs)):
        all_sets[i] = fovs[i].cellids(param)

    weights = {}
    count = 0
    last_weight = 0
    for item in universe:
        coord = cell_coord(item, param)
        # print coord
        leaf_node = tree.leafCover(coord)
        if leaf_node is not None:
            compute_urgency(leaf_node)
            boundary = np.array([[param.x_min, param.y_min],[param.x_max, param.y_max]])
            coverage_ratio = min(1, rect_area(boundary)/(param.GRID_SIZE*param.GRID_SIZE*rect_area(leaf_node.n_box)))
            weights[item] = leaf_node.urgency*coverage_ratio
            last_weight = weights[item]
        else:
            weights[item] = last_weight
            count = count + 1
    # print count
    # print universe
    # print all_sets
    # print fov_count
    # print weights

    start = time.time()

    covered_sets, covered_items, covered_weight = max_cover(universe, all_sets, fov_count, weights)
    print "time ", time.time() - start

    print covered_weight
    return covered_weight