def test_lower_bound_dict(self):
        box_list1 = [ds.Box(3, 5, 2) for i in range(5)]
        box_list2 = [ds.Box(2, 2, 2) for i in range(5)]
        box_list3 = [ds.Box(2, 2, 4) for i in range(5)]
        for box in box_list1:
            box.itemName = 'item1'
            box.weight = 10
            box.maximumWeight = 10
        for box in box_list2:
            box.itemName = 'item2'
            box.weight = 5
            box.maximumWeight = 4
        for box in box_list3:
            box.itemName = 'item3'
            box.weight = 4
            box.maximumWeight = 4
        box_list = box_list1 + box_list2 + box_list3
        box_set = ds.BoxSet(box_list)
        box_set2 = ds.BoxSet(box_list)

        self.assertEqual(True, box_set.__eq__(box_set2))
        self.assertEqual(False, box_set.__eq__(ds.BoxSet(box_list[:-1])))
예제 #2
0
def assign_box_to_bin_v2(box,
                         current_problem,
                         i,
                         not_placed_boxes,
                         optimal_solutions,
                         lower_bounds,
                         optimal=True,
                         nodes=5000,
                         optimized=True):
    to_place = [box] + current_problem.M[i].boxList
    bs = ds.BoxSet(to_place)
    optimal_placement = get_soluzione_ottima(bs, optimal_solutions)
    if optimal_placement is None:
        new_p = current_problem.__copy__()
        new_not_placed_boxes = [b for b in not_placed_boxes[1:]]
        new_p.boxList = new_not_placed_boxes
        new_sbp = new_p.M[i]
        new_sbp.add_boxes(box)
        h2_result = ds.H2(new_sbp.boxList, new_p.bin, optimized=optimized)
        if len(h2_result) == 1:
            new_p.M[i] = h2_result[0]
            add_optimal_solution(optimal_solutions,
                                 h2_result[0].placement_best_solution)
            return new_p, []

        #print "sto usando fill bin"
        if not optimal:
            new_sbp.max_nodes = nodes
            new_sbp.m_cut = True
            new_sbp.m = 1
        single_bin_result = new_sbp.fillBin(optimized=optimized)
        if single_bin_result == []:
            add_optimal_solution(optimal_solutions,
                                 new_sbp.placement_best_solution)
        else:
            insert_lower_bound(
                lower_bounds, current_problem.M[i].boxList + single_bin_result)
        return new_p, single_bin_result
    else:
        new_p = current_problem.__copy__()
        new_not_placed_boxes = [b for b in not_placed_boxes[1:]]
        new_p.boxList = new_not_placed_boxes
        new_sbp = new_p.M[i]
        new_sbp.boxList = optimal_placement.placement
        new_sbp.placement_best_solution = optimal_placement.placement
        #print "soluzione ottima riutilizzata"
        return new_p, []
예제 #3
0
def add_optimal_solution(optimal_solutions, placement_best_solution):
    bs = ds.BoxSet(placement_best_solution)
    bs.add_placement(placement_best_solution)
    optimal_solutions.append(bs)
예제 #4
0
def check_lower_bound(lower_bounds, box_list):
    if ds.BoxSet(box_list) in lower_bounds:
        print "match lower bound"
        return False
    return True
예제 #5
0
def insert_lower_bound(lower_bounds, box_list):
    bs = ds.BoxSet(box_list)
    lower_bounds.append(bs)