Пример #1
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
Пример #2
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