+ Reply to Thread
Results 1 to 13 of 13

Optimal Mix of Products

  1. #1
    Registered User
    Join Date
    04-18-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    70

    Optimal Mix of Products

    Hi,

    I have a problem from relating to the optimal mix of foods to meet a target nutrient content.

    Attached is a example sheet, the left hand side is a list of random foods and their nutritional content for 1 serving, to the right in yellow is the target nutritional content.

    The question i have to answer is, what is the best mix of those foods to deliver the target nutritional content.

    I thought solver would do this, but i couldnt work it out.

    Does anyone have any ideas?

    Thanks
    Attached Files Attached Files

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

    Re: Optimal Mix of Products

    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    1
    Food
    Protein
    Fat
    Carbs
    Cal
    Serving
    Protein
    Fat
    Carbs
    Cal
    2
    Almonds (30g)
    7.1
    16.7
    1.4
    188.0
    2.3
    16.0
    37.6
    3.2
    423.6
    H2: =$G2*B2
    3
    Tuna (1 Can)
    29.8
    1.2
    0.6
    134.0
    1.0
    30.2
    1.2
    0.6
    135.8
    4
    Veg Bag
    4.0
    6.6
    1.0
    29.0
    1.0
    3.9
    6.5
    1.0
    28.5
    5
    Basa (2 Pieces)
    39.6
    2.0
    1.0
    184.0
    1.1
    42.3
    2.1
    1.1
    196.6
    6
    Egg Whites (100ml)
    9.9
    0.1
    1.0
    43.0
    1.0
    9.9
    0.1
    1.0
    42.9
    7
    Peanut Butter (1Tbsp)
    5.5
    9.5
    2.6
    119.0
    1.8
    9.8
    16.9
    4.6
    211.3
    8
    Brown Rice (125g)
    4.1
    4.5
    35.8
    211.0
    2.9
    12.0
    13.1
    104.6
    616.3
    9
    Chicken Breast (100g)
    31.0
    3.6
    0.0
    165.0
    1.2
    37.9
    4.4
    0.0
    202.0
    10
    Total
    162.0
    82.0
    116.0
    1857.0
    H10: =SUM(H2:H9)
    11
    Target
    162.0
    82.0
    116.0
    1857.0
    12
    0.0
    K12: {=SQRT(AVERAGE((H10:K10 - H11:K11)^2))}


    Set K2 to Min by changing G2:G9
    Entia non sunt multiplicanda sine necessitate

  3. #3
    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: Optimal Mix of Products

    Using the sumproduct function you could set up a solver mode like this perhaps. You could also reach the target value without all the components. Just remove the constraint
    that B2:B9 values should be >= 1

    Alf
    Attached Files Attached Files

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

    Re: Optimal Mix of Products

    BTW, there are many (infinite) solutions; you have four equations (nutrients) in eight unknowns (servings).

  5. #5
    Registered User
    Join Date
    04-18-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Optimal Mix of Products

    Quote Originally Posted by shg View Post
    BTW, there are many (infinite) solutions; you have four equations (nutrients) in eight unknowns (servings).
    Hi,

    Thanks for that, what if there was the added constraint of only whole servings can be used, and that not all foods have to be used?

    Would you mind posting a workbook?

    Thankyou

  6. #6
    Registered User
    Join Date
    04-18-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Optimal Mix of Products

    Quote Originally Posted by Alf View Post
    Using the sumproduct function you could set up a solver mode like this perhaps. You could also reach the target value without all the components. Just remove the constraint
    that B2:B9 values should be >= 1

    Alf
    Hi,

    I dont understand how you use the workbook, please can you elaborate?

    Also what if there was the added constraint of only whole servings can be used, and that not all foods have to be used?

    Thanks

  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: Optimal Mix of Products

    Modified for portions being integers.

    Some comments in file but + an image of solver setup. But the best way to view solver setup is to open the solver model.

    Alf
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    04-18-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Optimal Mix of Products

    Quote Originally Posted by Alf View Post
    Modified for portions being integers.

    Some comments in file but + an image of solver setup. But the best way to view solver setup is to open the solver model.

    Alf
    Hi,

    I just tried to replicated your setup myself, but it is giving me weird answers!!

    even though i have set things to int i get weird answers to about 5 decimal places.

    Have I missed something?


    Thanks in advance, this is exactly the solution I was looking for

    Thanks
    Attached Files Attached Files

  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: Optimal Mix of Products

    Not sure of your excel version. You say excel 2003 but uploaded file had extension xlsx and this means excel 2007 or higher.

    Strangely enough the default setting for excel 2010 is to ignore "Integer settings" so you could check the settings for solver in "Options". If box marked "Ignore integer setting is ticked, untick and test again.

    If this don't solve your problem upload the problem file and I'll have a look at it. Be sure to specify your excel version as this has an influence on how the model should be set up.

    Alf

  10. #10
    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: Optimal Mix of Products

    Duplicate message courtesy of Swedish rails, deleted.

    Missad that you already had uploaded a file. As my tab' s excel version don't include solver I'll have a look at the file when I arrive at my destination later today.

    Alf
    Last edited by Alf; 10-12-2018 at 02:17 AM.

  11. #11
    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: Optimal Mix of Products

    You have set the constraint wrong i.e. "$I$4:$L$<=$I$3:$L$3" where it should be "$I$4:$L$>=$I$3:$L$3" as per instruction the instruction you had written in note 3.

    There is also the possibility of limited the number of sevings of a specific kind. Running solver with the correct constraint according to not 3 will giv you this result

    free_s.jpg

    and adding an extra constraint say that range B3:B14 should be less or equal to 3 (i.e. B3:B14=<3) will give you this result

    bound_s.jpg

    but this gives you a higher total nutrient value than the previous solution. Perhaps the best approach would be to add the cost of each serving and solve for minimum cost and keeping nutrient value as a constraint.


    Alf
    Last edited by Alf; 10-12-2018 at 06:27 AM. Reason: better informatin

  12. #12
    Registered User
    Join Date
    04-18-2011
    Location
    Melbourne
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Optimal Mix of Products

    Quote Originally Posted by Alf View Post
    You have set the constraint wrong i.e. "$I$4:$L$<=$I$3:$L$3" where it should be "$I$4:$L$>=$I$3:$L$3" as per instruction the instruction you had written in note 3.

    There is also the possibility of limited the number of sevings of a specific kind. Running solver with the correct constraint according to not 3 will giv you this result

    Attachment 593808

    and adding an extra constraint say that range B3:B14 should be less or equal to 3 (i.e. B3:B14=<3) will give you this result

    Attachment 593810

    but this gives you a higher total nutrient value than the previous solution. Perhaps the best approach would be to add the cost of each serving and solve for minimum cost and keeping nutrient value as a constraint.


    Alf
    This is what I came up with, how would i add the cost?
    Attached Files Attached Files

  13. #13
    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: Optimal Mix of Products

    Layout looks good. I did correct the setting of the object cell from N5 to O2. I also change the instructions a bit referring to the correct cells and cell ranges. See image.

    You don't have to specify each cell in the constraint, as you have set a range for min and max value for the solver values you click add and then using the mouse mark the range and add max constraint, then mark the range and add min constraint. This make it less tedious to do and much more readable.

    food_solver.jpg

    how would i add the cost?
    The same way as you have specified "protein", "fat" and "carbs". Just add a column and fill in the values and then use "SUMPRODUCT" formula to calculate total. I don't think there should be set any constraint on costs or? I do think the daily intake of fat calories and carb is the important part.

    As a friend of mine use to say "If you wish to live cheaply and reach a 100 years of age you should only drink water and only eat Swedish crispbread. And even if you don't get that old if will feel like you did."

    How about weight? Will any of these daily food intakes weight more than a normal human can eat? If so perhaps then wight should be added as well with a constraint on max weight?

    There may also be cases where solver can't find a solution if constraints are to restrictive. Solver will then pop up a message box telling "Solver could not find a feasible solution" and add an explanation that solver can not find a point for witch all constraints are satisfied.

    Alf
    Last edited by Alf; 10-15-2018 at 08:57 AM.

+ 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. Optimal Code
    By iaman44 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2018, 03:24 PM
  2. Replies: 8
    Last Post: 07-01-2016, 02:07 AM
  3. Replies: 6
    Last Post: 03-05-2016, 02:42 PM
  4. Finding optimal sum
    By naeco in forum Excel General
    Replies: 3
    Last Post: 08-21-2014, 11:12 AM
  5. Formula to work out how many products among various products!
    By MissConfussed in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-02-2013, 02:24 PM
  6. Optimal
    By SynGC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2012, 10:17 AM
  7. Optimal material layout
    By Paulymon in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-25-2006, 05:40 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