+ Reply to Thread
Results 1 to 12 of 12

Optimizing a number matrix

  1. #1
    Forum Contributor
    Join Date
    05-12-2013
    Location
    Australia
    MS-Off Ver
    Microsoft Office 365
    Posts
    117

    Optimizing a number matrix

    The attached file shows two sets of column numbers. Cell numbers in each row can be shuffled between columns A, B & C, and F & G, such that the sum of each set of individual columns is a minimum.
    Cheers.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Optimizing a number matrix

    Can you give example of the final result you want.
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    05-12-2013
    Location
    Australia
    MS-Off Ver
    Microsoft Office 365
    Posts
    117

    Re: Optimizing a number matrix

    Attached Example 2.
    By swapping (say) numbers 9 and 26 in col K & L the totals are probably close to the minimum values. Is it possible to get the totals to zero? That exercise would be very time consuming.
    Similarly for the other 2 col table, swapped numbers are shown in col P & Q. This table shows little improvement but the difference in totals has narrowed from -17 to -3.
    Hope this helps.
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    09-14-2018
    Location
    China
    MS-Off Ver
    Office 2010
    Posts
    41

    Re: Optimizing a number matrix

    You need to install an add-in called Open Solver.
    Www.opensolver.org
    Then set up the model as attached.
    I set up the model for you for 2-column scenario and 3-column scenario.
    This is a Mixed Integer Programming problem.

    Best,
    Jimmy
    Attached Files Attached Files
    Last edited by astupig; 08-13-2020 at 04:18 AM.

  5. #5
    Forum Contributor
    Join Date
    05-12-2013
    Location
    Australia
    MS-Off Ver
    Microsoft Office 365
    Posts
    117

    Re: Optimizing a number matrix

    I had given up!
    Excellent solution and solves my problem. Thank-you.

  6. #6
    Registered User
    Join Date
    09-14-2018
    Location
    China
    MS-Off Ver
    Office 2010
    Posts
    41

    Re: Optimizing a number matrix

    You are welcome. Glad it helps.

    Jimmy

  7. #7
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Optimizing a number matrix

    Nice solution Jimmy! Got any recommendation for learning about "Mixed Integer Programming"?

    Quick question do one really need all the constraint you used in your "2-column" setup?

    I made a modification of your "2-column" setup and one can either set the object function to "=Abs(G30)-Abs(H30)" or "=Abs(H30)-Abs(G30)". This will change the values in the
    F column but the value of the object function is 1 in both cases.

    Alf
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-14-2018
    Location
    China
    MS-Off Ver
    Office 2010
    Posts
    41

    Re: Optimizing a number matrix

    Hi Alf,

    See below link for the book of Decision Making, there are many cases regarding Mixed Integer Programming.
    https://opensolver.org/opensolverwor...onModeling.pdf

    =Abs()-Abs() is an excellent idea for considering the different of two sums.
    Very nice! I never thought of this kind of "ABS" function is accepted by Open Solver.

    But one issue, the abs-abs will lead to unexpected result: for example, 59 and -59.
    See attached, I modified B4 from 4 to 104 and run your model again and you can see the result is not what we expect.
    The variables U,V I introduced is from the idea of the book recommended by Open Solver. See Section 6.1 Absolute Values
    https://opensolver.org/opensolverwor...mingTricks.pdf

    Jimmy
    Attached Files Attached Files
    Last edited by astupig; 08-14-2020 at 08:07 PM.

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Optimizing a number matrix

    Hi Jimmy

    Thanks for the links and feedback especially about the problem using the Abs() function. As the Mixed Integer Programming is a technique I've never known before I need to study the how and the why of it so I can use it properly.

    Alf

    Ps Not using the Abs() function and just taking in sum difference i.e. "=G30-H30" or "=H30-G30" works right on your last uploaded file as well as the previous ones. If you got time could you check and see if you could find a combination of number where it goes wrong?
    Last edited by Alf; 08-15-2020 at 12:56 AM.

  10. #10
    Registered User
    Join Date
    09-14-2018
    Location
    China
    MS-Off Ver
    Office 2010
    Posts
    41

    Re: Optimizing a number matrix

    Hi Alf,

    You are correct. The 2-column case =G30-H30 works properly. So no need extra variables U,V.
    Thanks for pointing this out.

    Jimmy

  11. #11
    Valued Forum Contributor Hydraulics's Avatar
    Join Date
    07-15-2018
    Location
    Udine - Italy
    MS-Off Ver
    Office 365
    Posts
    372

    Re: Optimizing a number matrix

    Quote Originally Posted by Alf View Post
    Ps Not using the Abs() function and just taking in sum difference i.e. "=G30-H30" or "=H30-G30" works right on your last uploaded file as well as the previous ones.
    We can also minimize directly one of the two sums, for instance G30, and only add the constraint G30 >= H30. This works also for the 3 column problem.

    By the way, Solver complains that the problem is not linear, since there is an IF function in columns G:H. OpenSolver performs only a quick linearity check and may report erroneous results. As a workaround, we can write

    =(1-F3)*B3+F3*C3

    in cell G3.

    HTH,

    Francesco
    Aim high or don't even try.
    ---------------------------------
    If your question has been answered, don't forget to mark the thread as SOLVED.
    If you find an answer helpful, click on the star icon at the bottom of the post.

  12. #12
    Registered User
    Join Date
    09-14-2018
    Location
    China
    MS-Off Ver
    Office 2010
    Posts
    41

    Re: Optimizing a number matrix

    Hi Francesco,

    Thanks. Yes, the if function may appear non-linear. Your =(1-F3)*B3+F3*C3 is better.

    Jimmy

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help optimizing formula that returns row number
    By trickyricky in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-07-2018, 03:26 PM
  2. Number Matrix
    By toughTerry in forum Excel General
    Replies: 1
    Last Post: 07-26-2011, 10:49 AM
  3. Number Lookup in Matrix
    By N Harkawat in forum Excel Formulas & Functions
    Replies: 24
    Last Post: 09-06-2005, 06:05 AM
  4. Number Lookup in Matrix
    By N Harkawat in forum Excel Formulas & Functions
    Replies: 36
    Last Post: 09-06-2005, 04:05 AM
  5. Number Lookup in Matrix
    By Rod in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  6. [SOLVED] Number Lookup in Matrix
    By Rod in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  7. Number Lookup in Matrix
    By Rod in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-02-2005, 07:05 PM

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