'usability'... haha
This commit is contained in:
parent
dfa216e642
commit
addccfef86
3 changed files with 59 additions and 43 deletions
|
@ -1,9 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
|
||||||
import itertools
|
import itertools
|
||||||
import shutil
|
from util import xmlfiletodict, get_pallet, get_articles
|
||||||
from util import xmlfiletodict, dicttoxmlfile, get_pallet, get_articles, get_packlist_dict
|
from arrange_spread2 import arrange_in_layer, spread_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
|
import zlib
|
||||||
|
@ -54,8 +52,8 @@ def get_bit(num, pos):
|
||||||
return num>>pos&1
|
return num>>pos&1
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 2:
|
||||||
print "usage:", sys.argv[0], "order.xml packlist.xml"
|
print "usage:", sys.argv[0], "order.xml"
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
orderline = xmlfiletodict(sys.argv[1])
|
orderline = xmlfiletodict(sys.argv[1])
|
||||||
|
@ -74,14 +72,20 @@ def main():
|
||||||
|
|
||||||
stuff1 = list()
|
stuff1 = list()
|
||||||
|
|
||||||
#for order in itertools.product([True, False], repeat=10):
|
rot_pallet_only = False
|
||||||
#for order in [[True]*12,]:
|
if rot_pallet_only:
|
||||||
for order in itertools.product([0,1,2,3], repeat=8):
|
combos = [True, False]
|
||||||
|
else:
|
||||||
|
combos = [0,1,2,3]
|
||||||
|
|
||||||
|
for order in itertools.product(combos, repeat=5):
|
||||||
rests = list()
|
rests = list()
|
||||||
layers = list()
|
layers = list()
|
||||||
|
|
||||||
it = get_layers(bins, pallet, get_bit(order[0], 0), get_bit(order[0], 1))
|
if rot_pallet_only:
|
||||||
#it = get_layers(bins, pallet, order[0], False)
|
it = get_layers(bins, pallet, False, order[0])
|
||||||
|
else:
|
||||||
|
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)
|
||||||
|
@ -91,8 +95,10 @@ def main():
|
||||||
fail = True
|
fail = True
|
||||||
for rot_article in order[1:]:
|
for rot_article in order[1:]:
|
||||||
try:
|
try:
|
||||||
layer, rest = it.send((get_bit(rot_article,0), get_bit(rot_article,1)))
|
if rot_pallet_only:
|
||||||
#layer, rest = it.send((rot_article, False))
|
layer, rest = it.send((False, rot_article))
|
||||||
|
else:
|
||||||
|
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:
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import itertools
|
import itertools
|
||||||
import shutil
|
from util import dicttoxmlfile, get_packlist_dict, dicttoxmlstring
|
||||||
from util import xmlfiletodict, dicttoxmlfile, get_pallet, get_articles, get_packlist_dict
|
from arrange_spread2 import arrange_in_layer
|
||||||
from arrange_spread2 import arrange_in_layer, spread_articles, find_articles
|
|
||||||
import cPickle
|
import cPickle
|
||||||
import marshal
|
|
||||||
from binascii import a2b_base64
|
from binascii import a2b_base64
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
import zlib
|
import zlib
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
def evaluate_layers_rests(layers, rests, scores, pallet):
|
def evaluate_layers_rests(layers, rests, scores, pallet, result_max):
|
||||||
rest_layers = list()
|
rest_layers = list()
|
||||||
# sort rests by space they cover and move them to the center of the pile
|
# sort rests by space they cover and move them to the center of the pile
|
||||||
# append them to the layer list
|
# append them to the layer list
|
||||||
|
@ -58,37 +56,24 @@ def evaluate_layers_rests(layers, rests, scores, pallet):
|
||||||
dicttoxmlfile(packlist, tmp)
|
dicttoxmlfile(packlist, tmp)
|
||||||
|
|
||||||
# ugly, ugly, ugly, ugly hack - dont copy this...
|
# ugly, ugly, ugly, ugly hack - dont copy this...
|
||||||
score = float(subprocess.check_output("../palletandtruckviewer-3.0/palletViewer -o "
|
score = float(subprocess.check_output(sys.argv[3]+" -o "
|
||||||
+sys.argv[1]+" -p "+tmp
|
+sys.argv[1]+" -p "+tmp
|
||||||
+" -s ../icra2011TestFiles/scoreAsPlannedConfig1.xml --headless | grep Score", shell=True).split(' ')[1].strip())
|
+" -s "+sys.argv[4]+" --headless | grep Score", shell=True).split(' ')[1].strip())
|
||||||
if score > max(scores+[0]):
|
if score >= max(scores+[0]):
|
||||||
shutil.move(tmp, sys.argv[2])
|
result_max[0] = dicttoxmlstring(packlist)
|
||||||
else:
|
os.remove(tmp)
|
||||||
os.remove(tmp)
|
|
||||||
scores.append(score)
|
scores.append(score)
|
||||||
|
|
||||||
"""
|
|
||||||
lock = open("score_max.lock", "w")
|
|
||||||
fcntl.lockf(lock, fcntl.LOCK_EX)
|
|
||||||
score_max_f = open("score_max", "w+")
|
|
||||||
score_max = score_max_f.read()
|
|
||||||
if not score_max:
|
|
||||||
score_max = 0.0
|
|
||||||
if score > score_max:
|
|
||||||
shutil.move(tmp, sys.argv[2])
|
|
||||||
score_max_f.write(str(score))
|
|
||||||
else:
|
|
||||||
os.remove(tmp)
|
|
||||||
score_max_f.close()
|
|
||||||
lock.close()
|
|
||||||
scores.append(score)
|
|
||||||
"""
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
if len(sys.argv) < 6:
|
||||||
|
print "usage:", sys.argv[0], "order.xml packlist.xml palletViewer scoring.xml LAYER [LAYER..]"
|
||||||
|
exit(1)
|
||||||
|
|
||||||
scores = list()
|
scores = list()
|
||||||
for arg in sys.argv[3:]:
|
result_max = [None]
|
||||||
|
for arg in sys.argv[5:]:
|
||||||
layers, rests, pallet = cPickle.loads(zlib.decompress(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, result_max)
|
||||||
|
|
||||||
print max(scores)
|
print max(scores)
|
||||||
#print "max:", max(scores)
|
#print "max:", max(scores)
|
||||||
|
@ -98,5 +83,19 @@ def main():
|
||||||
#from math import sqrt
|
#from math import sqrt
|
||||||
#print "stddev:", sqrt(sum([(x-mean)**2 for x in scores])/len(scores))
|
#print "stddev:", sqrt(sum([(x-mean)**2 for x in scores])/len(scores))
|
||||||
|
|
||||||
|
lock = open("score_max.lock", "w")
|
||||||
|
fcntl.lockf(lock, fcntl.LOCK_EX)
|
||||||
|
if os.path.isfile("score_max"):
|
||||||
|
with open("score_max", "r") as f:
|
||||||
|
score_max = float(f.read())
|
||||||
|
else:
|
||||||
|
score_max = 0.0
|
||||||
|
if max(scores) > score_max:
|
||||||
|
with open(sys.argv[2], "w+") as f:
|
||||||
|
f.write(result_max[0])
|
||||||
|
with open("score_max", "w+") as f:
|
||||||
|
f.write(str(max(scores)))
|
||||||
|
lock.close()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
11
run.sh
Executable file
11
run.sh
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh -ex
|
||||||
|
|
||||||
|
rm -f score_max
|
||||||
|
|
||||||
|
VIEWER=../palletandtruckviewer-3.0/palletViewer
|
||||||
|
SCORING=../icra2011TestFiles/scoreAsPlannedConfig1.xml
|
||||||
|
|
||||||
|
python bruteforce2.py $1 \
|
||||||
|
| sort\
|
||||||
|
| uniq\
|
||||||
|
| xargs --max-procs=4 python bruteforce3.py $1 packlist.xml $VIEWER $SCORING
|
Loading…
Reference in a new issue