예제 #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
파일: main.py 프로젝트: ryankane/pallet
def evaluate_layers(layers, score_max, pallet, result_max): 
  # Center the higest layer
  topLayer = layers.pop()
  plength, pwidth = (pallet['Dimensions']['Length'], pallet['Dimensions']['Width'])
  com_x = 0
  com_y = 0
  leftmost = pallet['Dimensions']['Length']
  rightmost = 0
  bottommost = pallet['Dimensions']['Width']
  topmost = 0
  
  for article in topLayer:
    com_x += article['PlacePosition']['X']
    com_y += article['PlacePosition']['Y']
    if article['PlacePosition']['X']-article['Article']['Length']/2 < leftmost:
      leftmost = article['PlacePosition']['X']-article['Article']['Length']/2
    if article['PlacePosition']['X']+article['Article']['Length']/2 > rightmost:
      rightmost = article['PlacePosition']['X']+article['Article']['Length']/2
    if article['PlacePosition']['Y']-article['Article']['Width']/2 < bottommost:
      bottommost = article['PlacePosition']['Y']-article['Article']['Width']/2
    if article['PlacePosition']['Y']+article['Article']['Width']/2 > topmost:
      topmost = article['PlacePosition']['Y']+article['Article']['Width']/2
  com_x, com_y = com_x/len(topLayer), com_y/len(topLayer)

  llength = rightmost - leftmost
  lwidth = topmost - bottommost

  if com_x < llength-plength/2:
    com_x = llength-plength/2
  elif com_x > plength/2:
    com_x = plength/2
  if com_y < lwidth-pwidth/2:
    com_y = lwidth-pwidth/2
  elif com_y > pwidth/2:
    com_y = pwidth/2

  diff_x, diff_y = plength*0.5-com_x, pwidth*0.5-com_y

  for article in topLayer:
    article['PlacePosition']['X'] += diff_x
    article['PlacePosition']['Y'] += diff_y

  layers.append(topLayer) # Add modified layer back to layers
  
  max_count = 50
  cur_count = 0
  permutations = itertools.permutations(layers)
  for permut_layers in permutations:
    permut_layers = list(permut_layers)
    random.shuffle(permut_layers)
    packlist = pack_single_pallet(permut_layers, pallet)
    score = evaluate_single_pallet(packlist)
    if score >= score_max[0]:
      result_max[0] = dicttoxmlstring(packlist)
      score_max[0] = score
      print score
    cur_count += 1
    if max_count < 1 or cur_count > max_count: break
예제 #3
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))
예제 #4
0
def evaluate_layers_rests(layers, rests, score_max, pallet, result_max):
    rest_layers = list()
    # sort rests by space they cover and move them to the center of the pile
    # append them to the layer list
    for rest in sorted(rests, key=lambda rest: sum([article['Article']['Length']*article['Article']['Width'] for article in rest]), reverse=True):
        plength, pwidth = (pallet['Dimensions']['Length'], pallet['Dimensions']['Width'])
        root, layer, rest = arrange_in_layer(rest, plength, pwidth)

        com_x = 0
        com_y = 0
        leftmost = pallet['Dimensions']['Length']
        rightmost = 0
        bottommost = pallet['Dimensions']['Width']
        topmost = 0
        for article in layer:
            com_x += article['PlacePosition']['X']
            com_y += article['PlacePosition']['Y']
            if article['PlacePosition']['X']-article['Article']['Length']/2 < leftmost:
                leftmost = article['PlacePosition']['X']-article['Article']['Length']/2
            if article['PlacePosition']['X']+article['Article']['Length']/2 > rightmost:
                rightmost = article['PlacePosition']['X']+article['Article']['Length']/2
            if article['PlacePosition']['Y']-article['Article']['Width']/2 < bottommost:
                bottommost = article['PlacePosition']['Y']-article['Article']['Width']/2
            if article['PlacePosition']['Y']+article['Article']['Width']/2 > topmost:
                topmost = article['PlacePosition']['Y']+article['Article']['Width']/2
        com_x, com_y = com_x/len(layer), com_y/len(layer)

        llength = rightmost - leftmost
        lwidth = topmost - bottommost

        if com_x < llength-plength/2:
            com_x = llength-plength/2
        elif com_x > plength/2:
            com_x = plength/2
        if com_y < lwidth-pwidth/2:
            com_y = lwidth-pwidth/2
        elif com_y > pwidth/2:
            com_y = pwidth/2

        diff_x, diff_y = plength*0.5-com_x, pwidth*0.5-com_y

        for article in layer:
            article['PlacePosition']['X'] += diff_x
            article['PlacePosition']['Y'] += diff_y

        rest_layers.append(layer)

    if try_permutations:
        permutations = itertools.permutations(layers)
    else:
        #permutations = [tuple(sorted(layers, key=lambda layer: sum([article['Article']['Weight'] for article in layer]), reverse=True))]
        #permutations = [tuple(sorted(layers, key=lambda layer: sum([article['Article']['Length']*article['Article']['Width'] for article in layer]), reverse=True))]
        #permutations = (layers for i in xrange(1000))
        permutations = [layers]

    i = 0
    for permut_layers in permutations:
        permut_layers = list(permut_layers)
        if try_random:
            random.shuffle(permut_layers)
        if try_multi_pallet:
            packlist = pack_multi_pallet(permut_layers, rest_layers, pallet)
            score = evaluate_multi_pallet(packlist)
        else:
            packlist = pack_single_pallet(permut_layers, rest_layers, pallet)
            score = evaluate_single_pallet(packlist)

        if score >= score_max[0]:
            result_max[0] = dicttoxmlstring(packlist)
            score_max[0] = score

        i+=1
        if max_iter != -1 and i >= max_iter:
            break
