473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Bin Packing Problem

Hi all,

I'm struggling with a specific bin packing problem...

I have a dataset where there is a column which identifies certain records. i.e. the cell takes a value 1 if the record needs including and 0 if not.
There is also a column which gives a number of parts needed. i.e. 1.56 or 2.73 etc.

What I'm trying to do is split the records into batches of 4 to minimise wastage. So I need a code to look at the identifier column and then group together those records identified in the groups which minimise wastage according to the number of parts column.

So ideally the output would be something like:

group 1: A D E P
group 2: B C F G

etc...

I'm sure this must be possible, but can't figure it out. Any help would be greatly appreciated. It seems to be different to the other bin packing problems I've seen as the desired outcome is any whole number not a specified value.
Apr 2 '12 #1

✓ answered by Guido Geurs

I hope this is the code you are looking for (see attachment)
PS:
I have changed some values to check if a group with total fraction=0 is selected first.
I can send you an explanation (drawing) of the code if necessary because I have used several array.

20 5456
Guido Geurs
767 Expert 512MB
Is it possible to attach in Bytes the workbook with a part of the records (+- 10) if there are to much ?
If the data is confidential, replace it with fictive values.
Apr 2 '12 #2
Hi Guido Geurs


This is a dummy workbook to show the structure
Attached Files
File Type: xls repair dummy.xls (41.0 KB, 538 views)
Apr 2 '12 #3
Guido Geurs
767 Expert 512MB
Is it possible to give an example according to the attached "repair dummy.xls" what you want to see?
Apr 2 '12 #4
Sorry I don't think I explained myself very well.

I'm looking for a code which will identify from column L which machines need a repair and then use column K to calculate the 4 machine combinations of these machines which minimises total wastage.

I may have been misleading talking about whole numbers as I think they're not necessarily what I need. (You can probably tell this is a bit above my skill level).

So ideally the end result would show the groups of ID's (from column E) and the total wastage.

i.e. group 1: G H J K
group 2: P I L M...
Total Wastage: x units.

Thanks for looking at this.
Apr 3 '12 #5
Guido Geurs
767 Expert 512MB
I hope this is it: (see also attachment)

Expand|Select|Wrap|Line Numbers
  1. Sub Filter()
  2. Dim ARRselected() As SELECTION
  3. Dim ARRidx As Integer
  4. Dim GROUPcount As Integer
  5. Dim ARRdump() As Variant
  6. Dim TOTALWASTAGE As Double
  7. Dim REPLACEbit As Border
  8.     Worksheets("Sheet1").Activate
  9.     Range("E3").Activate
  10.     ReDim ARRselected(0)
  11.     GROUPcount = 0
  12. '§ collect data
  13.     Do While ActiveCell.Value <> ""
  14.         '§ if "Refill"
  15.         If ActiveCell.Offset(0, 7).Value = 1 Then
  16.             ReDim Preserve ARRselected(UBound(ARRselected) + 1)
  17.             ARRselected(UBound(ARRselected)).MACHid = ActiveCell.Value
  18.             ARRselected(UBound(ARRselected)).WASTAGE = ActiveCell.Offset(0, 6).Value
  19.             GROUPcount = GROUPcount + 1
  20.         End If
  21.         '§ add blanco line if group=4
  22.         If GROUPcount = 4 Then
  23.             '§ add line for total group
  24.             ReDim Preserve ARRselected(UBound(ARRselected) + 1)
  25.             '§ total of the group
  26.             ARRselected(UBound(ARRselected)).MACHid = "Total"
  27.             ARRselected(UBound(ARRselected)).WASTAGE = _
  28.                     ARRselected(UBound(ARRselected) - 4).WASTAGE + _
  29.                     ARRselected(UBound(ARRselected) - 3).WASTAGE + _
  30.                     ARRselected(UBound(ARRselected) - 2).WASTAGE + _
  31.                     ARRselected(UBound(ARRselected) - 1).WASTAGE
  32.             TOTALWASTAGE = TOTALWASTAGE + ARRselected(UBound(ARRselected)).WASTAGE
  33.             ReDim Preserve ARRselected(UBound(ARRselected) + 1) '§ add blanco line
  34.             GROUPcount = 0
  35.         End If
  36.         '§ goto next record
  37.         ActiveCell.Offset(1, 0).Activate
  38.     Loop
  39.     '§ add final total
  40.     ReDim Preserve ARRselected(UBound(ARRselected) + 1) '§ add blanco line
  41.     ReDim Preserve ARRselected(UBound(ARRselected) + 1) '§ add blanco line
  42.         ARRselected(UBound(ARRselected)).MACHid = "TOTAL"
  43.         ARRselected(UBound(ARRselected)).WASTAGE = TOTALWASTAGE
  44. '§ dump data
  45.     '§ transform ARRSELECTED to 2D array
  46.     ReDim ARRdump(1 To UBound(ARRselected), 1 To 2)
  47.     For ARRidx = 1 To UBound(ARRselected)
  48.         ARRdump(ARRidx, 1) = ARRselected(ARRidx).MACHid
  49.         ARRdump(ARRidx, 2) = ARRselected(ARRidx).WASTAGE
  50.     Next
  51.     '§ dump to sheet2
  52.     Sheets("sheet2").Activate
  53.     Range("A1").Resize(UBound(ARRdump), 2) = ARRdump
  54.     '§ clear cells with zero
  55.     Worksheets("Sheet2").Columns("B").Replace What:="0", Replacement:="", _
  56.         SearchOrder:=xlByColumns, MatchCase:=True, lookat:=xlWhole
  57. End Sub
