+ Reply to Thread
Results 1 to 8 of 8

Solver with intermediate formula steps not working

  1. #1
    Registered User
    Join Date
    08-23-2023
    Location
    France
    MS-Off Ver
    Version 2302
    Posts
    2

    Solver with intermediate formula steps not working

    Hi all
    I couldn't find a post already which explained this exact situation so posting here.
    I am trying to use Solver but it is not working - it is not adjusting the input variable.
    Spreadsheet attached including screenshot of my solver parameters. I am trying to maximise cell F5 by changing cell D5.
    The 'correct' answer is D5 should be changed to any value below 1 (I am happy with any correct answer and have no constraints - integers, non-integers, negative numbers etc - 0.9 or 0 or -0.1 etc).
    But when I run it Solver says it has an answer but the input doesn't variable doesn't change from 2 (which I set it at by default) and so does not maximise F5.
    Appreciate any help and let me know if more detail required.
    Thanks
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Solver with intermediate formula steps not working

    Your intermediate functions (and, as a result, your final objective function) are "step" functions -- they stay constant at 0 or 1 until the value in D4 crosses over the value in column B. As noted in the solving method description, GRG non-linear really does not like step functions or other non-smooth functions.

    You could try an evolutionary engine and see if that helps. Reading between the lines, the sample you provide seems to be a greatly simplified representation of your real problem. Assuming your real problem is also a step function, an evolutionary engine may be able to find a solution.

    You also might consider how you can change the calculation procedure to see if you can make a smooth objective function for solver to work with.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  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: Solver with intermediate formula steps not working

    MrShorty is right. Using the Evolutionary solver engine will give you a solution but ....

    Setting up the Evolutionary solver I first unticked the box "Required bounds on variables" and then I did a run with D5 = 6. Solder gave the answer D5 = 0 and F4 = 2.
    I did make two more runs with D5 = 6 and got the same answer both times D5 = 0 and F4 = 2.

    I then ticked the box "Required bounds on variables" and added an upper limit on D5 <= 4 as well as a lower limit for D5 >= 0

    Ist run with a starting value D5 = 6 gave a result of D5 = 0.147622904 and F5 = 2
    2nd run with a starting value D5 = 6 gave a result of D5 = 0.763249001 and F5 = 2
    3de run with a starting value D5 = 6 gave a result of D5 = 0.289896832 and F5 = 2

    This I can't explain unless your "equation" is undecided i.e. all values of D5 >= 0 and less than 1 will give you a max value of F5 = 2. Hopefully MrShorty can give a better explanation.

    Alf

  4. #4
    Registered User
    Join Date
    08-23-2023
    Location
    France
    MS-Off Ver
    Version 2302
    Posts
    2

    Re: Solver with intermediate formula steps not working

    Thanks both. Evolutionary solver is the right way to go and getting me there!

    And how can I put a constraint so the solver only tests increments - say to 2 decimal places? So the solution to the variable Solver will select, say, 0.01 but not 0.010001.
    Again struggling to work out on my own or find on another post.

    MrShorty - you're correct, I have a more complex actual dataset.
    On the step functions, I don't know of a way I could redesign them to be objective functions - not overly sure what these are but I will certainly need if statements and not sure if there are workarounds for these.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Solver with intermediate formula steps not working

    tl:dr -- At this point, I would say that, if simply switching to an evolutionary engine is enough to get Solver to reliably find a solution for you, then leave what isn't broken alone. Assuming Solver is reliably finding a solution, it may be easy enough to round Solver's solution to the nearest 0.01 after Solver finds its solution.

    continue reading for further thoughts on the problem:

    Without knowing more about your actual computation scheme and how the simplified (oversimplified?) example represents the computation scheme, it is difficult to talk about better ways to formulate the problem.

    Looking at the problem in the sample sheet, it reduces down to "find a number that is both greater than 3 and greater than 1." Obviously, the trivially easy answer without using Solver is, "any number greater than 3." I could easily put =MAX(B9:B10)+0.01 into E4 and make a comment that anything larger than E4 is a solution. If I wanted to get Solver to solve this problem, I would probably set Solver up to Set D4 to a minimum by changing D4 subject to the constraints that D4>=3 and D4>=1. After Solver runs and returns 3 as the result, I add a small amount to D4 to get my final answer, since I don't actually want a result exactly equal to 3 (Maybe in E4, enter =D4+0.01). But, obviously, I don't know how either of those strategies would translate into your actual calculation scheme.

    As for the "limit solutions to 2 decimal places" constraint. I usually prefer not to impose that kind of constraint on Solver if at all possible. I feel like it is usually easier to let Solver find a solution without that kind of constraint, then round Solver's result after Solver has finished running. Something like =ROUND(D4,0.01) or =ROUNDUP(D4,0.01) in E4. Solver finds the unconstrained optimum value in D4, then I can easily round that to the desired precision after Solver runs. But that kind of strategy doesn't always work for some problems, so you have to know enough about your actual problem to decide whether that kind of strategy works or not. When it doesn't work, the usual strategy is to move the by changing cell to C4, constrain C4 to be an integer, then have D4 be =C4/100. This approach adds more discontinuities to the function, which often makes it harder for Solver to find a solution, so I don't like to do it this way unless it is necessary.

  6. #6
    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: Solver with intermediate formula steps not working

    Looking at the "Static" value in B9 (3)and B10 (1) you formulas i.e. "D9" "IF(B9>$D$5;1;0)" and "D10" "=IF(B10>$D$5;1;0)" this means that for every value of D5 From 0 to 0,99999 will put the value of 1 in both D9 and D10 so the maximum value for F5 will be 2.

    As soon as D5 reaches the value of 1 the value in D10 changes to 0 as B9 is now not grater than D5 but the D9 still stays with a value of 1 up 2.9999. As soon as D5 reaches a value of 3 then the D9 value will also turn to 0.

    If you like to test this you could use a macro like this to see the values of the variables to change (H column) and the result of the cell to maximize in the I column.

    Please Login or Register  to view this content.
    Alf

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

    Re: Solver with intermediate formula steps not working

    Quote Originally Posted by richybee View Post
    MrShorty - you're correct, I have a more complex actual dataset.
    Can you share more details about both the dataset and what precisely you are trying to achieve? (context and objective)

    We don't need personal informations, just a small, representative sample. This seems to be an example of an XY problem.

    With the setup in your file, the problem is trivial: since the intermediate formula step in column D is an IF condition that returns either 1 or 0, and you are maximizing their sum in F5, we can just look for the smallest number x in column B and choose x-eps, for instance

    =MIN(B9:B10)-0,01

    and @Alf has already offered a VBA solution to check it. (Hi Alf!)

    On the step functions, I don't know of a way I could redesign them to be objective functions - not overly sure what these are but I will certainly need if statements and not sure if there are workarounds for these.
    There exist workarounds, we need a deeper understanding of your problem to help you, assuming that Solver is really required.

    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.

  8. #8
    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: Solver with intermediate formula steps not working

    Seems to be a problem with my suggested macro. Testing a range of values going from 2.6 to 3.1 the value 2.84 was in reality 2,83999999999999 so when the macro reached 3.0 it shows 3.0 but the real value was 2,999999999999 and the corresponding F5 was 1 where it should have been 0 for a proper value of 3.0.

    To fix this replace lines
    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    Alf

+ 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. Optimization - running VBA subroutine at intermediate steps
    By williamB2023 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-14-2022, 09:58 AM
  2. How to sum using a formula for each row without intermediate subtotal
    By Renlid in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-05-2018, 07:26 PM
  3. problem with how if insert copy paste working steps of macros when using VBA code
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2013, 04:23 AM
  4. [SOLVED] Explaining the steps involved in the MACRO working
    By PRADEEPB270 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-08-2012, 02:51 AM
  5. Replies: 10
    Last Post: 12-29-2011, 01:23 PM
  6. Intermediate Excel Formula Help
    By BigChris10 in forum Excel General
    Replies: 3
    Last Post: 01-12-2011, 05:27 PM
  7. Is a single formula better than intermediate calculations?
    By David Huang in forum Excel General
    Replies: 3
    Last Post: 02-10-2010, 10:23 AM

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