예제 #5
0
def evaluate_layers(layers, score_max, pallet, result_max):
    # Center the higest layer
    topLayer = layers.pop()
    plength, pwidth = (pallet['Dimensions']['Length'],
                       pallet['Dimensions']['Width'])
    com_x = 0
    com_y = 0
    leftmost = pallet['Dimensions']['Length']
    rightmost = 0
    bottommost = pallet['Dimensions']['Width']
    topmost = 0

    for article in topLayer:
        com_x += article['PlacePosition']['X']
        com_y += article['PlacePosition']['Y']
        if article['PlacePosition'][
                'X'] - article['Article']['Length'] / 2 < leftmost:
            leftmost = article['PlacePosition'][
                'X'] - article['Article']['Length'] / 2
        if article['PlacePosition'][
                'X'] + article['Article']['Length'] / 2 > rightmost:
            rightmost = article['PlacePosition'][
                'X'] + article['Article']['Length'] / 2
        if article['PlacePosition'][
                'Y'] - article['Article']['Width'] / 2 < bottommost:
            bottommost = article['PlacePosition'][
                'Y'] - article['Article']['Width'] / 2
        if article['PlacePosition'][
                'Y'] + article['Article']['Width'] / 2 > topmost:
            topmost = article['PlacePosition'][
                'Y'] + article['Article']['Width'] / 2
    com_x, com_y = com_x / len(topLayer), com_y / len(topLayer)

    llength = rightmost - leftmost
    lwidth = topmost - bottommost

    if com_x < llength - plength / 2:
        com_x = llength - plength / 2
    elif com_x > plength / 2:
        com_x = plength / 2
    if com_y < lwidth - pwidth / 2:
        com_y = lwidth - pwidth / 2
    elif com_y > pwidth / 2:
        com_y = pwidth / 2

    diff_x, diff_y = plength * 0.5 - com_x, pwidth * 0.5 - com_y

    for article in topLayer:
        article['PlacePosition']['X'] += diff_x
        article['PlacePosition']['Y'] += diff_y

    layers.append(topLayer)  # Add modified layer back to layers

    max_count = 50
    cur_count = 0
    permutations = itertools.permutations(layers)
    for permut_layers in permutations:
        permut_layers = list(permut_layers)
        random.shuffle(permut_layers)
        packlist = pack_single_pallet(permut_layers, pallet)
        score = evaluate_single_pallet(packlist)
        if score >= score_max[0]:
            result_max[0] = dicttoxmlstring(packlist)
            score_max[0] = score
            print score
        cur_count += 1
        if max_count < 1 or cur_count > max_count: break