Example #1
0
def get_layers(bins, pallet, rot_article=False, rot_pallet=False):
    for abin in bins:
        bins[abin] = sorted(bins[abin], key=lambda article: article['Article']['Length']*article['Article']['Width'], reverse=True)
        plength, pwidth = (pallet['Dimensions']['Length'], pallet['Dimensions']['Width'])
        if rot_pallet:
            root, layer, rest = arrange_in_layer(bins[abin], pwidth, plength, rot_article=rot_article)
        else:
            root, layer, rest = arrange_in_layer(bins[abin], plength, pwidth, rot_article=rot_article)
        while layer:
            spread_articles(root)
            if rot_pallet:
                rotate(root)

            occupied_area = 0
            for article in layer:
                length, width = article['Article']['Length'], article['Article']['Width']
                occupied_area += length*width

            # print "layer occupation:", occupied_area/float(plength*pwidth)
            if occupied_area/float(plength*pwidth) <= 0.7:
                rot_article, rot_pallet = (yield None, layer)
            else:
                rot_article, rot_pallet = (yield layer, None)

            if rot_pallet:
                root, layer, rest = arrange_in_layer(rest, pwidth, plength, rot_article=rot_article)
            else:
                root, layer, rest = arrange_in_layer(rest, plength, pwidth, rot_article=rot_article)
Example #2
0
def get_layers(bins, pallet, rot_article=False, rot_pallet=False):
    for abin in bins:
        bins[abin] = sorted(bins[abin],
                            key=lambda article: article['Article']['Length'] *
                            article['Article']['Width'],
                            reverse=True)
        plength, pwidth = (pallet['Dimensions']['Length'],
                           pallet['Dimensions']['Width'])
        if rot_pallet:
            root, layer, rest = arrange_in_layer(bins[abin],
                                                 pwidth,
                                                 plength,
                                                 rot_article=rot_article)
        else:
            root, layer, rest = arrange_in_layer(bins[abin],
                                                 plength,
                                                 pwidth,
                                                 rot_article=rot_article)
        while layer:
            spread_articles(root)
            if rot_pallet:
                rotate(root)

            occupied_area = 0
            for article in layer:
                length, width = article['Article']['Length'], article[
                    'Article']['Width']
                occupied_area += length * width

            # print "layer occupation:", occupied_area/float(plength*pwidth)
            if occupied_area / float(plength * pwidth) <= 0.7:
                rot_article, rot_pallet = (yield None, layer)
            else:
                rot_article, rot_pallet = (yield layer, None)

            if rot_pallet:
                root, layer, rest = arrange_in_layer(rest,
                                                     pwidth,
                                                     plength,
                                                     rot_article=rot_article)
            else:
                root, layer, rest = arrange_in_layer(rest,
                                                     plength,
                                                     pwidth,
                                                     rot_article=rot_article)
Example #3
0
def evaluate_layers_rests(layers, rests, score_max, pallet, result_max):
    rest_layers = list()
    # sort rests by space they cover and move them to the center of the pile
    # append them to the layer list
    for rest in sorted(rests, key=lambda rest: sum([article['Article']['Length']*article['Article']['Width'] for article in rest]), reverse=True):
        plength, pwidth = (pallet['Dimensions']['Length'], pallet['Dimensions']['Width'])
        root, layer, rest = arrange_in_layer(rest, plength, pwidth)

        com_x = 0
        com_y = 0
        leftmost = pallet['Dimensions']['Length']
        rightmost = 0
        bottommost = pallet['Dimensions']['Width']
        topmost = 0
        for article in layer:
            com_x += article['PlacePosition']['X']
            com_y += article['PlacePosition']['Y']
            if article['PlacePosition']['X']-article['Article']['Length']/2 < leftmost:
                leftmost = article['PlacePosition']['X']-article['Article']['Length']/2
            if article['PlacePosition']['X']+article['Article']['Length']/2 > rightmost:
                rightmost = article['PlacePosition']['X']+article['Article']['Length']/2
            if article['PlacePosition']['Y']-article['Article']['Width']/2 < bottommost:
                bottommost = article['PlacePosition']['Y']-article['Article']['Width']/2
            if article['PlacePosition']['Y']+article['Article']['Width']/2 > topmost:
                topmost = article['PlacePosition']['Y']+article['Article']['Width']/2
        com_x, com_y = com_x/len(layer), com_y/len(layer)

        llength = rightmost - leftmost
        lwidth = topmost - bottommost

        if com_x < llength-plength/2:
            com_x = llength-plength/2
        elif com_x > plength/2:
            com_x = plength/2
        if com_y < lwidth-pwidth/2:
            com_y = lwidth-pwidth/2
        elif com_y > pwidth/2:
            com_y = pwidth/2

        diff_x, diff_y = plength*0.5-com_x, pwidth*0.5-com_y

        for article in layer:
            article['PlacePosition']['X'] += diff_x
            article['PlacePosition']['Y'] += diff_y

        rest_layers.append(layer)

    if try_permutations:
        permutations = itertools.permutations(layers)
    else:
        #permutations = [tuple(sorted(layers, key=lambda layer: sum([article['Article']['Weight'] for article in layer]), reverse=True))]
        #permutations = [tuple(sorted(layers, key=lambda layer: sum([article['Article']['Length']*article['Article']['Width'] for article in layer]), reverse=True))]
        #permutations = (layers for i in xrange(1000))
        permutations = [layers]

    i = 0
    for permut_layers in permutations:
        permut_layers = list(permut_layers)
        if try_random:
            random.shuffle(permut_layers)
        if try_multi_pallet:
            packlist = pack_multi_pallet(permut_layers, rest_layers, pallet)
            score = evaluate_multi_pallet(packlist)
        else:
            packlist = pack_single_pallet(permut_layers, rest_layers, pallet)
            score = evaluate_single_pallet(packlist)

        if score >= score_max[0]:
            result_max[0] = dicttoxmlstring(packlist)
            score_max[0] = score

        i+=1
        if max_iter != -1 and i >= max_iter:
            break