Exemple #1
0
def find_resource_hierarchies_scattered_local(itvs, hy, rqts):
    l_hy = len(hy)
    #    print "find itvs: ", itvs, rqts[0]
    if (l_hy == 1):
        return extract_n_scattered_block_itv(itvs, hy[0], rqts[0])
    else:
        return find_resource_n_h_local(itvs, hy, rqts, hy[0], 0, l_hy)
Exemple #2
0
def find_resource_n_h(itvs, hy, rqts, top, h, h_bottom):

    # potentiel available blocks
    avail_bks = keep_no_empty_scat_bks(itvs, top)
    l_avail_bks = len(avail_bks)

    if (l_avail_bks < rqts[h]):
        # not enough scattered blocks
        return []
    else:
        if (h == h_bottom - 2):
            # reach last level hierarchy of requested resource
            # iter on top and find rqts[h-1] block
            itvs_acc = []
            i = 0
            nb_r = 0
            while (i < l_avail_bks) and (nb_r != rqts[h]):  # need
                # print avail_bks[i], "*", hy[h+1]
                # TODO test cost of [] filtering .....
                avail_sub_bks = [
                    intersec(avail_bks[i], x) for x in hy[h + 1] if intersec(avail_bks[i], x) != []]
                # print avail_sub_bks
                # print "--------------------------------------"
                r = extract_n_scattered_block_itv(
                    itvs, avail_sub_bks, rqts[h + 1])
                # r = []
                if (r != []):
                    # win for this top_block
                    itvs_acc.extend(r)
                    nb_r += 1
                i += 1
            if (nb_r == rqts[h]):
                return itvs_acc
            else:
                return []

        else:
            # intermediate hierarchy level
            # iter on available_bk
            itvs_acc = []
            i = 0
            nb_r = 0
            while (i < l_avail_bks) and (nb_r != rqts[h]):
                r = find_resource_n_h(
                    itvs, hy, rqts, [avail_bks[i]], h + 1, h_bottom)
                if (r != []):
                    # win for this top_block
                    itvs_acc.extend(r)
                    nb_r += 1
                i += 1
            if (nb_r == rqts[h]):
                return itvs_acc
            else:
                return []
Exemple #3
0
def test_extract_n_scattered_block_itv_2():
    y = [[(1, 4), (10, 17)], [(6, 9), (19, 22)], [(25, 30)]]
    a = extract_n_scattered_block_itv([(1, 30)], y, 2)
    assert a == [(1, 4), (6, 9), (10, 17), (19, 22)]
Exemple #4
0
def test_extract_n_scattered_block_itv_1():
    y = [[(1, 4), (6, 9)], [(10, 17)], [(20, 30)]]
    a = extract_n_scattered_block_itv([(1, 30)], y, 3)
    assert a == [(1, 4), (6, 17), (20, 30)]