from vtk import *
import vtk
import functools
import random
import math
# 数据生成,输入为箱子种类数,箱子最大长、最小长、最大宽、最小宽、商品个数、商品最大长、最小长、最大宽、最小宽
# 输出为生成的箱子列表和商品列表
def boxs_generate_3d(nums_box=20, max_l_box=80, min_l_box=21, max_w_box=60, min_w_box=14, max_h_box=60, min_h_box=9):
# 随机生成箱子
boxs = []
for i in range(nums_box):
boxs.append([int((max_l_box-min_l_box) * random.random() + min_l_box),
int((max_w_box-min_w_box) * random.random() + min_w_box),
int((max_h_box-min_h_box) * random.random() + min_h_box)])
# boxs = []
# for i in range(nums_box):
# boxs.append([int((max_l_box-min_l_box) * random.random() + min_l_box),
# int((max_w_box-min_w_box) * random.random() + min_w_box),
# int((max_h_box-min_h_box) * random.random() + min_h_box)])
return boxs
# 二维商品排序用
def cmp_2d(x,y):
if x[0] < y[0]:
return -1
elif x[0] > y[0]:
return 1
elif x[1] < y[1]:
return -1
elif x[1] > y[1]:
return 1
else:
return 0
# 三维商品排序用
def cmp_3d(x, y):
if x[0] < y[0]:
return -1
elif x[0] > y[0]:
return 1
elif x[1] < y[1]:
return -1
elif x[1] > y[1]:
return 1
elif x[2] < y[2]:
return -1
elif x[2] > y[2]:
return 1
else:
return 0
# 检验是否每个商品都能有一个箱子放下它
def check_3d(boxs, goods):
for good in goods:
can_put = False
for box in boxs:
if good[0] <= box[0] and good[1] <= box[1] and good[2] <= box[2]:
can_put = True
break
if not can_put:
print(good,"太大,无合适箱子")
return False
return True
def can_put_3d(l, w, h, goods):
L = max(l, w, h)
H = min(l, w, h)
W = l + w + h - L - H
for good in goods:
# lg, wg, hg = good[0], good[1], good[2]
lg = max(good[0], good[1], good[2])
hg = min(good[0], good[1], good[2])
wg = good[0] + good[1] + good[2] - lg - hg
if lg > L or wg > W or hg > H:
return False
return True
# 先以w为限制码垛,再以l为限制码垛
# 输入为长、宽、商品集,输出为箱子个数
def packing_simple(l, w, h, goods):
# 先检查是否每一个商品在此规则下都能放下
if not can_put_3d(l, w, h, goods):
return -1
#以h为限制码垛成条,商品排序,大的放前面
goods1 = []
for good in goods:
if good[0] <= l and good[1] <= w and good[2] <= h:
goods1.append([good[0], good[1], good[2]])
elif good[0] <= l and good[2] <= w and good[1] <= h:
goods1.append([good[0], good[2], good[1]])
elif good[1] <= l and good[0] <= w and good[2] <= h:
goods1.append([good[1], good[0], good[2]])
elif good[1] <= l and good[2] <= w and good[0] <= h:
goods1.append([good[1], good[2], good[0]])
elif good[2] <= l and good[0] <= w and good[1] <= h:
goods1.append([good[2], good[0], good[1]])
else:
goods1.append([good[2], good[1], good[0]])
goods1 = sorted(goods1, key=functools.cmp_to_key(cmp_3d), reverse=True)
strips = []
goods1_used = [0 for i in range(len(goods1))]
while sum(goods1_used) < len(goods1_used):
l_used = 0
w_used = 0
h_used = 0
for i in range(len(goods1_used)):
if goods1_used[i] == 0 and h_used + goods1[i][2] <= h:
l_used = max(l_used, goods1[i][0])
w_used = max(w_used, goods1[i][1])
h_used += goods1[i][2]
goods1_used[i] = 1
strips.append([l_used, w_used])
strips = sorted(strips, key=functools.cmp_to_key(cmp_2d), reverse=True)
#以w为限制码垛成层
levels = []
strip_used = [0 for i in range(len(strips))]
while sum(strip_used) < len(strip_used):
l_used = 0
w_used = 0
for i in range(len(strips)):
if strip_used[i] == 0 and w_used + strips[i][1] <= w:
l_used = max(l_used, strips[i][0])
w_used += strips[i][1]
strip_used[i] = 1
levels.append(l_used)
#再以l为限制码垛
levels = sorted(levels, reverse=True)
L_box_unused = [l]
for level in levels:
flag = -1
for i in range(len(L_box_unused)):
if L_box_unused[i] >= level:
if flag == -1:
flag = i
elif L_box_unused[i] < L_box_unused[flag]:
flag = i
if flag == -1:
L_box_unused.append(l - level)
else:
L_box_unused[flag] -= level
return len(L_box_unused)
# 选择合适的主箱子
def box_choose_3d(boxs, nums_simplePacking_1, nums_simplePacking_2, nums_simplePacking_3, nums_simplePacking_4, nums_simplePacking_5, nums_simplePacking_6):
l = -1
w = -1
h = -1
nums = -1
for i in range(len(boxs)):
if nums_simplePacking_1[i] != -1:
if nums == -1 or (nums != -1 and nums > nums_simplePacking_1[i]) or (nums != -1 and nums == nums_simplePacking_1[i] and l * w * h > boxs[i][0] * boxs[i][1] * boxs[i][2]):
l = boxs[i][0]
w = boxs[i][1]
h = boxs[i][2]
nums = nums_simplePacking_1[i]
if nums_simplePacking_2[i] != -1:
if nums == -1 or (nums != -1 and nums > nums_simplePacking_2[i]) or (nums != -1 and nums == nums_simplePacking_2[i] and l * w * h > boxs[i][0] * boxs[i][1] * boxs[i][2]):
l = boxs[i][0]
w = boxs[i][2]
h = boxs[i][1]
nums = nums_simplePacking_2[i]
if nums_simplePacking_3[i] != -1:
if nums == -1 or (nums != -1 and nums > nums_simplePacking_3[i]) or (nums != -1 and nums == nums_simplePacking_3[i] and l * w * h > boxs[i][0] * boxs[i][1] * boxs[i][2]):
l = boxs[i][1]
w = boxs[i][0]
h = boxs[i][2]
nums = nums_simplePacking_3[i]
if nums_simplePacking_4[i] != -1:
if nums == -1 or (nums != -1 and nums > nums_simplePacking_4[i]) or (nums != -1 and nums == nums_simplePacking_4[i] and l * w * h > boxs[i][0] * boxs[i][1] * boxs[i][2]):
l = boxs[i][1]
w = boxs[i][2]
h = boxs[i][0]
nums = nums_simplePacking_4[i]
if nums_simplePacking_5[i] != -1:
if nums == -1 or (nums != -1 and nums > nums_simplePacking_5[i]) or (nums != -1 and nums == nums_simplePacking_5[i] and l * w * h > boxs[i][0] * boxs[i][1] * boxs[i][2]):
l = boxs[i][2]
w = boxs[i][0]
h = boxs[i][1]
nums = nums_simplePacking_5[i]
if nums_simplePacking_6[i] != -1:
if nums == -1 or (nums != -1 and nums > nums_simplePacking_6[i]) or (nums != -1 and nums == nums_simplePacking_6[i] and l * w * h > boxs[i][0] * boxs[i][1] * boxs[i][2]):
l = boxs[i][2]
w = boxs[i][1]
h = boxs[i][0]
nums = nums_simplePacking_6[i]
return l, w, h
def packing_3d(l, w, h, goods):
# 先检查是否每一个商品在此规则下都能放下
if not can_put_3d(l, w, h, goods):
return -1
# 以h为限制码垛成条,商品排序,大的放前面
goods1 = []
for good in goods:
if good[0] <= l and good[1] <= w and good[2] <= h:
goods1
没有合适的资源?快使用搜索试试~ 我知道了~
3d_container_python三维装箱_python_3dpacking_
共28个文件
sample:12个
head:4个
py:2个
5星 · 超过95%的资源 29 下载量 47 浏览量
2021-09-29
12:10:56
上传
评论 11
收藏 5.36MB ZIP 举报
温馨提示
物流系统中的3维装箱的问题的python实现。
资源详情
资源评论
资源推荐
收起资源包目录
3d_container.zip (28个子文件)
.git
index 321B
hooks
fsmonitor-watchman.sample 5KB
pre-push.sample 1KB
prepare-commit-msg.sample 1KB
pre-merge-commit.sample 416B
applypatch-msg.sample 478B
pre-commit.sample 2KB
pre-receive.sample 544B
pre-applypatch.sample 424B
commit-msg.sample 896B
pre-rebase.sample 5KB
update.sample 4KB
post-update.sample 189B
config 306B
description 73B
refs
tags
heads
master 41B
remotes
origin
HEAD 32B
logs
refs
heads
master 185B
remotes
origin
HEAD 185B
HEAD 185B
packed-refs 114B
objects
info
pack
pack-cc662a3c8964452e6290f1963e522af843512070.idx 7KB
pack-cc662a3c8964452e6290f1963e522af843512070.pack 5.34MB
info
exclude 240B
HEAD 23B
3d_container_next1_1.py 21KB
.gitattributes 68B
3d_container_next2.py 28KB
共 28 条
- 1
爱牛仕
- 粉丝: 93
- 资源: 4716
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论6