+ Reply to Thread
Results 1 to 14 of 14

Permutations of a list (groups of 3)

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by xlwho
    Thanks for the reply...instead of considering all possible combinations of matched sets, I guess we're looking at some kind of VB script that:

    1. Starts at the first row of the sorted input table and stores the flow and length values in temporary variables
    2. Proceeds to the next row of the sorted table and stores the flow and length values in a second set of variables.
    3. Proceeds to the next row and stores a third set of variables.
    4. Performs a calculation on the stored variables to determine if the sum of the flows falls within the necessary range.
    5. If so, populate the first row in the output table with the results and delete the three rows from the input table and resort.
    6. If not, replace the third input row with the next available input row and recalculate. Continue looping through the subsequent rows until a set can be made. This might require nested loops because if no acceptable third variable makes a matched set, the second and then the first input rows would have to be increase by 1 (while also making sure that row is not already being used in the variable set) each time the loop runs without a successful "hit" meeting the conditions.
    7. Repeat until no additional matched sets are found.

    Would this yield the least waste? If so, what would the script look like? If not, how could it be optimized?
    Your suggested algorithm can be incorporated in a macro with nested loops but it will not ensure minimum waste. For that we will have to use some more complex mathematial methods I don't much about.
    Just to confirm what I understand the problem can I say that you have a number of rectangular pieces and you want to make bigger rectangular pieces by joing three pieces together and the new assemblies will have width between 140 and 180 and length as much as possible ( I will have to cut two pieces in length so that they match the length of the shortes in the group).
    It sounds very interesting but seems complex. Let me think this over.

    A V Veerkar

  2. #2
    Registered User
    Join Date
    11-01-2006
    Posts
    18
    Quote Originally Posted by avveerkar
    Your suggested algorithm can be incorporated in a macro with nested loops but it will not ensure minimum waste. For that we will have to use some more complex mathematial methods I don't much about.
    Just to confirm what I understand the problem can I say that you have a number of rectangular pieces and you want to make bigger rectangular pieces by joing three pieces together and the new assemblies will have width between 140 and 180 and length as much as possible ( I will have to cut two pieces in length so that they match the length of the shortes in the group).
    It sounds very interesting but seems complex. Let me think this over.
    A V Veerkar
    Exactly right...the two longer pieces in a matched set are wasted material. Your analogy of thickness substituted for flow is perfect...sum of the assembled piece must be within acceptable range or it is not useable.

    I was actually attempting to do this in a database where table one is comprised of the input records (subtracting rows as sets are made) and another table is populated with the matched sets as they are created, but I'm not good enough with the database language to code this, so I figured i'd see if there's an Excel solution.

  3. #3
    Forum Contributor
    Join Date
    07-05-2007
    Location
    Lexington, MA
    Posts
    302

    A worksheet example of simple, largest fit

    I have attached a worksheet that works on a simpler problem that tries to fit quantities into bins. I shows a worksheet approach, and may give you some ideas. This doesn't solve your problem, but I did have it lying around.
    Attached Files Attached Files
    FrankBoston is the pen name for Andrew Garland, Lexington MA

  4. #4
    Registered User
    Join Date
    11-01-2006
    Posts
    18
    Thanks Frank. I'm thinking the only way to do this is to write a script and loop through all of the possible combinations and perform analysis before populating a new output table. Might not be possible in Excel, but perhaps Access is better suited for this.

  5. #5
    Registered User
    Join Date
    11-01-2006
    Posts
    18
    I was talking to a friend today and he said there may be an easier way to do this. You make a table on one sheet that takes your input data and you make a second table on another sheet that serves as your output "sets" table. Since we're making combined sets of 3 items from the data input table, the output table will always be a maximum of 1/3 the number of rows of the input table. If your starting list is 100 items, the maximum number of acceptable unique sets you can end up with is 33.

    The number of possible iterations of 100 items being made into sets of 3 is (100*99*98)/6 or 161,700 but you don't want to create a table with that many rows, so you limit the output table size to just what you need and overwrite existing values if a better set is found than one already in the table (as you iterate through the various permutations).

    A nested loop could be used to create possible combinations in memory processing rows in the input table, simplified like this:

    For x = 1 to 100
    For y = x+1 to 99
    For z = y+1 to 98

    Perform analysis on possible set and see if it meets the criteria
    Check output table to see if any items from current set are already in the table
    If so, overwrite the output table row with new set values if waste value is smaller
    If not, write set data to next available row in output table

    Next z
    Next y
    Next x

    Anyone think their VBA is good enough to perform this type of function?
    Last edited by xlwho; 09-20-2007 at 06:53 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1