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
|
from arrange_spread2 import arrange_in_layer, spread_articles, find_articles
|
||||||
import cPickle
|
import cPickle
|
||||||
from binascii import b2a_base64
|
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):
|
def get_layers(bins, pallet, rot_article=False, rot_pallet=False):
|
||||||
for abin in bins:
|
for abin in bins:
|
||||||
bins[abin] = sorted(bins[abin], key=lambda article: article['Article']['Length']*article['Article']['Width'], reverse=True)
|
bins[abin] = sorted(bins[abin], key=lambda article: article['Article']['Length']*article['Article']['Width'], reverse=True)
|
||||||
plength, pwidth = (pallet['Dimensions']['Length'], pallet['Dimensions']['Width'])
|
plength, pwidth = (pallet['Dimensions']['Length'], pallet['Dimensions']['Width'])
|
||||||
root, layer, rest = arrange_in_layer(bins[abin], plength, pwidth, rot_article=rot_article)
|
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:
|
while layer:
|
||||||
spread_articles(root)
|
spread_articles(root)
|
||||||
|
if rot_pallet:
|
||||||
|
rotate(root)
|
||||||
|
|
||||||
occupied_area = 0
|
occupied_area = 0
|
||||||
for article in layer:
|
for article in layer:
|
||||||
|
@ -26,7 +45,13 @@ def get_layers(bins, pallet, rot_article=False, rot_pallet=False):
|
||||||
else:
|
else:
|
||||||
rot_article, rot_pallet = (yield layer, None)
|
rot_article, rot_pallet = (yield layer, None)
|
||||||
|
|
||||||
root, layer, rest = arrange_in_layer(rest, plength, pwidth, rot_article=rot_article)
|
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():
|
def main():
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
|
@ -49,12 +74,12 @@ def main():
|
||||||
|
|
||||||
stuff1 = list()
|
stuff1 = list()
|
||||||
|
|
||||||
#for order in itertools.product([True, False], repeat=12):
|
for order in itertools.product([0,1,2,3], repeat=8):
|
||||||
for order in [[True]*12,]:
|
#for order in [[True]*12,]:
|
||||||
rests = list()
|
rests = list()
|
||||||
layers = 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()
|
layer, rest = it.next()
|
||||||
if layer:
|
if layer:
|
||||||
layers.append(layer)
|
layers.append(layer)
|
||||||
|
@ -64,7 +89,7 @@ def main():
|
||||||
fail = True
|
fail = True
|
||||||
for rot_article in order[1:]:
|
for rot_article in order[1:]:
|
||||||
try:
|
try:
|
||||||
layer, rest = it.send((rot_article, False))
|
layer, rest = it.send((get_bit(rot_article,0), get_bit(rot_article,1)))
|
||||||
if layer:
|
if layer:
|
||||||
layers.append(layer)
|
layers.append(layer)
|
||||||
if rest:
|
if rest:
|
||||||
|
@ -74,6 +99,6 @@ def main():
|
||||||
break
|
break
|
||||||
if fail:
|
if fail:
|
||||||
raise Exception("finished early")
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -9,6 +9,7 @@ import marshal
|
||||||
from binascii import a2b_base64
|
from binascii import a2b_base64
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
|
import zlib
|
||||||
|
|
||||||
def evaluate_layers_rests(layers, rests, scores, pallet):
|
def evaluate_layers_rests(layers, rests, scores, pallet):
|
||||||
rest_layers = list()
|
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
|
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:
|
for article in layer:
|
||||||
article['PlacePosition']['X'] += diff_x
|
article['PlacePosition']['X'] += diff_x
|
||||||
article['PlacePosition']['Y'] += diff_y
|
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 "
|
score = float(subprocess.check_output("../palletandtruckviewer-3.0/palletViewer -o "
|
||||||
+sys.argv[1]+" -p "+tmp
|
+sys.argv[1]+" -p "+tmp
|
||||||
+" -s ../icra2011TestFiles/scoreAsPlannedConfig1.xml --headless | grep Score", shell=True).split(' ')[1].strip())
|
+" -s ../icra2011TestFiles/scoreAsPlannedConfig1.xml --headless | grep Score", shell=True).split(' ')[1].strip())
|
||||||
scores.append(score)
|
|
||||||
if score > max(scores+[0]):
|
if score > max(scores+[0]):
|
||||||
shutil.move(tmp, sys.argv[2])
|
shutil.move(tmp, sys.argv[2])
|
||||||
else:
|
else:
|
||||||
os.remove(tmp)
|
os.remove(tmp)
|
||||||
|
scores.append(score)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
scores = list()
|
scores = list()
|
||||||
for arg in sys.argv[3:]:
|
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)
|
evaluate_layers_rests(layers, rests, scores, pallet)
|
||||||
|
|
||||||
print max(scores)
|
print max(scores)
|
||||||
|
|
Loading…
Reference in a new issue