+ Reply to Thread
Results 1 to 11 of 11

Solver not meeting constraints when it claims to do so

  1. #1
    Registered User
    Join Date
    04-02-2004
    Posts
    16

    Solver not meeting constraints when it claims to do so

    Hi,

    I am using Excel's solver to solve the equations of motion for a two degree of freedom system on a row-wise basis using a simple VBA loop. I've done this several times for other models and never run into this problem before.

    The problem is that the Solver claims to have found a solution for each row that satisfies the objective and the single constraint. However, it hasn't.

    The two equations of motion are written so that they should equal 0 at every time step so the objective and constraint are similar: set a cell value equal to 0.

    The Solver options are default: precision is 0.000001, convergence is 0.0001 and the engine is GRG Nonlinear.

    Some rows solve perfectly, with the cell values stopping at very small numbers - typically with exponents of -5 to -10. Often, however, they stop with values that are 0.X or 0.0X, which clearly does not satisfy the required precision.

    Pausing at each iteration shows that only 2-3 iterations are being used before it claims to have found a solution. Setting the max time to 20 (seconds?) and iterations to 999 has no effect.

    Here's the weird thing: I tend to set the two variables that it is adjusting to 0 before each run whilst I investigate the problem. However, if I run the loop to get a first set of answers (many of which are poor as described above) and then run the loop again using the first results as start points then it finds good solutions!

    To try and combat this, I put in a few extra lines of code that copy the result from the current line into the next line so that each line's start point is not 0 but the same as the result from the line before. This didn't work either and still requires a second run-through. I then thought about using an extrapolated value based on the previous two results but then thought I'm slowly writing my own solver!

    I have tinkered with every solver option but to no avail. The main problem for my is why is it ignoring the requested precision?

    I also tried setting upper and lower values instead of 'equal to 0' but it ignored those constraints as well. I can't interpret the reports unfortunately but did notice that when a constraint was met it was labelled as non-binding and when not met it was labelled binding. Could that be a clue?

    I'd be grateful for any help.

    Thanks,

    Simon.

  2. #2
    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 not meeting constraints when it claims to do so

    Perhaps you could upload the file with your solver model (removing sensitive first) so that forum members may have a go at trying to solve this problem.

    Alf

  3. #3
    Registered User
    Join Date
    04-02-2004
    Posts
    16

    Re: Solver not meeting constraints when it claims to do so

    Hi Alf,

    I don't seem to be able to add attachments unfortunately. If I press the attachments button then I get a small blank pop up and the words (in Chrome, anyway) JavaScript voids: attachments.

    I've tried IE and the same thing happens.

    Sorry.

  4. #4
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Solver not meeting constraints when it claims to do so

    Go Advanced -> Manage Attachments -> Upload

  5. #5
    Registered User
    Join Date
    04-02-2004
    Posts
    16

    Re: Solver not meeting constraints when it claims to do so

    And where is Advanced??

  6. #6
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Solver not meeting constraints when it claims to do so

    Button next to Post Quick Reply

  7. #7
    Registered User
    Join Date
    04-02-2004
    Posts
    16

    Re: Solver not meeting constraints when it claims to do so

    I've uploaded the file but can't see any evidence of that in this thread. I'll post this message and see if it works.

    Simon.

  8. #8
    Registered User
    Join Date
    04-02-2004
    Posts
    16

    Re: Solver not meeting constraints when it claims to do so

    Perhaps the file was too large so I'll try again with a reduced version.

    If you press the button on the sheet it will run a simple solver loop over a few of the rows, some of which are known to produce a result that does not meet the constraints.

    Thanks,

    Simon.
    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: Solver not meeting constraints when it claims to do so

    I had a go at your problem but did not find a solution to you result. Could be that this is due to the way that computers calculate numbers i.e. max 15 decimals.

    I changed your macro a bit and did a run with excel 2010, your file is an xls file but in the macro you have a reference to "Engine:1" and these "Engine" concept was first introduced in Excel 2010.

    Running you macro three times with a bit tighter convergence (0.0000001 as opposed to your setting 0.0001) gave this result
    solver_1.jpg
    compared to run your macro three times with your original settings
    solver_2.jpg
    and as you can see there is not much of a difference.

    Running out of ideas I set up solver to use the Evolutionary engine. Must confess I'm not that familiar with this engine as well as the mathematics behind it. I've set a max time of 30 seconds and when it
    stops telling you it has reach max time setting you are given a choice of clicking the stop button to processes the next line or continue to work on the present problem. If the result is not improved after some seconds solver jumps down to next line.

    Using the Evolutionary engine in this case takes time as you must be present to provide an input for every line of the problem. For the GRG Nonlinear model result could be improved by the second run and the third run gave no improvement as far as I could see.

    The "Application.ScreenUpdating" command do not have any effect in a solver run by the way aside from being a good habit.

    Macro for running the Evolutionary engine:

    Please Login or Register  to view this content.
    and the result using the Evolutionary engine is perhaps a tad better than using the GRG Nonlinear but GRG seems a lot faster.

    solver_3.jpg

    Alf

    Ps If you do have problems seeing the results right click on the images and select "Open in a new tab"
    Last edited by Alf; 05-14-2018 at 10:47 AM.

  10. #10
    Registered User
    Join Date
    04-02-2004
    Posts
    16

    Re: Solver not meeting constraints when it claims to do so

    Thanks for your work Alf.

    I managed to find and solve the problem - you touched upon it when referring to decimal places. To diagnose the problem I ran the macro once on a dozen rows or so and then only ran it for a second time on a single row. This ruled out influence between rows and showed me that the difference between the results from each of the two runs were solution values of XE-11!

    I initially considered changing the parameter units to use millimetres instead of metres and millrad instead of rad to avoid such small numbers but before that I just set the precision to 1E-13. That worked perfectly and hasn't slowed the solver to any significant degree.

    So, in conclusion, I think it is misleading for the solver help pages to state that the precision controls the degree to which the constraint is satisfied as that clearly isn't true. However, the precision does control the degree to which the variable cells are changed in order to satisfy the constraints.

    Regards,

    Simon.

  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: Solver not meeting constraints when it claims to do so

    Hi Simon
    You are welcome and thanks for feedback.

    So the precision controls the degree to which the variable cells are changed in order to satisfy the constraints as long as the constraints are greater than the smallest number that the computer will work with?

    Good to know as well as knowing that you have solved your problem.

    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. [SOLVED] Excel Solver VBA - Solver Violating Constraints
    By lespaul00 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-19-2015, 04:00 PM
  2. [SOLVED] Calculate number of claims and claims paid out per policy year
    By Even in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 10-21-2014, 08:15 AM
  3. Solver constraints help
    By Rogeo in forum Excel General
    Replies: 0
    Last Post: 01-11-2014, 04:56 PM
  4. [SOLVED] using INDEX and IF to output value meeting multiple min/max range constraints
    By myersac in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-30-2013, 04:13 PM
  5. How to use Solver constraints : dif
    By alee001 in forum Excel General
    Replies: 0
    Last Post: 06-06-2012, 02:36 PM
  6. [SOLVED] Excel SOLVER problem, claims it is solved but retains original values. Example given.
    By ad9051 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-25-2012, 04:18 PM
  7. Solver constraints shall be OR // Solver target cell
    By Cunner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2009, 04:28 AM

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