Attached Files
File Type: xls repair dummy_v1.xls (57.5 KB, 370 views)
Apr 3 '12 #6
Thank you for this the code looks good, but it doesn't quite do what I was looking for. It seems to just work down grouping the records by row order not by minimal wastage.

Is there a way to tweak it so that it examines all the records and then groups them according to least wastage not just in order?
Apr 3 '12 #7
Guido Geurs
767 Expert 512MB
it must be= ??

G 1.62
K 1.74
P 1.8
L 2.31

H 2.82
J 2.97
M 3.3
N 4.35
Apr 3 '12 #8
these are the results I get when I run the filter macro...

G 1.62
H 2.82
J 2.97
K 1.74
Total 9.15

L 2.31
M 3.3
N 4.35
P 1.8
Total 11.76


TOTAL 20.91


Are you getting different results?
Apr 3 '12 #9
Guido Geurs
767 Expert 512MB
I have the same results but in your previous mail you are mentioning:
"...and then groups them according to least wastage not just in order? "
Is it sorted what you want? like=
G 1.62
K 1.74
P 1.8
L 2.31

H 2.82
J 2.97
M 3.3
N 4.35

Or how do you want them sorted?
Please tell me what you just want with the file you have attached (with an example list).
Apr 4 '12 #10
I am missing the step From getting them in order to sorting into the groups of 4 to produce the least wastage.

for example if I changed the values column K as follows:

record G = 1.3
record H = 1.2
record M = 1.3
record P = 1.2

I was hoping the code would identify that this combination would produce zero wastage and group them together.

I thought I'd add for clarity that my definition of least wastage would be the group producing as close to a whole number as possible

Again thank you so much for your help on this.
Apr 4 '12 #11
Guido Geurs
767 Expert 512MB
Is this right, you want to see only the 4 data with the least wastage number:

G 1.62
K 1.74
P 1.8
L 2.31

If not, please attach the workbook with in sheet1 the data and in sheet2 the results you want to see.
Sorry but it's a little confusing for me.
Apr 4 '12 #12
sorry this is my inability to express myself fully.

What I want to see is all the data split into groups of 4 where the sum of all the values in each group are as close to a whole number as possible.

In this way we can share packs of parts across the group and waste fewer packs.

I think the central assumption is that without grouping a repair requiring 1.3 parts would need 2 packs and waste .7 of a pack.

Therefore if 4 packs can be grouped by how close to a whole number the sum of the parts required is, savings can be made.

