예제 #1
0
def main():
    if len(sys.argv) != 5:
        print "usage:", sys.argv[0], "packlist.xml x1,y1,z1 x2,y2,z2 x3,y3,z3"
        exit(1)

    x1, y1, z1 = map(int, sys.argv[2].split(','))
    x2, y2, z2 = map(int, sys.argv[3].split(','))
    x3, y3, z3 = map(int, sys.argv[4].split(','))

    d = xmlfiletodict(sys.argv[1])

    pallets = d["Response"]["PackList"]["PackPallets"]["PackPallet"]

    if not isinstance(pallets, list):
        pallets = [pallets]

    for pallet in pallets:
        for article in pallet["Packages"]["Package"]:
            x, y, z = int(article['PlacePosition']['X']), int(
                article['PlacePosition']['Y']), int(
                    article['PlacePosition']['Z'])
            article['ApproachPoint1']['X'], article['ApproachPoint1'][
                'Y'], article['ApproachPoint1']['Z'] = x + x1, y + y1, z + z1
            article['ApproachPoint2']['X'], article['ApproachPoint2'][
                'Y'], article['ApproachPoint2']['Z'] = x + x2, y + y2, z + z2
            article['ApproachPoint3']['X'], article['ApproachPoint3'][
                'Y'], article['ApproachPoint3']['Z'] = x + x3, y + y3, z + z3

    sys.stdout.write(dicttoxmlstring(packlist))
예제 #2
0
파일: barcodes.py 프로젝트: josch/sisyphus
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    orderline = xmlfiletodict(sys.argv[1])

    for article in get_articles(orderline):
        print article['Barcode']
예제 #3
0
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    orderline = xmlfiletodict(sys.argv[1])

    for article in get_articles(orderline):
        volume = article['Article']['Length']*article['Article']['Width']*article['Article']['Height']
        print 1000.0*article['Article']['Weight']/volume
예제 #4
0
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    orderline = xmlfiletodict(sys.argv[1])

    for article in get_articles(orderline):
        print '\t'.join([
            str(a) for a in [
                article['Article']['Description'], article['Article']['ID'],
                article['Article']['Type'], article['Article']['Family'],
                article['Article']['Length'], article['Article']['Width'],
                article['Article']['Height'], article['Article']['Weight']
            ]
        ])
예제 #5
0
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    orderline = xmlfiletodict(sys.argv[1])

    for article in get_articles(orderline):
        print '\t'.join([str(a) for a in [
            article['Article']['Description'],
            article['Article']['ID'],
            article['Article']['Type'],
            article['Article']['Family'],
            article['Article']['Length'],
            article['Article']['Width'],
            article['Article']['Height'],
            article['Article']['Weight']]])
예제 #6
0
파일: pallets.py 프로젝트: Ash0311/pallet
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    d = xmlfiletodict(sys.argv[1])

    pallets = d['Message']['PalletInit']['Pallets']['Pallet']

    if not isinstance(pallets, list):
        pallets = [pallets]

    for p in pallets:
        print "\t".join([
            p['Dimensions']['Length'],
            p['Dimensions']['Width'],
            p['Dimensions']['MaxLoadHeight'],
            p['Dimensions']['MaxLoadWeight']
            ])
예제 #7
0
def main():
    # Usage
    if len(sys.argv) < 4:
        print "usage:", sys.argv[0], "order.xml packlist.xml scoring.xml"
        exit(1)

    # Create a new dictionary from the order
    orderline = xmlfiletodict(sys.argv[1])
    # Get pallet sub-dictionary from order dictionary
    pallet = get_pallet(orderline)
    # Get articles sub-dictionary from the order dictionary
    articles = get_articles(orderline)
    # Create a dictionary that separates each height into a separate bin
    aStack = sortLarge(articles)

    layers = get_layers(aStack, pallet)

    for layer in layers:
        print '\n'
        for article in layer:
            print '%.2f - %d - %dx%d' % (
                density(article), article['Article']['Height'],
                article['Article']['Length'], article['Article']['Width'])

    score_max = [0]
    result_max = [None]
    evaluate_layers(layers, score_max, pallet, result_max)

    print score_max[0]

    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_f = float(f.read())
    else:
        score_max_f = 0.0
    if score_max[0] > score_max_f:
        with open(sys.argv[2], "w+") as f:
            f.write(result_max[0])
        with open("score_max", "w+") as f:
            f.write(str(score_max[0]))
    lock.close()
