+ Reply to Thread
Results 1 to 10 of 10

Permutation List by Inventory and Value Total

  1. #1
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Permutation List by Inventory and Value Total

    Hello,
    I am trying to create a list of permutations which select from an inventory of items, sometimes multiple or none based on an available quantity, and then check a reference value of those items to see if they meet a particular total. For instance, such a set:
    (I apologize for the formatting of both of these tables. Whitespace I use while editing this post is being removed by the forum after submission.)

    Item Quantity Value
    Part A 0-2 100
    Part B 0-4 70
    Part C 0-4 40
    Part D 0-6 10

    By doing this manually I can create a permutation list that appears as this:
    A B C D Total Pieces
    1 0 2 3 4 300 9
    2 0 2 4 0 300 6
    3 0 3 1 5 300 9
    4 0 3 2 1 300 6
    5 0 4 0 2 300 6
    6 1 0 4 4 300 9
    7 1 1 2 5 300 9
    8 1 1 3 1 300 6
    9 1 2 0 6 300 9
    10 1 2 1 2 300 6
    11 2 0 1 6 300 9
    12 2 0 2 2 300 6
    13 2 1 0 3 300 6

    I've done this manually using an inventory set up to approximately 80,000 rows, however now I have a larger inventory data set which results in approximately 1.4 billion rows, exceeding the limits of excel using my previous methods. I'm afraid I will have to purchase a C++ compiler to create a program which tests each permutation for the desired total value and then dumps entries to a text file, however I believe it is likely this can be done in Excel using methods I am not skilled enough to apply.

    For example, I have attached the sample file I used to create this list. Sheet 1 is the raw data including every possible permutation. Sheet 2 contains the same data but sorted, with point per item subtotals hidden for formatting, and with a piece total. Sheet 3 is my desired final result, cut to show only those permutations which match the desired value total.

    Thank you very much for taking the time to read my post! I hope you find this problem as intriguing as I do!
    Attached Files Attached Files
    Last edited by AlbertMarty; 05-13-2013 at 06:55 AM.

  2. #2
    Registered User
    Join Date
    04-22-2013
    Location
    The Netherlands
    MS-Off Ver
    Excel 2003/2007 & 2010
    Posts
    90

    Re: Permutation List by Inventory and Value Total

    Hey,

    have a look at attached workbook with the following code:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Permutation List by Inventory and Value Total

    This works for your example I think

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Permutation List by Inventory and Value Total

    You guys are amazing! It will take me some effort to modify your example to fit my new data set but I believe I can manage it. I will mark my post solved after I complete my project tomorrow. You guys provided such a rapid response!

    Thank you very much for your assistance!

  5. #5
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Permutation List by Inventory and Value Total

    Hello again!
    I have modified the code to use my new data set, however it is 2 hours into a run and has only calculated a fraction of the data. I attempted to replace some of the cell references with the actual values to reduce computation time but it doesn't seem to have reduced the number of minutes.

    I also added some code to benchmark the speed of processing and output to the statusbar. I would never have attempted these things but seeing your code inspired me to try applying my own C++ knowledge. So far it's benchmarking at just over 2 days runtime! I hope after that I don't end up with over 1 million results, thereby exceeding the Excel limits again, and effectively making my document unprintable. Even so I'm beginning to believe the resulting list will be far too many pages for me to format for printing, negating some of the projects application.

    I also added +1 to the pieces total to include a base starting piece, and also a check to limit number of total pieces to 48, not that those details are important to the code.

    In any case, I wanted to share the resulting project document with you guys in case you have some wizardry that significantly reduces computation time!

    Thank you very much again, this would have been literally impossible without your help!

    (I figured out how to remove attachments after all so I've removed my previously uploaded v3 which contained errors.)
    Last edited by AlbertMarty; 05-13-2013 at 08:27 PM.

  6. #6
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Permutation List by Inventory and Value Total

    Silly me, I ran into an error because I didn't think to change r from Int to Long. That is corrected now. I wanted to simply replace the v3 document but I couldn't figure out how to delete documents I've uploaded here through the management UI. I'm going to start a new run and I'll reply again when it finishes or overflows again.

    Thank you!
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Permutation List by Inventory and Value Total

    After 43.3 hours the script is complete! Totaling 873,691 selected results out of the possible 878,353,875 permutations. So close to the 1.04 million row limit of Excel 2007. The end file comes in at 50.5 mb, not too bad. I think this will probably be the largest and longest excel project I ever work on.

    I'm marking this thread as SOLVED now. One final thank you to the people that helped me do something that seemed virtually impossible.

    Thank you!
    Al

  8. #8
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Permutation List by Inventory and Value Total

    Well, I realized I had made a mistake in the inventory of 2 of the items so I had to restart the whole thing. I definitely didn't want to do another 43 hour run, so I tried replacing the value references in the "result =" line with the actual values.... BOOM! It took 32 minutes to do 975 million permutations now. MASSIVE performance increase by removing the cell references. This has been an extremely valuable lesson for me.

    Thank you again guys!

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Permutation List by Inventory and Value Total

    What are you going to do what all that data?
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Registered User
    Join Date
    05-13-2013
    Location
    San Jose, CA.
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Permutation List by Inventory and Value Total

    It was a personal project to calculate the optimal selections of equipment for an experimental board game. I hadn't revealed it was a game related project before because I didn't want anyone to dismiss my request as unimportant, which it is.
    The old project from a few years ago returned few enough results that I printed them out (7 pages) and used them as a reference sheet for player use during testing, but now I want to expand the options and that has made a 13,000 page document that I can't possibly use in the same way. It was still a fun and educational project for me though.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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