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.
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
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.
Hi Guido Geurs
This is a dummy workbook to show the structure
Is it possible to give an example according to the attached "repair dummy.xls" what you want to see?
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.
I hope this is it: (see also attachment) - Sub Filter()
-
Dim ARRselected() As SELECTION
-
Dim ARRidx As Integer
-
Dim GROUPcount As Integer
-
Dim ARRdump() As Variant
-
Dim TOTALWASTAGE As Double
-
Dim REPLACEbit As Border
-
Worksheets("Sheet1").Activate
-
Range("E3").Activate
-
ReDim ARRselected(0)
-
GROUPcount = 0
-
'§ collect data
-
Do While ActiveCell.Value <> ""
-
'§ if "Refill"
-
If ActiveCell.Offset(0, 7).Value = 1 Then
-
ReDim Preserve ARRselected(UBound(ARRselected) + 1)
-
ARRselected(UBound(ARRselected)).MACHid = ActiveCell.Value
-
ARRselected(UBound(ARRselected)).WASTAGE = ActiveCell.Offset(0, 6).Value
-
GROUPcount = GROUPcount + 1
-
End If
-
'§ add blanco line if group=4
-
If GROUPcount = 4 Then
-
'§ add line for total group
-
ReDim Preserve ARRselected(UBound(ARRselected) + 1)
-
'§ total of the group
-
ARRselected(UBound(ARRselected)).MACHid = "Total"
-
ARRselected(UBound(ARRselected)).WASTAGE = _
-
ARRselected(UBound(ARRselected) - 4).WASTAGE + _
-
ARRselected(UBound(ARRselected) - 3).WASTAGE + _
-
ARRselected(UBound(ARRselected) - 2).WASTAGE + _
-
ARRselected(UBound(ARRselected) - 1).WASTAGE
-
TOTALWASTAGE = TOTALWASTAGE + ARRselected(UBound(ARRselected)).WASTAGE
-
ReDim Preserve ARRselected(UBound(ARRselected) + 1) '§ add blanco line
-
GROUPcount = 0
-
End If
-
'§ goto next record
-
ActiveCell.Offset(1, 0).Activate
-
Loop
-
'§ add final total
-
ReDim Preserve ARRselected(UBound(ARRselected) + 1) '§ add blanco line
-
ReDim Preserve ARRselected(UBound(ARRselected) + 1) '§ add blanco line
-
ARRselected(UBound(ARRselected)).MACHid = "TOTAL"
-
ARRselected(UBound(ARRselected)).WASTAGE = TOTALWASTAGE
-
'§ dump data
-
'§ transform ARRSELECTED to 2D array
-
ReDim ARRdump(1 To UBound(ARRselected), 1 To 2)
-
For ARRidx = 1 To UBound(ARRselected)
-
ARRdump(ARRidx, 1) = ARRselected(ARRidx).MACHid
-
ARRdump(ARRidx, 2) = ARRselected(ARRidx).WASTAGE
-
Next
-
'§ dump to sheet2
-
Sheets("sheet2").Activate
-
Range("A1").Resize(UBound(ARRdump), 2) = ARRdump
-
'§ clear cells with zero
-
Worksheets("Sheet2").Columns("B").Replace What:="0", Replacement:="", _
-
SearchOrder:=xlByColumns, MatchCase:=True, lookat:=xlWhole
-
End Sub
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?
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
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?
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).
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.
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.
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)
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.
That looks perfect. I can't thank you enough. If you wouldn't mind sending the explanation that would be v useful for me.
Attached are some flowcharts of the code.
This is a version working on the same principle but with the indexes of the ARRSEL array.
Maybe a little faster with large sheets
That's perfect. Thank you so much for this.
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,
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: - .....
-
Case 3
-
.INDEX3 = ARRSELidx
-
Case 4
-
.INDEX4 = ARRSELidx
-
End Select
-
End With
-
.....
perfect.
Thanks again Guido.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
| |