예제 #8
0
파일: main.py 프로젝트: ryankane/pallet
def main():
  # Usage
  if len(sys.argv) < 4:
    print "usage:", sys.argv[0], "order.xml packlist.xml scoring.xml"
    exit(1)

  # Create a new dictionary from the order
  orderline = xmlfiletodict(sys.argv[1])
  # Get pallet sub-dictionary from order dictionary
  pallet = get_pallet(orderline)
  # Get articles sub-dictionary from the order dictionary
  articles = get_articles(orderline)
  # Create a dictionary that separates each height into a separate bin
  aStack = sortLarge(articles)
  
  layers = get_layers(aStack, pallet)
  
  for layer in layers:
    print '\n'
    for article in layer:
      print '%.2f - %d - %dx%d'%(density(article), article['Article']['Height'], article['Article']['Length'], article['Article']['Width'])
      
  score_max = [0]
  result_max = [None]
  evaluate_layers(layers, score_max, pallet, result_max)

  print score_max[0]

  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_f = float(f.read())
  else:
      score_max_f = 0.0
  if score_max[0] > score_max_f:
    with open(sys.argv[2], "w+") as f:
      f.write(result_max[0])
    with open("score_max", "w+") as f:
      f.write(str(score_max[0]))
  lock.close()
예제 #9
0
def main():
    if len(sys.argv) != 5:
        print "usage:", sys.argv[0], "packlist.xml x1,y1,z1 x2,y2,z2 x3,y3,z3"
        exit(1)

    x1, y1, z1 = map(int, sys.argv[2].split(','))
    x2, y2, z2 = map(int, sys.argv[3].split(','))
    x3, y3, z3 = map(int, sys.argv[4].split(','))

    d = xmlfiletodict(sys.argv[1])

    pallets = d["Response"]["PackList"]["PackPallets"]["PackPallet"]

    if not isinstance(pallets, list):
        pallets = [pallets]

    for pallet in pallets:
        for article in pallet["Packages"]["Package"]:
            x, y, z = int(article['PlacePosition']['X']), int(article['PlacePosition']['Y']), int(article['PlacePosition']['Z'])
            article['ApproachPoint1']['X'], article['ApproachPoint1']['Y'], article['ApproachPoint1']['Z'] = x+x1, y+y1, z+z1
            article['ApproachPoint2']['X'], article['ApproachPoint2']['Y'], article['ApproachPoint2']['Z'] = x+x2, y+y2, z+z2
            article['ApproachPoint3']['X'], article['ApproachPoint3']['Y'], article['ApproachPoint3']['Z'] = x+x3, y+y3, z+z3

    sys.stdout.write(dicttoxmlstring(packlist))
