Spaces:
Configuration error
Configuration error
File size: 3,664 Bytes
0864e84 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | {
"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
}
|