I have tried to demonstrate on sheet 2.... (I have modified the numbers to make this easier to calculate by hand)
Attached Files
File Type: xls repair dummy_v1.xls (55.5 KB, 342 views)
Apr 4 '12 #13
Guido Geurs
767 Expert 512MB
I hope this is the code you are looking for (see attachment)
PS:
I have changed some values to check if a group with total fraction=0 is selected first.
I can send you an explanation (drawing) of the code if necessary because I have used several array.
Attached Files
File Type: xls repair dummy_v3.4.xls (74.0 KB, 329 views)
Apr 5 '12 #14
That looks perfect. I can't thank you enough. If you wouldn't mind sending the explanation that would be v useful for me.
Apr 6 '12 #15
Guido Geurs
767 Expert 512MB
Attached are some flowcharts of the code.
Attached Files
File Type: pdf Visio-repair dummy_v3.4__v2.pdf (502.3 KB, 357 views)
Apr 7 '12 #16
Guido Geurs
767 Expert 512MB
This is a version working on the same principle but with the indexes of the ARRSEL array.
Maybe a little faster with large sheets
Attached Files
File Type: xls repair dummy_v4.1.xls (73.0 KB, 319 views)
Apr 7 '12 #17
That's perfect. Thank you so much for this.
Apr 10 '12 #18
Hi Guido,

Last year you were increadibly helpful with this problem, and I was hoping you could provide some of your expertise again to help with a slight issue I've identified when using your code in practise.

It is perfect as long as a multiple of 4 is not entered. However, when a multiple of 4 is entered it seems to ignore one record.

Alternatively if anyone else can help I'd greatly appreciate it.

I have attached a workbook.

Many Thanks in advance,
Attached Files
File Type: xls repair dummy_v5.xls (1.78 MB, 366 views)
May 7 '13 #19
Guido Geurs
767 Expert 512MB
Sorry, my mistake.
For the last records there is an error in the code.
There is 2 times "Case 3" so If there are 4 records left, the 4th will never be seen.
It must be:
Expand|Select|Wrap|Line Numbers
  1. .....
  2.                 Case 3
  3.                     .INDEX3 = ARRSELidx
  4.                 Case 4
  5.                     .INDEX4 = ARRSELidx
  6.                 End Select
  7.             End With
  8. .....
Attached Files
File Type: xls repair dummy_v5.0.xls (1.77 MB, 462 views)
May 9 '13 #20
perfect.

Thanks again Guido.
May 10 '13 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ZaGras | last post by:
after i pack my vb program using package and deployment wizard, i try to install the program on other computer instead of my computer and run the program. when i click to add a new record to the...
4
by: j_mckitrick | last post by:
Hi all. Here is a tiny container for one of each combo box, along with the glade file. Just 2 widgets, so hopefully not too large. How the heck do I get the selection from the ComboBox, as...
0
by: nobull | last post by:
Google won't let me post this as a follow-up but lynch@agere.com (lynto) wrote in message news:<503469eb.0407271148.7ee4b0ca@posting.google.com>... > Does anyone have an algorithm for packing...
5
by: Michael Olea | last post by:
Here is a design problem I ran into this am - and I have cleaned the bathroom, scrubbed toilet sink and tub, windexed all glass, mopped the floor, and vacuumed the house - no dice, the problem is...
2
by: gbb0330 | last post by:
Hi all I need some advice. the daily packing number will be used to match a box with its label. the guys in the warehouse will get a list of items to pack. they will find the item - put it...
1
by: gbb0330 | last post by:
hi guys -the code (all capital letters) generates daily packing number, it is in the on click event of a command button that moves to the next record. dpkn is unbound control - i use it to...
2
by: FMorales | last post by:
Hello all, quick hopefully easy question. Here goes. I've started on the Art Of Assembly tutorial(s) (http://webster.cs.ucr.edu/Page_asm/0_ArtOfAsm.html) and got to the sample projects and kinda...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
9
by: fraz | last post by:
Does anyone have code to solve a 3-d bin packing problem in php? I am trying to solve the issue of packing various sized rectangular shaped objects into boxes of three different sizes so as to use...
1
by: QbProg | last post by:
Hello, what I'm saying here is about VS 2005 WITHOUT service pack. I have two DLL projects, with EXACTLY the same project preferences and settings. Both have alignment set to "default", it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.