예제 #10
0
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    orderline = xmlfiletodict(sys.argv[1])
    pallet = get_pallet(orderline)
    articles = get_articles(orderline)
    bins = dict()

    for article in articles:
        abin = bins.get(article['Article']['Height'])
        if abin:
            abin.append(article)
        else:
            bins[article['Article']['Height']] = [article]

    if os.environ.get("rot_article"):
        try_rot_article = bool(int(os.environ["rot_article"]))
    else:
        try_rot_article = True

    if os.environ.get("rot_pallet"):
        try_rot_pallet = bool(int(os.environ["rot_pallet"]))
    else:
        try_rot_pallet = True

    if os.environ.get("rot_article_default"):
        rot_article_default = bool(int(os.environ["rot_article_default"]))
    else:
        rot_article_default = False

    if os.environ.get("rot_pallet_default"):
        rot_pallet_default = bool(int(os.environ["rot_pallet_default"]))
    else:
        rot_pallet_default = False

    if os.environ.get("iterations"):
        max_iter = int(os.environ["iterations"])
    else:
        max_iter = -1

    if os.environ.get("randomize"):
        try_random = bool(int(os.environ["randomize"]))
    else:
        try_random = False

    if try_rot_article and try_rot_pallet:
        if try_random:
            product_it = starmap(random.randint, itertools.repeat((0, 3)))
        else:
            product_it = product_varlength(4)
    elif try_rot_article or try_rot_pallet:
        if try_random:
            product_it = starmap(random.randint, itertools.repeat((0, 1)))
        else:
            product_it = product_varlength(2)

    i = 0
    while True:
        rests = list()
        layers = list()
        try:
            if try_rot_article and try_rot_pallet:
                rot_article, rot_pallet = get_bitmask(product_it.send(True), 2)
            elif try_rot_article and not try_rot_pallet:
                rot_article = get_bitmask(product_it.send(True), 1)[0]
                rot_pallet = rot_pallet_default
            elif not try_rot_article and try_rot_pallet:
                rot_article = rot_article_default
                rot_pallet = get_bitmask(product_it.send(True), 1)[0]
            else:
                rot_article = rot_article_default
                rot_pallet = rot_pallet_default
        except TypeError:
            if try_rot_article and try_rot_pallet:
                rot_article, rot_pallet = get_bitmask(product_it.next(), 2)
            elif try_rot_article and not try_rot_pallet:
                rot_article = get_bitmask(product_it.next(), 1)[0]
                rot_pallet = rot_pallet_default
            elif not try_rot_article and try_rot_pallet:
                rot_article = rot_article_default
                rot_pallet = get_bitmask(product_it.next(), 1)[0]
            else:
                rot_article = rot_article_default
                rot_pallet = rot_pallet_default
        except StopIteration:
            break  # generator empty
        it = get_layers(bins, pallet, rot_article, rot_pallet)
        layer, rest = it.next()
        if layer:
            layers.append(layer)
        if rest:
            rests.append(rest)

        while True:
            try:
                if try_rot_article and try_rot_pallet:
                    layer, rest = it.send(
                        get_bitmask(product_it.send(False), 2))
                elif try_rot_article and not try_rot_pallet:
                    layer, rest = it.send(
                        (get_bitmask(product_it.send(False),
                                     1)[0], rot_pallet_default))
                elif not try_rot_article and try_rot_pallet:
                    layer, rest = it.send((rot_article_default,
                                           get_bitmask(product_it.send(False),
                                                       1)[0]))
                else:
                    layer, rest = it.send(
                        (rot_article_default, rot_pallet_default))
                if layer:
                    layers.append(layer)
                if rest:
                    rests.append(rest)
            except StopIteration:
                break
        print b2a_base64(zlib.compress(cPickle.dumps(
            (layers, rests, pallet)))),
        if not try_rot_article and not try_rot_pallet:
            break  # only one iteration if both are deactivated
        i += 1
        if max_iter != -1 and i >= max_iter:
            break
예제 #11
0
def main():
    if len(sys.argv) != 2:
        print "usage:", sys.argv[0], "order.xml"
        exit(1)

    orderline = xmlfiletodict(sys.argv[1])
    pallet = get_pallet(orderline)
    articles = get_articles(orderline)
    bins = dict()

    for article in articles:
        abin = bins.get(article['Article']['Height'])
        if abin:
            abin.append(article)
        else:
            bins[article['Article']['Height']] = [article]

    if os.environ.get("rot_article"):
        try_rot_article = bool(int(os.environ["rot_article"]))
    else:
        try_rot_article = True

    if os.environ.get("rot_pallet"):
        try_rot_pallet = bool(int(os.environ["rot_pallet"]))
    else:
        try_rot_pallet = True

    if os.environ.get("rot_article_default"):
        rot_article_default = bool(int(os.environ["rot_article_default"]))
    else:
        rot_article_default = False

    if os.environ.get("rot_pallet_default"):
        rot_pallet_default = bool(int(os.environ["rot_pallet_default"]))
    else:
        rot_pallet_default = False

    if os.environ.get("iterations"):
        max_iter = int(os.environ["iterations"])
    else:
        max_iter = -1

    if os.environ.get("randomize"):
        try_random = bool(int(os.environ["randomize"]))
    else:
        try_random = False

    if try_rot_article and try_rot_pallet:
        if try_random:
            product_it = starmap(random.randint, itertools.repeat((0,3)))
        else:
            product_it = product_varlength(4)
    elif try_rot_article or try_rot_pallet:
        if try_random:
            product_it = starmap(random.randint, itertools.repeat((0,1)))
        else:
            product_it = product_varlength(2)

    i = 0
    while True:
        rests = list()
        layers = list()
        try:
            if try_rot_article and try_rot_pallet:
                rot_article, rot_pallet = get_bitmask(product_it.send(True), 2)
            elif try_rot_article and not try_rot_pallet:
                rot_article = get_bitmask(product_it.send(True), 1)[0]
                rot_pallet = rot_pallet_default
            elif not try_rot_article and try_rot_pallet:
                rot_article = rot_article_default
                rot_pallet = get_bitmask(product_it.send(True), 1)[0]
            else:
                rot_article = rot_article_default
                rot_pallet = rot_pallet_default
        except TypeError:
            if try_rot_article and try_rot_pallet:
                rot_article, rot_pallet = get_bitmask(product_it.next(), 2)
            elif try_rot_article and not try_rot_pallet:
                rot_article = get_bitmask(product_it.next(), 1)[0]
                rot_pallet = rot_pallet_default
            elif not try_rot_article and try_rot_pallet:
                rot_article = rot_article_default
                rot_pallet = get_bitmask(product_it.next(), 1)[0]
            else:
                rot_article = rot_article_default
                rot_pallet = rot_pallet_default
        except StopIteration:
            break # generator empty
        it = get_layers(bins, pallet, rot_article, rot_pallet)
        layer, rest = it.next()
        if layer:
            layers.append(layer)
        if rest:
            rests.append(rest)

        while True:
            try:
                if try_rot_article and try_rot_pallet:
                    layer, rest = it.send(get_bitmask(product_it.send(False), 2))
                elif try_rot_article and not try_rot_pallet:
                    layer, rest = it.send((get_bitmask(product_it.send(False), 1)[0], rot_pallet_default))
                elif not try_rot_article and try_rot_pallet:
                    layer, rest = it.send((rot_article_default, get_bitmask(product_it.send(False), 1)[0]))
                else:
                    layer, rest = it.send((rot_article_default, rot_pallet_default))
                if layer:
                    layers.append(layer)
                if rest:
                    rests.append(rest)
            except StopIteration:
                break
        print b2a_base64(zlib.compress(cPickle.dumps((layers, rests, pallet)))),
        if not try_rot_article and not try_rot_pallet:
            break # only one iteration if both are deactivated
        i+=1
        if max_iter != -1 and i >= max_iter:
            break
예제 #12
0
#     => 18 possible configurations per layer
#     18^n layer sets (18, 324, 5832, 104976)
#
# 2. free 3d packing

import sys
import subprocess
import itertools
import shutil
from util import xmlfiletodict, dicttoxmlfile, get_pallet, get_articles, get_packlist_dict

if len(sys.argv) != 3:
    print "usage:", sys.argv[0], "order.xml packlist.xml"
    exit(0)

orderline = xmlfiletodict(sys.argv[1])

pallet = get_pallet(orderline)

articles = get_articles(orderline)

