include pallet rotation
This commit is contained in:
parent
41e5ec2706
commit
53350b5bff
2 changed files with 37 additions and 9 deletions
|
@ -6,14 +6,33 @@ from util import xmlfiletodict, dicttoxmlfile, get_pallet, get_articles, get_pac
|
|||
from arrange_spread2 import arrange_in_layer, spread_articles, find_articles
|
||||
import cPickle
|
||||
from binascii import b2a_base64
|
||||
import zlib
|
||||
|
||||
def rotate(node):
|
||||
if node is None:
|
||||
return
|
||||
|
||||
if node['article']:
|
||||
# exchange x and y coordinate
|
||||
node['article']['PlacePosition']['X'], node['article']['PlacePosition']['Y'] = node['article']['PlacePosition']['Y'], node['article']['PlacePosition']['X']
|
||||
# rotate article
|
||||
node['article']['Orientation'] = node['article']['Orientation']%2+1
|
||||
|
||||
rotate(node['right'])
|
||||
rotate(node['down'])
|
||||
|
||||
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:
|
||||
|
@ -26,8 +45,14 @@ def get_layers(bins, pallet, rot_article=False, rot_pallet=False):
|
|||
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)
|
||||
|
||||
def get_bit(num, pos):
|
||||
return num>>pos&1
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print "usage:", sys.argv[0], "order.xml packlist.xml"
|
||||
|
@ -49,12 +74,12 @@ def main():
|
|||
|
||||
stuff1 = list()
|
||||
|
||||
#for order in itertools.product([True, False], repeat=12):
|
||||
for order in [[True]*12,]:
|
||||
for order in itertools.product([0,1,2,3], repeat=8):
|
||||
#for order in [[True]*12,]:
|
||||
rests = list()
|
||||
layers = list()
|
||||
|
||||
it = get_layers(bins, pallet, order[0], False)
|
||||
it = get_layers(bins, pallet, get_bit(order[0], 0), get_bit(order[0], 1))
|
||||
layer, rest = it.next()
|
||||
if layer:
|
||||
layers.append(layer)
|
||||
|
@ -64,7 +89,7 @@ def main():
|
|||
fail = True
|
||||
for rot_article in order[1:]:
|
||||
try:
|
||||
layer, rest = it.send((rot_article, False))
|
||||
layer, rest = it.send((get_bit(rot_article,0), get_bit(rot_article,1)))
|
||||
if layer:
|
||||
layers.append(layer)
|
||||
if rest:
|
||||
|
@ -74,6 +99,6 @@ def main():
|
|||
break
|
||||
if fail:
|
||||
raise Exception("finished early")
|
||||
print b2a_base64(cPickle.dumps((layers, rests, pallet))),
|
||||
print b2a_base64(zlib.compress(cPickle.dumps((layers, rests, pallet)))),
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -9,6 +9,7 @@ import marshal
|
|||
from binascii import a2b_base64
|
||||
import tempfile
|
||||
import os
|
||||
import zlib
|
||||
|
||||
def evaluate_layers_rests(layers, rests, scores, pallet):
|
||||
rest_layers = list()
|
||||
|
@ -27,6 +28,8 @@ def evaluate_layers_rests(layers, rests, scores, pallet):
|
|||
|
||||
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
|
||||
|
@ -57,16 +60,16 @@ def evaluate_layers_rests(layers, rests, scores, pallet):
|
|||
score = float(subprocess.check_output("../palletandtruckviewer-3.0/palletViewer -o "
|
||||
+sys.argv[1]+" -p "+tmp
|
||||
+" -s ../icra2011TestFiles/scoreAsPlannedConfig1.xml --headless | grep Score", shell=True).split(' ')[1].strip())
|
||||
scores.append(score)
|
||||
if score > max(scores+[0]):
|
||||
shutil.move(tmp, sys.argv[2])
|
||||
else:
|
||||
os.remove(tmp)
|
||||
scores.append(score)
|
||||
|
||||
def main():
|
||||
scores = list()
|
||||
for arg in sys.argv[3:]:
|
||||
layers, rests, pallet = cPickle.loads(a2b_base64(arg))
|
||||
layers, rests, pallet = cPickle.loads(zlib.decompress(a2b_base64(arg)))
|
||||
evaluate_layers_rests(layers, rests, scores, pallet)
|
||||
|
||||
print max(scores)
|
||||
|
|
Loading…
Reference in a new issue