def generate_data(self): self.packer = Packer() bin_W =60#random.uniform(self.bin_W_range[0],self.bin_W_range[1]) bin_H =40#random.uniform(self.bin_H_range[0],self.bin_H_range[1]) bin_L =40#random.uniform(self.bin_L_range[0],self.bin_L_range[1]) bin_volume=bin_W*bin_H*bin_L self.packer.add_bin(Bin('FirstBin', bin_W, bin_H, bin_L , 1)) current_volume=0 index=0 while (current_volume<bin_volume): index+=1 item_W =random.randint(10,20)#random.uniform(self.item_W_range[0],self.item_W_range[1]) item_H =random.randint(10,20)#random.uniform(self.item_H_range[0],self.item_H_range[1]) item_L =random.randint(10,20)#random.uniform(self.item_L_range[0],self.item_L_range[1]) current_volume+=item_W*item_H*item_L self.packer.add_item(Item('Item '+str(index), item_W, item_H, item_L, 0)) self.packer.pack() item_list=[] for b in self.packer.bins: #draw bin origin bin_origin=o3d.geometry.TriangleMesh.create_coordinate_frame(size=10.0, origin= [0., 0., 0.] ) item_list.append(bin_origin) print(":::::::::::", b.string()) mesh_bin = self.create_mesh_box(width = b.width, height = b.height, depth = b.depth)#, dx=b.position[0], dy=b.position[1], dz=b.position[2])#position mesh_bin.compute_vertex_normals() mesh_bin.paint_uniform_color([random.uniform(0,1), random.uniform(0,1), random.uniform(0,1)]) lineset_bin=o3d.geometry.LineSet.create_from_triangle_mesh(mesh_bin) item_list.append(lineset_bin) print("FITTED ITEMS:") for item in b.items: print("====> ", item.string()) dim=item.get_dimension() mesh_box = self.create_mesh_box(width = dim[0], height = dim[1], depth = dim[2], dx=item.position[0], dy=item.position[1], dz=item.position[2])#position mesh_box.compute_vertex_normals() mesh_box.paint_uniform_color([random.uniform(0,1), random.uniform(0,1), random.uniform(0,1)]) item_list.append(mesh_box) print("UNFITTED ITEMS:") for item in b.unfitted_items: print("====> ", item.string()) print("***************************************************") print("***************************************************") o3d.visualization.draw_geometries(item_list)
def loading(Container_vehicle, final_set, n_customer, N, V, Cat, IT, IT_num, nv, locationtuples, RP, A, nmaps, dist, historical_routes, historical_routes_tuples): packer = Packer() # The maximum volum and weight that a container can carry (length, width, height, weight) # Add bins packer.add_bin( Bin(Container_vehicle[0], Container_vehicle[1], Container_vehicle[2], Container_vehicle[3], Container_vehicle[4])) # add items to corresponding containers for customeritems in final_set: for items in customeritems: packer.add_item( Item( list(items.keys())[0], list(items.values())[0][0], list(items.values())[0][1], list(items.values())[0][2], list(items.values())[0][3])) packer.pack(number_of_decimals=0) return packer
def fit_company(self, company, input_items): ''' Empacota os itens nos veículos de uma empresa e retorna uma lista de bins em que os itens couberam ''' # Empacotador packer = Packer() # Seleciona os bins de uma empresa bins = self.available_bins[company] # Adiciona os bins ao empacotador for bin_ in bins: packer.add_bin(bin_) # Adiciona os itens ao empacotador for input_item in input_items: item = get_item(input_item) packer.add_item(item) # Empacota packer.pack() # Lista com os bins que couberam fitted_bins = [] for bin_ in packer.bins: if len(bin_.unfitted_items) > 0: continue else: fitted_bins.append(bin_) return fitted_bins
from py3dbp import Item, Bin, Packer print('start') from copy import deepcopy packer = Packer() packer.add_bin(Bin('small-envelope 1', 85, 85, 85, 124)) for j in range(11): a = Item('Beauty & Personal Care {}'.format(j), 19, 19, 19, 12) packer.add_item(a) for j in range(14): a = Item('Tools & Home Improvement {}'.format(j), 6, 6, 6, 4) packer.add_item(a) for j in range(8): a = Item('Audible Books & Originals {}'.format(j), 15, 15, 15, 8) packer.add_item(a) import time now = time.time() packer_1 = deepcopy(packer) packer_2 = deepcopy(packer) packer = packer_1 packer.algorithm_1() print('start') for b in packer.bins: print(b.string()) for i in b.items:
from py3dbp import Packer, Bin, Item packer = Packer() packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10)) packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 15)) packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) packer.add_bin(Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0)) packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0)) packer.add_bin(Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0)) packer.add_item(Item('50g [powder 1]', 3.9370, 1.9685, 1.9685, 1)) packer.add_item(Item('50g [powder 2]', 3.9370, 1.9685, 1.9685, 2)) packer.add_item(Item('50g [powder 3]', 3.9370, 1.9685, 1.9685, 3)) packer.add_item(Item('250g [powder 4]', 7.8740, 3.9370, 1.9685, 4)) packer.add_item(Item('250g [powder 5]', 7.8740, 3.9370, 1.9685, 5)) packer.add_item(Item('250g [powder 6]', 7.8740, 3.9370, 1.9685, 6)) packer.add_item(Item('250g [powder 7]', 7.8740, 3.9370, 1.9685, 7)) packer.add_item(Item('250g [powder 8]', 7.8740, 3.9370, 1.9685, 8)) packer.add_item(Item('250g [powder 9]', 7.8740, 3.9370, 1.9685, 9)) packer.pack() for b in packer.bins: print(":::::::::::", b.string()) print("FITTED ITEMS:") for item in b.items: print("====> ", item.string())
from py3dbp import Packer, Bin, Item packer = Packer() packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 0.8125)) packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 0.8125)) packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) packer.add_bin(Bin('medium-box', 13.625, 11.875, 3.375, 70.0)) packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0)) packer.add_bin(Bin('large-box', 23.6875, 11.75, 3.0, 70.0)) packer.add_item(Item('50g [powder]', 3.9370, 1.9685, 1.9685, 50)) packer.add_item(Item('50g [powder]', 3.9370, 1.9685, 1.9685, 50)) packer.add_item(Item('50g [powder]', 3.9370, 1.9685, 1.9685, 50)) packer.add_item(Item('250g [powder]', 7.8740, 3.9370, 1.9685, 250)) packer.add_item(Item('250g [powder]', 7.8740, 3.9370, 1.9685, 250)) packer.add_item(Item('250g [powder]', 7.8740, 3.9370, 1.9685, 250)) packer.add_item(Item('250g [powder]', 7.8740, 3.9370, 1.9685, 250)) packer.add_item(Item('250g [powder]', 7.8740, 3.9370, 1.9685, 250)) packer.add_item(Item('250g [powder]', 7.8740, 3.9370, 1.9685, 250)) packer.algorithm_1() for b in packer.bins: print(b.string()) for i in b.items: print("====> ", i.string()) if packer.unfit_items: print('Unfit items') for b in packer.unfit_items:
from py3dbp import Packer, Bin, Item from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection import numpy as np import matplotlib.pyplot as plt import random trucks = [[250, 250, 500], [500, 500, 400], [300, 300, 300], [300, 300, 200], [300, 300, 100], [500, 500, 500]] for t in range(len(trucks)): packer = Packer() #packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10)) #packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 15)) #packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) #packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) #packer.add_bin(Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0)) #packer.add_bin(Bin('large-box', 240, 244, 1360, 70.0)) #packer.add_bin(Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0)) truckX = trucks[t][0] truckY = trucks[t][1] truckZ = trucks[t][2] packer.add_bin(Bin('LB', truckX, truckY, truckZ, 3000.0)) for i in range(300): packer.add_item(Item('boxL' + str(i), 20, 40, 20, 1)) for i in range(10):
def generate_data_test(sefl): packer = Packer() packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10)) packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 15)) packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) packer.add_bin(Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0)) packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0)) packer.add_bin(Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0)) packer.add_item(Item('50g [powder 1]', 3.9370, 1.9685, 1.9685, 1)) packer.add_item(Item('50g [powder 2]', 3.9370, 1.9685, 1.9685, 2)) packer.add_item(Item('50g [powder 3]', 3.9370, 1.9685, 1.9685, 3)) packer.add_item(Item('250g [powder 4]', 7.8740, 3.9370, 1.9685, 4)) packer.add_item(Item('250g [powder 5]', 7.8740, 3.9370, 1.9685, 5)) packer.add_item(Item('250g [powder 6]', 7.8740, 3.9370, 1.9685, 6)) packer.add_item(Item('250g [powder 7]', 7.8740, 3.9370, 1.9685, 7)) packer.add_item(Item('250g [powder 8]', 7.8740, 3.9370, 1.9685, 8)) packer.add_item(Item('250g [powder 9]', 7.8740, 3.9370, 1.9685, 9)) packer.pack() for b in packer.bins: print(":::::::::::", b.string()) print("FITTED ITEMS:") for item in b.items: print("====> ", item.string()) print("UNFITTED ITEMS:") for item in b.unfitted_items: print("====> ", item.string()) print("***************************************************") print("***************************************************")
class Online3DPackingDataGenerator: def __init__(self): self.bin_W_range = [300,500] self.bin_H_range = [500,700] self.bin_L_range = [300,500] self.item_W_range = [self.bin_W_range[0]*0.05,self.bin_W_range[1]*0.3] self.item_H_range = [self.bin_H_range[0]*0.05,self.bin_H_range[1]*0.3] self.item_L_range = [self.bin_L_range[0]*0.05,self.bin_L_range[1]*0.3] self.packer=None def generate_data(self): self.packer = Packer() bin_W =60#random.uniform(self.bin_W_range[0],self.bin_W_range[1]) bin_H =40#random.uniform(self.bin_H_range[0],self.bin_H_range[1]) bin_L =40#random.uniform(self.bin_L_range[0],self.bin_L_range[1]) bin_volume=bin_W*bin_H*bin_L self.packer.add_bin(Bin('FirstBin', bin_W, bin_H, bin_L , 1)) current_volume=0 index=0 while (current_volume<bin_volume): index+=1 item_W =random.randint(10,20)#random.uniform(self.item_W_range[0],self.item_W_range[1]) item_H =random.randint(10,20)#random.uniform(self.item_H_range[0],self.item_H_range[1]) item_L =random.randint(10,20)#random.uniform(self.item_L_range[0],self.item_L_range[1]) current_volume+=item_W*item_H*item_L self.packer.add_item(Item('Item '+str(index), item_W, item_H, item_L, 0)) self.packer.pack() item_list=[] for b in self.packer.bins: #draw bin origin bin_origin=o3d.geometry.TriangleMesh.create_coordinate_frame(size=10.0, origin= [0., 0., 0.] ) item_list.append(bin_origin) print(":::::::::::", b.string()) mesh_bin = self.create_mesh_box(width = b.width, height = b.height, depth = b.depth)#, dx=b.position[0], dy=b.position[1], dz=b.position[2])#position mesh_bin.compute_vertex_normals() mesh_bin.paint_uniform_color([random.uniform(0,1), random.uniform(0,1), random.uniform(0,1)]) lineset_bin=o3d.geometry.LineSet.create_from_triangle_mesh(mesh_bin) item_list.append(lineset_bin) print("FITTED ITEMS:") for item in b.items: print("====> ", item.string()) dim=item.get_dimension() mesh_box = self.create_mesh_box(width = dim[0], height = dim[1], depth = dim[2], dx=item.position[0], dy=item.position[1], dz=item.position[2])#position mesh_box.compute_vertex_normals() mesh_box.paint_uniform_color([random.uniform(0,1), random.uniform(0,1), random.uniform(0,1)]) item_list.append(mesh_box) print("UNFITTED ITEMS:") for item in b.unfitted_items: print("====> ", item.string()) print("***************************************************") print("***************************************************") o3d.visualization.draw_geometries(item_list) def create_mesh_box(self,width, height, depth, dx=0, dy=0, dz=0): box = o3d.geometry.TriangleMesh() vertices = np.array([[0,0,0], [width,0,0], [0,0,depth], [width,0,depth], [0,height,0], [width,height,0], [0,height,depth], [width,height,depth]]) vertices[:,0] += dx vertices[:,1] += dy vertices[:,2] += dz triangles = np.array([[4,7,5],[4,6,7],[0,2,4],[2,6,4], [0,1,2],[1,3,2],[1,5,7],[1,7,3], [2,3,7],[2,7,6],[0,4,1],[1,4,5]]) box.vertices = o3d.utility.Vector3dVector(vertices) box.triangles = o3d.utility.Vector3iVector(triangles) return box def generate_data_test(sefl): packer = Packer() packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10)) packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 15)) packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) packer.add_bin(Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0)) packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0)) packer.add_bin(Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0)) packer.add_item(Item('50g [powder 1]', 3.9370, 1.9685, 1.9685, 1)) packer.add_item(Item('50g [powder 2]', 3.9370, 1.9685, 1.9685, 2)) packer.add_item(Item('50g [powder 3]', 3.9370, 1.9685, 1.9685, 3)) packer.add_item(Item('250g [powder 4]', 7.8740, 3.9370, 1.9685, 4)) packer.add_item(Item('250g [powder 5]', 7.8740, 3.9370, 1.9685, 5)) packer.add_item(Item('250g [powder 6]', 7.8740, 3.9370, 1.9685, 6)) packer.add_item(Item('250g [powder 7]', 7.8740, 3.9370, 1.9685, 7)) packer.add_item(Item('250g [powder 8]', 7.8740, 3.9370, 1.9685, 8)) packer.add_item(Item('250g [powder 9]', 7.8740, 3.9370, 1.9685, 9)) packer.pack() for b in packer.bins: print(":::::::::::", b.string()) print("FITTED ITEMS:") for item in b.items: print("====> ", item.string()) print("UNFITTED ITEMS:") for item in b.unfitted_items: print("====> ", item.string()) print("***************************************************") print("***************************************************")
def random_item(): name_len = random.randrange(3, 6) item_name = get_random_string(4) w = round(random.uniform(1000.0, 2000.0), 2) h = round(random.uniform(1000.0, 2000.0), 2) d = round(random.uniform(1000.0, 2000.0), 2) mw = round(random.uniform(500.0, 1000.0), 2) new_item = Item(item_name, w, h, d, mw) print(new_item.string()) return new_item packer = Packer() total_bin = random.randrange(1, 3) for i in range(total_bin): packer.add_bin(random_bin()) print() total_item = random.randrange(20, 60) for i in range(total_item): packer.add_item(random_item()) # packer.add_bin(Bin("The Container", 150, 150, 150, 10000)) # for i in range(27): # print(i) # packer.add_item(Item("Item"+str(i), 50, 50, 50, 1)) ''' Test 1 From example ''' # packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10))
def __init__(self): super().__init__() self.packer = Packer()
class SimpleSolver(AbstractSolver): def __init__(self): super().__init__() self.packer = Packer() @staticmethod def convert_rotation(rotation_type): rotation = (0, 0, 0) if rotation_type == 1: rotation = (90, 0, 0) elif rotation_type == 2: rotation = (0, 90, 0) elif rotation_type == 3: rotation = (0, 90, 90) elif rotation_type == 4: rotation = (0, 0, 90) elif rotation_type == 5: rotation = (90, 0, 90) return rotation def solve(self, bins, items): for bin in bins: self.packer.add_bin( Bin(bin.name, bin.width, bin.height, bin.depth, bin.max_weight)) for item in items: self.packer.add_item( Item(item.name, item.width, item.height, item.depth, item.weight)) self.packer.pack(distribute_items=True) return self.parse_solution() def parse_solution(self): solution = {} bins = [] for bin in self.packer.bins: items = [] for item in bin.items: rotation_coords = self.convert_rotation(item.rotation_type) items.append({ "name": item.name, "width": item.width, "height": item.height, "depth": item.depth, "x": item.position[2], # Because Z and X axes swapped for Unity "y": item.position[1], "z": item.position[0], "rotation_x": rotation_coords[0], "rotation_y": rotation_coords[1], "rotation_z": rotation_coords[2] }) bins.append({"name": bin.name, "items": items}) solution['bins'] = bins return solution
from py3dbp import Packer, Bin, Item packer = Packer() a = Bin('large-3-box', 23.6875, 11.2, 35.0, 1000.0) #packer.add_bin(Bin('small-envelope', 11.5, 6.125, 0.25, 10)) #packer.add_bin(Bin('large-envelope', 15.0, 12.0, 0.75, 15)) #packer.add_bin(Bin('small-box', 8.625, 5.375, 1.625, 70.0)) #packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0)) #packer.add_bin(Bin('medium-2-box', 13.625, 11.875, 3.375, 70.0)) #packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0)) #packer.add_bin(Bin('large-2-box', 23.6875, 11.75, 3.0, 70.0)) packer.add_bin(a) packer.add_item(Item('1', 3.9370, 1.9685, 11.9685, 1)) packer.pack() #packer.add_item(Item('2', 23.6875, 11.2, 30, 10)) #packer.pack() packer.add_item(Item('2', 3.9370, 1.9685, 1.9685, 2)) packer.pack() packer.add_item(Item('3', 3.9370, 1.9685, 1.9685, 3)) packer.pack() packer.add_item(Item('4', 7.8740, 3.9370, 1.9685, 4)) packer.pack() packer.add_item(Item('5', 7.8740, 3.9370, 1.9685, 5)) packer.pack() packer.add_item(Item('6', 7.8740, 3.9370, 1.9685, 6)) packer.pack() packer.add_item(Item('7', 15.5, 6, 20, 6)) packer.pack()