# bins of items of equal height
bins = dict()

for article in articles:
    abin = bins.get(article['Article']['Height'])
    if abin:
        abin.append(article)
    else:
        bins[article['Article']['Height']] = [article]
예제 #13
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sisyphus.  If not, see <http://www.gnu.org/licenses/>.

import ctypes, sys
from util import xmlfiletodict, get_packlist_dict, dicttoxmlfile, get_order_dict
import os

if len(sys.argv) != 2:
    print "usage:", sys.argv[0], "packlist.xml"
    exit(1)

packlist = xmlfiletodict(sys.argv[1])

pallets = packlist['Response']['PackList']['PackPallets']['PackPallet']

if not isinstance(pallets, list):
    sys.stderr.write("this is not a multi-pallet packlist\n")
    exit(1)

article_lists = [pallet['Packages']['Package'] for pallet in pallets]

scores = list()
for i, (pallet, articles_to_pack) in enumerate(zip(pallets, article_lists)):
    partial_packlist = get_packlist_dict(pallet, articles_to_pack)
    dicttoxmlfile(partial_packlist, sys.argv[1] + "_" + str(i) + ".xml")
    partial_order = get_order_dict(pallet, articles_to_pack)
    dicttoxmlfile(partial_order, sys.argv[1] + "_order_" + str(i) + ".xml")
예제 #14
0
# You should have received a copy of the GNU General Public License
# along with Sisyphus.  If not, see <http://www.gnu.org/licenses/>.

import ctypes, sys
from util import xmlfiletodict, get_packlist_dict, dicttoxmlfile, get_order_dict
import tempfile
import os

if len(sys.argv) != 3:
    print "usage:", sys.argv[0], "packlist.xml scoring.xml"
    exit(1)

libpallet = ctypes.cdll.LoadLibrary("./libpallet.so.0.0.0")
libpallet.evaluate.restype = ctypes.c_double

packlist = xmlfiletodict(sys.argv[1])

pallets = packlist["Response"]["PackList"]["PackPallets"]["PackPallet"]

article_lists = [pallet["Packages"]["Package"] for pallet in pallets]

scores = list()
for pallet, articles_to_pack in zip(pallets, article_lists):
    partial_packlist = get_packlist_dict(pallet, articles_to_pack)
    tmp_fh, tmp = tempfile.mkstemp()
    tmp_order_fh, tmp_order = tempfile.mkstemp()
    dicttoxmlfile(partial_packlist, tmp)
    dicttoxmlfile(get_order_dict(pallet, articles_to_pack), tmp_order)
    scores.append(libpallet.evaluate(tmp_order, tmp, sys.argv[2]))
    os.close(tmp_fh)
    os.close(tmp_order_fh)
예제 #15
0
# (at your option) any later version.
#
# Sisyphus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sisyphus.  If not, see <http://www.gnu.org/licenses/>.

import sys
from util import xmlfiletodict

if len(sys.argv) != 2:
    print "usage:", sys.argv[0], "packlist.xml"
    exit(1)

d = xmlfiletodict(sys.argv[1])

pallets = d["Response"]["PackList"]["PackPallets"]["PackPallet"]

if not isinstance(pallets, list):
    pallets = [pallets]

num_articles = 0

for pallet in pallets:
    num_articles += len(pallet["Packages"]["Package"])

print num_articles
예제 #16
0
#
# Copyright 2012 Johannes 'josch' Schauer <*****@*****.**>
#
# This file is part of Sisyphus.
#
# Sisyphus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Sisyphus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Sisyphus.  If not, see <http://www.gnu.org/licenses/>.

import sys
from util import xmlfiletodict, get_pallet, get_articles

if len(sys.argv) != 2:
    print "usage:", sys.argv[0], "order.xml"
    exit(1)

orderline = xmlfiletodict(sys.argv[1])
pallet = get_pallet(orderline)
articles = get_articles(orderline)

print len(articles)