From bb9cebab81e316225a14db7ad1a2f9940c8b708f Mon Sep 17 00:00:00 2001 From: josch Date: Tue, 15 May 2012 03:24:24 +0200 Subject: [PATCH] use shared library, do not create duplicate permutations, update run.sh --- bruteforce3.py | 17 +++++++++++------ run.sh | 15 +++++++++------ util.py | 2 ++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bruteforce3.py b/bruteforce3.py index 9144d2a..06c0688 100644 --- a/bruteforce3.py +++ b/bruteforce3.py @@ -9,6 +9,10 @@ import tempfile import os import zlib import fcntl +import ctypes + +libpallet = ctypes.cdll.LoadLibrary('./libpallet.so.0.0.0') +libpallet.evaluate.restype = ctypes.c_double def evaluate_layers_rests(layers, rests, scores, pallet, result_max): rest_layers = list() @@ -56,22 +60,23 @@ def evaluate_layers_rests(layers, rests, scores, pallet, result_max): dicttoxmlfile(packlist, tmp) # ugly, ugly, ugly, ugly hack - dont copy this... - score = float(subprocess.check_output(sys.argv[3]+" -o " - +sys.argv[1]+" -p "+tmp - +" -s "+sys.argv[4]+" --headless | grep Score", shell=True).split(' ')[1].strip()) + #score = float(subprocess.check_output(sys.argv[3]+" -o " + # +sys.argv[1]+" -p "+tmp + # +" -s "+sys.argv[4]+" --headless | grep Score", shell=True).split(' ')[1].strip()) + score = libpallet.evaluate(sys.argv[1], tmp, sys.argv[3]) if score >= max(scores+[0]): result_max[0] = dicttoxmlstring(packlist) os.remove(tmp) scores.append(score) def main(): - if len(sys.argv) < 6: - print "usage:", sys.argv[0], "order.xml packlist.xml palletViewer scoring.xml LAYER [LAYER..]" + if len(sys.argv) < 5: + print "usage:", sys.argv[0], "order.xml packlist.xml scoring.xml LAYER [LAYER..]" exit(1) scores = list() result_max = [None] - for arg in sys.argv[5:]: + for arg in sys.argv[4:]: layers, rests, pallet = cPickle.loads(zlib.decompress(a2b_base64(arg))) evaluate_layers_rests(layers, rests, scores, pallet, result_max) diff --git a/run.sh b/run.sh index be2aa12..1d09aee 100755 --- a/run.sh +++ b/run.sh @@ -1,11 +1,14 @@ #!/bin/sh -ex +if [ $# -ne 3 ]; then + echo usage: $0 order.xml packlist.xml scoring.xml + exit 1 +fi + rm -f score_max -VIEWER=../palletandtruckviewer-3.0/palletViewer -SCORING=../icra2011TestFiles/scoreAsPlannedConfig1.xml +python bruteforce2.py $1 | xargs --max-procs=4 python bruteforce3.py $1 $2 $3 + +echo palletViewer -o $1 -p $2 -s $3 -python bruteforce2.py $1 \ - | sort\ - | uniq\ - | xargs --max-procs=4 python bruteforce3.py $1 packlist.xml $VIEWER $SCORING +echo python evaluate.py $1 $2 $3 diff --git a/util.py b/util.py index c0e22df..578f573 100644 --- a/util.py +++ b/util.py @@ -126,6 +126,8 @@ def product_varlength(branch_factor): for val in range(branch_factor)] current = current["children"][0] if (yield current["value"]): + current["parent"]["children"] = [] # only for the icra 2012 + current = current["parent"] # bruteforce implementation while True: if current["parent"]: current["parent"]["children"].pop(0)