乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 11|回复: 4

[编程交流] (nesting)optimize bar lengths

[复制链接]

34

主题

105

帖子

91

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
224
发表于 2022-7-5 17:44:58 | 显示全部楼层 |阅读模式
Hi,
 
 
Does anyone know any code that would allow me to optimize bar lengths?
 
I have bar lengths that are 6m long and I have to cut 20 allsorted lengths from the 6m lengths.
 
What code would you write to perform this task?
 
Thanks
 
Col
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-5 18:06:36 | 显示全部楼层
Related subjects. I thought there was another one but could not find it.
 
http://cadtutor.net/forum/viewtopic.php?t=2257&highlight=
 
http://cadtutor.net/forum/viewtopic.php?t=6690&highlight=
回复

使用道具 举报

34

主题

105

帖子

91

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
224
发表于 2022-7-5 18:18:37 | 显示全部楼层
Those are kinda what im looking for but the seem overally complicated.
 
All I need to be able to do is 1D optimizing and it doesnt need to be drawn out, could use Text boxes for input & output
 
any thoughts?
 
cheers
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-5 18:34:42 | 显示全部楼层
This is something I was playing with some time back. Perhaps you can make use of it.
 
  1. (defun c:test(/ lst maxlen) (setq lst '(144 35 23 86 99 12 230 12 12 14 132 189 6 3 99)) (setq maxlen 240.0) (get_cutlist lst maxlen));;  result ((99) (99 132) (86 144) (12 12 12 14 23 35 189) (3 6 230));;  CAB 03-10-06(defun get_cutlist (lst maxlen / cutlst itm lst ptr tl x finallst remove-at) (defun remove-at (lst pos / head) ; Tony Tanzillo   (repeat pos     (setq head (cons (car lst) head)           lst  (cdr lst)     )   )   (append (reverse head) (cdr lst)) ) (setq lst (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst '>))) ;;  step through lst (while lst   (setq cutlst (list (car lst)) ; start new cutlist w/ first item         lst    (cdr lst) ; remove first item         ptr    (1- (length lst)) ; point to end of list         tl     (apply '+ cutlst) ; total length so far   )   ;; build the cutlst   (while (and lst cutlst)     ;; find largest next cut     ;; exit conditions ptr < 0 or itm length exceeds max     (while (and (< (+ tl (setq itm (nth ptr lst))) maxlen)                 (> ptr 0))       (setq ptr (1- ptr))     )     (if (> ptr -1)       (if (= ptr (1- (length lst)))         ;;  no more cuts fit, go to next         (setq finallst (cons cutlst finallst)               cutlst   nil         )         (setq cutlst (cons (nth (1+ ptr) lst) cutlst)               lst    (remove-at lst (1+ ptr))               tl     (apply '+ cutlst) ; new total         )       )       ;; else exausted pointer       (setq finallst (cons cutlst finallst)             cutlst   nil       )     )    )  ) (if cutlst   (cons cutlst finallst)   finallst ))
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
0
发表于 2022-7-5 18:48:46 | 显示全部楼层
Hi Guys,
 
I was playing around with the code above and noticed that it wouldn't work in a real world situation when I make;
 
(setq maxlen 6500.0) and (setq lst '(1120 2705 2725 2715)).... I get back ((2715) (1120 2705 2725)) = 6550? this should be (2725 2715)(2705 1120)
 
(setq maxlen 6500.0) and (setq lst '(2715 1050 2725 2705)).... i get back ((2715) (1050 2705 2725)) where as this should optimize to (2725 2715 1050)(2705)
 
 
Can someone please help me fix this code?
 
Cheers
Mike
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 04:16 , Processed in 0.963216 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表