+ Reply to Thread
Results 1 to 4 of 4

Solver - macro loop - want it faster

  1. #1
    Registered User
    Join Date
    04-26-2016
    Location
    Helsinki
    MS-Off Ver
    2016
    Posts
    4

    Solver - macro loop - want it faster

    Hey guys,

    I have macro which is looping solver on every row, code is :

    Please Login or Register  to view this content.
    The problem is, that I have approx. 70.000 rows and it took EXCEL like 20 mins to solve these 500 test rows. Is there any way how to do it faster? If possible, write the specific code please since I´m not very experienced with VBA (Actually I wouldn´t have even this without ALF ).

    Thank you so much!

  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: Solver - macro loop - want it faster

    So it's taking Solver a couple of seconds per row -- that doesn't seem unreasonable. The code isn't pretty, but it's adequate, and not the cause of the performance issue.

    You might look to see if you have a lot of volatile formulas that could be replaced by non-volatile equivalents, so they don't need needlessly recalculate as Solver iterates.
    Entia non sunt multiplicanda sine necessitate

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

    Re: Solver - macro loop - want it faster

    I will agree with shg, the code itself seems functional and completing within a reasonable time frame. If you need to speed this up, you might need to go a completely different direction.

    You say that you are not very experienced with VBA. Are you likewise inexperienced with spreadsheet programming in general? Other programming languages? How about the math/algebra associated with this problem?

    I note that your "objective function" (column T) is essentially a "least squares" type objective function -- suggesting to me that this problem might reduce to a simple "linear regression" that you can solve using the LINEST() function instead of Solver. The challenge here is exploring the function (J:N) to see if that function can be linearized to something in the form y=mx+b (it looks to me like it should -- you may need to spend some time with the algebra of the function). This will probably generate the most improvement because, on my machine, a 1000 LINEST() functions doing 1000 different regressions can calculate near instantaneously.

    One complication is the presence of the constraints for z and mu. In both of the examples you gave in the other thread, z wants to exceed the upper limit of 0.06, so Solver fixes z at 0.06. Do you have enough experience with the 70000 regressions you need to do to know how often z and mu will naturally fit within their constraints? If we can say that z will always be 0.06, we can simplify the problem to a single parameter, and perhaps speed it up that way. If not, you will at least need to figure out how to work those constraints into the regression. Off the top of my head, that means a) performing the regression, b) testing the constraints, c) if either parameter is out of bounds, perform the regression again constraining the offending parameter to its max/min value. Even performing the regression twice like that will probably be much faster than Solver and VBA.

    I haven't done the actual work (obviously), but that would be a quick overview of how I would try to approach this. If this works, you can bypass Solver and VBA, and program the whole problem using spreadsheet functions, and, I expect, compute these much faster than 500 in 20 minutes.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    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 - macro loop - want it faster

    If this is a one time job you could register at Frontline Systems and get a two weeks free testing periode of their most powerful models and they are really fast
    http://www.solver.com/
    or if you are a student you could try this link.
    http://www.solver.com/welcome-students

    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. VBA Macro for Solver Loop
    By vizbasic in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-24-2016, 09:13 AM
  2. [SOLVED] Solver Loop Macro Question
    By ngiesbrecht in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2015, 05:25 PM
  3. Macro Loop for Solver
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-28-2010, 09:42 AM
  4. Macro Loop for Solver
    By kchm_2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2010, 12:26 PM
  5. Macro to loop solver
    By NMason in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2010, 03:19 PM
  6. Solver macro with Loop
    By golfclubs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-31-2010, 10:35 AM
  7. Error message when using the Solver in a VBA macro loop
    By Mathieu Fournier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2005, 11:06 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