From 7ef525156f7410eeeb5d956d1c648ba80d51eba3 Mon Sep 17 00:00:00 2001 From: josch Date: Wed, 16 May 2012 07:47:24 +0200 Subject: [PATCH] when centering rest, do not create an overhang --- bruteforce3.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/bruteforce3.py b/bruteforce3.py index 01091af..28087ed 100644 --- a/bruteforce3.py +++ b/bruteforce3.py @@ -102,15 +102,37 @@ def evaluate_layers_rests(layers, rests, score_max, pallet, result_max): 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 - #TODO: for long/wide layers the center of mass might delta might - # create an overhang over one side of the pallet for article in layer: article['PlacePosition']['X'] += diff_x article['PlacePosition']['Y'] += diff_y