{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from rectpack import newPacker\n", "import rectpack.packer as packer\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def plot_solution(all_rects, pal_812, pal_1012):\n", " # Plot\n", " plt.figure(figsize=(10,10))\n", " # Loop all rect\n", " for rect in all_rects:\n", " b, x, y, w, h, rid = rect\n", " x1, x2, x3, x4, x5 = x, x+w, x+w, x, x\n", " y1, y2, y3, y4, y5 = y, y, y+h, y+h,y\n", "\n", " # Pallet type\n", " if [w, h] == pal_812:\n", " color = '--k'\n", " else:\n", " color = '--r'\n", "\n", " plt.plot([x1,x2,x3,x4,x5],[y1,y2,y3,y4,y5], color)\n", " \n", " plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Function Solver\n", "def solver(n_812, n_1012, bins):\n", " # Pallets to load\n", " rectangles = [pal_812 for i in range(n_812)] + [pal_1012 for i in range(n_1012)]\n", " \n", " # Build the Packer\n", " pack = newPacker(mode = packer.PackingMode.Offline, bin_algo = packer.PackingBin.Global,\n", " rotation=True)\n", "\n", " # Add the rectangles to packing queue\n", " for r in rectangles:\n", " pack.add_rect(*r)\n", "\n", " # Add the bins where the rectangles will be placed\n", " for b in bins:\n", " pack.add_bin(*b)\n", "\n", " # Start packing\n", " pack.pack()\n", " \n", " # Full rectangle list\n", " all_rects = pack.rect_list()\n", "\n", " # Pallets with dimensions\n", " all_pals = [sorted([p[3], p[4]]) for p in all_rects]\n", "\n", " # Count number of 80 x 120 \n", " p_812, p_1012 = all_pals.count(pal_812), all_pals.count(pal_1012)\n", " print(\"{:,}/{:,} Pallets 80 x 120 (cm) | {:,}/{:,} Pallets 100 x 120 (cm)\".format(p_812, n_812, p_1012, n_1012))\n", " \n", " return all_rects, all_pals" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Pallets Count\n", "#-- 80 x 120 cm\n", "\n", "bx = 0\n", "by = 0 \n", "pal_812 = [80 + bx, 120 + by]\n", "#-- 100 x 120 cm\n", "bx = 0\n", "by = 0\n", "pal_1012 = [100 + bx, 120 + by]\n", "\n", "# Number of pallets\n", "n_812 = 14\n", "n_1012 = 0 # 100 x 120 cm\n", "rectangles = [pal_812 for i in range(n_812)] + [pal_1012 for i in range(n_1012)]\n", "\n", "# Container size\n", "bins20 = [(236, 595)] \n", "bins40 = [(236, 1203.396)] \n", "# https://www.dsv.com/fr-fr/nos-solutions/modes-de-transport/fret-maritime/dimensions-de-conteneurs-maritimes/dry-container\n", "# https://www.icontainers.com/help/how-many-pallets-fit-in-a-container/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Test 1\n", "n_812 = 8\n", "n_1012 = 2\n", "all_rects, all_pals = solver(n_812, n_1012, bins20)\n", "plot_solution(all_rects, pal_812, pal_1012)" ] } ], "metadata": { "language_info": { "name": "python" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }