Exemplo n.º 1
0
def divide_biggest_ranges_in_two(z3inst, module, num_split):
    initial_num_split = num_split
    pairs = []
    for i in z3inst.cfr_sorts.values():
        glCardRange = i.numInstances - i.element.glCard[0].value + 1
        if glCardRange > 1:
            pairs.append((i, glCardRange))
        pairs.append((i, glCardRange))
    pairs.reverse()
    constraints = [True]
    try:
        while num_split != 1:
            num_split = num_split // 2
            (currSort, currRange) = pairs.pop(0)

            left1 = API.createCard(
                API.createArg(currSort.element.uid, currSort))
            right1 = API.createInteger(currSort.element.glCard[0].value +
                                       (currRange // 2))
            bc1 = CreateBracketedConstraints.CreateBracketedConstraints(
                z3inst, True)
            constraint1 = bc1.generatedConstraintVisit(
                API.createLT(left1, right1))

            left2 = API.createCard(
                API.createArg(currSort.element.uid, currSort))
            right2 = API.createInteger(currSort.element.glCard[0].value +
                                       (currRange // 2))
            bc2 = CreateBracketedConstraints.CreateBracketedConstraints(
                z3inst, True)
            constraint2 = bc2.generatedConstraintVisit(
                API.createLE(right2, left2))

            newConstraints = []
            for i in constraints:
                newConstraints.append(mAnd(i, constraint1))
            for i in constraints:
                newConstraints.append(mAnd(i, constraint2))
            constraints = newConstraints
    except:
        return safe_raise_heuristic_failure_exception(
            "divide_biggest_ranges_in_two#" + str(initial_num_split) +
            "failed.")
    if num_split != 1:
        return safe_raise_heuristic_failure_exception(
            "divide_biggest_ranges_in_two#" + str(initial_num_split) +
            "failed.")
    return constraints

    sys.exit(
        "INCOMPLETE: need to figure out what to do when run out of splits")
Exemplo n.º 2
0
def divide_biggest_ranges_in_two(z3inst, module, num_split):
    initial_num_split = num_split
    pairs = []
    for i in z3inst.cfr_sorts.values():
        glCardRange = i.numInstances - i.element.glCard[0].value + 1
        if glCardRange > 1:
            pairs.append((i, glCardRange))
        pairs.append((i, glCardRange))
    pairs.reverse()
    constraints = [True]
    try:
        while num_split != 1:
            num_split = num_split // 2
            (currSort,currRange) = pairs.pop(0)
            
            left1 = API.createCard(API.createArg(currSort.element.uid, currSort))
            right1 = API.createInteger(currSort.element.glCard[0].value + (currRange//2))
            bc1 = CreateBracketedConstraints.CreateBracketedConstraints(z3inst, True)
            constraint1 = bc1.generatedConstraintVisit(API.createLT(left1, right1))
            
            left2 = API.createCard(API.createArg(currSort.element.uid, currSort))
            right2 = API.createInteger(currSort.element.glCard[0].value + (currRange//2))
            bc2 = CreateBracketedConstraints.CreateBracketedConstraints(z3inst, True)
            constraint2 = bc2.generatedConstraintVisit(API.createLE(right2, left2))
            
            newConstraints = []
            for i in constraints:
                newConstraints.append(mAnd(i, constraint1))
            for i in constraints:
                newConstraints.append(mAnd(i, constraint2))
            constraints = newConstraints
    except:
        return safe_raise_heuristic_failure_exception("divide_biggest_ranges_in_two#" + str(initial_num_split) + "failed.") 
    if num_split != 1:
        return safe_raise_heuristic_failure_exception("divide_biggest_ranges_in_two#" + str(initial_num_split) + "failed.") 
    return constraints
    
    
    sys.exit("INCOMPLETE: need to figure out what to do when run out of splits")
Exemplo n.º 3
0
def range_split(z3inst, module, num_split, order="biggest"):
    initial_num_split = num_split
    #only consider ranges of top level abstracts that are referring to the same type of concretes
    pairs = []
    for i in z3inst.cfr_sorts.values():
        glCardRange = i.numInstances - i.element.glCard[0].value + 1
        if glCardRange > 1:
            pairs.append((i, glCardRange))
    if order == "random":
        random.shuffle(pairs)
    else:
        pairs.sort(key=operator.itemgetter(1))
        if order == "biggest":
            pairs.reverse()
    constraints = []

    splitters = []
    curr_count = 0
    for i in pairs:
        (claferSort, card_range) = i
        splitters.append(claferSort)
        curr_count = curr_count + card_range
        if curr_count >= num_split:
            break
    if curr_count < num_split:
        return safe_raise_heuristic_failure_exception(order + "_range_split" +
                                                      str(initial_num_split) +
                                                      " failed.")
    else:
        ranges = []
        for i in splitters:
            curr_range = []
            for j in range(i.element.glCard[0].value, i.numInstances + 1):
                left = API.createCard(API.createArg(i.element.uid, i))
                right = API.createInteger(j)
                bc = CreateBracketedConstraints.CreateBracketedConstraints(
                    z3inst, True)
                constraint = bc.generatedConstraintVisit(
                    API.createEquals(left, right))
                curr_range.append(constraint)
            ranges.append(curr_range)
        products = list(itertools.product(*ranges))
        products = [[And(*list(i))] for i in products]
        products = condense(products, num_split)
        return products

    return safe_raise_heuristic_failure_exception(order + "_range_split" +
                                                  str(initial_num_split) +
                                                  " failed.")
Exemplo n.º 4
0
def range_split(z3inst, module, num_split, order="biggest"):
    initial_num_split = num_split
    #only consider ranges of top level abstracts that are referring to the same type of concretes
    pairs = []
    for i in z3inst.cfr_sorts.values():
        glCardRange = i.numInstances - i.element.glCard[0].value + 1
        if glCardRange > 1:
            pairs.append((i, glCardRange))
    if order == "random":
        random.shuffle(pairs)
    else:
        pairs.sort(key=operator.itemgetter(1))
        if order == "biggest":
            pairs.reverse()
    constraints = []
    
    splitters = []
    curr_count = 0
    for i in pairs:
        (claferSort, card_range) = i
        splitters.append(claferSort)
        curr_count = curr_count + card_range
        if curr_count >= num_split:
            break
    if curr_count < num_split:
        return safe_raise_heuristic_failure_exception(order + "_range_split" + str(initial_num_split) + " failed." )
    else:
        ranges = []
        for i in splitters:
            curr_range = []
            for j in range(i.element.glCard[0].value, i.numInstances + 1):
                left = API.createCard(API.createArg(i.element.uid, i))
                right = API.createInteger(j)
                bc = CreateBracketedConstraints.CreateBracketedConstraints(z3inst, True)
                constraint = bc.generatedConstraintVisit(API.createEquals(left, right))
                curr_range.append(constraint)
            ranges.append(curr_range)
        products = list(itertools.product(*ranges))
        products = [[And(*list(i))] for i in products]
        products = condense(products, num_split)
        return products
    
    return safe_raise_heuristic_failure_exception(order + "_range_split" + str(initial_num_split) + " failed." )