How to optimise material use with VBA and multiple solvers

ZPar

New Member
Joined
Aug 3, 2022
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hello guys,
I got the following problem.
I need to calculate the minimum required aluminum bars and cut them in predetermined lengths.
The problem is the following:
Constraints
1: My aluminum bars are 6m long
2: Every time I cut, 4mm of material is lost.
Let's say that I have the following requirements
6000mm - Qnty: 1
5400mm - Qnty: 1
3770mm - Qnty: 2
2450mm - Qnty: 4
1255mm - Qty: 7
550mm - Qty: 3
I would create a table with 3 columns
Any ideas, anyone?
Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi, I'm a little late but maybe it will be useful to you.
Here is a working file:

Bars.zip

It just uses formulas. And it is too big to past de whole xl2bb
Here is the first columns:

Bars.xlsx
ABCDEFGHIJKLMNOPQ
1Bar length [mm]6000Max length used of 1 bar6000
2Theoretical min # of bars7
3# of bars needed877777
4Calculation
5# of pieces1812345
6RequirementsSorted resultUnsorted result65776
7Length [mm]QtyPiece lengthBar #Piece lengthBar #Long with cuts128461552897741245918687
86000124501600061600065321
95400112551540022540443717
103770254002377083377472376
11245045502377074377462266
121255724503245035245432276
13550312553245056245474566
1424504245017245424435
1512554245048245442766
1612554125519125964666
17245051255410125944567
18125551255711125924576
1955051255512125936564
20600061255413125912446
21377071255314125972657
22125571255815125966113
23550755051655462771
243770855071755416743
251255855021855443535
Sheet1
Cell Formulas
RangeFormula
F1F1=MAX(BYROW(UNIQUE(I8#), LAMBDA(x, SUM($L$8:$L$100*(I8#=x)))))
F2F2=ROUNDUP(SUM(L8#)/$C$1,0)
F3F3=COUNT(UNIQUE(I8#))
M3:NUB3M3=INT(SEQUENCE(,10000,0)/(10000/4))+$F$2
C5C5=SUM(C8:C25)
M5:NUB5M5=SEQUENCE(,10000)
M6:Q6M6=COUNT(UNIQUE(M8#))
M7:Q7M7=MAX(BYROW(UNIQUE(M8#), LAMBDA(x, SUM($L$8#*(M8#=x)))))
E8:F100E8=LET(d, SORT(H8:I100,2), IF(d=0,"",d))
H8:H25H8=LET(l,NUMBERVALUE(TEXTSPLIT(CONCAT(REPT(B8:B25&";",C8:C25)),,";",1)), l )
I8:I100I8=LET(b, INDEX(M8:NUB100,,MATCH(LET(d, (M7:NUB7<=C1)*M6:NUB6, MIN(IF(d = 0, "", d)))&";1", M6:NUB6&";"&(M7:NUB7<=C1)*1,0)), IF(b=0, "",b))
K8:K25K8=SEQUENCE(SUM(C8:C25))
L8:L25L8=LET(l,NUMBERVALUE(TEXTSPLIT(CONCAT(REPT($B$8:$B$25&";",$C$8:$C$25)),,";",1)), lwc,IF(l<($C$1-4),l+4,$C$1), lwc )
M8:Q25M8=RANDARRAY($C$5, , 1,M3,TRUE)
Dynamic array formulas.


there are 10000 columns for the calculation.
Basically we generate random combination and check the minimum number of bar needed.
You'll have to press F9 a few time to see if the "# of bars needed" (cell F3) becomes smaller.

For your example data with less than 5 F9 presses you'll get the result of 8 bars. Which i think is the smallest amount of bars needed.
The result in cells E8:F8 and downwards may not have all numbers from 1 to 8, there may be 1 to 10 and a 3 or some other number missing. Thats because they are the random generated numbers.

One example:

Piece lengthBar #
24501
24501
24502
12552
12552
5502
37704
12554
5504
12555
12555
5505
54007
60008
37709
12559
245010
125510


Here you can see that the bar sequence is from 1 to 10 but the 3 and the 6 are missing.
We could see to change the numbers so they would be from 1 to 8 (if 8 is the maximum number of bars needed).

Let me know if it works for you.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top