+ Reply to Thread
Results 1 to 5 of 5

calling Solver .dll through VBA

Hybrid View

bored calling Solver .dll through... 05-18-2013, 11:57 PM
Alf Re: calling Solver .dll... 05-19-2013, 12:21 AM
bored Re: calling Solver .dll... 05-19-2013, 01:47 AM
Alf Re: calling Solver .dll... 05-19-2013, 06:06 AM
bored Re: calling Solver .dll... 05-19-2013, 11:22 PM
  1. #1
    Registered User
    Join Date
    01-27-2010
    Location
    prague
    MS-Off Ver
    Excel 2010
    Posts
    52

    calling Solver .dll through VBA

    Hi,

    I have been running Solver with this kind of code:

    SolverOk SetCell:="$BM$3", MaxMinVal:=2, ValueOf:=0, ByChange:="$R$3:$R$9", _
            Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverSolve UserFinish:=True
    Before I run this VBA, I will make the first Solver run manually, so that the conditions and constraints are properly set. This works fine, with the only problem being that it is very slow when I loop the VBA over, say, a few thousand times. This is understandable, because each manual run of the Solver usually takes about 1-2 seconds anyway.

    The question that I would like to ask is, if I call the Solver .dll directly (which I suppose will bypass many GUI steps), will it make the program much faster? If it does, can someone please show me how to edit the above code to call the .dll? I am not familiar with using .dll files at all.

    Thanks!

  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,784

    Re: calling Solver .dll through VBA

    Cross-posting http://www.mrexcel.com/forum/excel-q...lications.html

    Alf

  3. #3
    Registered User
    Join Date
    01-27-2010
    Location
    prague
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: calling Solver .dll through VBA

    Hi Alf,

    Yes, I posted the same topic at Mr Excel too. My bad, I wasn't aware that these 2 forums are linked. I am repeating my post here because that post in Mr Excel failed to attract any response.

    Thanks.

  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,784

    Re: calling Solver .dll through VBA

    Hi

    Cross-posting is no problem if you just add a link to the other forum where you also posted your question.

    I wasn't aware that these 2 forums are linked
    They are not but quite a number of forum members are rather active in a number of other excel forums as they have this strange craving for solving excel problems.

    Re your problem I have not seen any info about calling solver from the solver.dll file and succeeding. Why do you need to run solver in a ”normal” mode first before reverting to vba?

    Just record a macro with all settings and set a reference to solver in the vba window i.e. Tools -> References and click box for solver.

    I recommend starting the loop with the SolverReset command to avoid build up of the constraint.

    I assume you have tried running the “Simplex LP” as this is the fastest solver model.

    You could also upload a sample file then hopefully some member may have some suggestion on how to speed up the process.

    I’ve read somewhere that Excel do have problems with multitasking Excel-> Options -> Advanced find heading “Formulas” -> “Multi-thread calculations

    http://www.mrexcel.com/forum/excel-q...ore-cores.html

    Alf
    Last edited by Alf; 05-19-2013 at 06:12 AM.

  5. #5
    Registered User
    Join Date
    01-27-2010
    Location
    prague
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: calling Solver .dll through VBA

    Hi,

    The reason I do a manual run of Solver before I run the VBA is so that I do not need to reset the Solver for every iteration. So, say I have 1000 iterations, I just need to reuse the same constraints over and over again. If I were to do a SolverReset before each run, it would take even more time. Of course, I re-initialise my parameters to some fixed values before I run each Solver, so I think there is no constrain-build up that you mention. And I cannot use Simplex because my problem is nonlinear.

    Currently I do not have a sample file to upload -- the files that I am working with were not created by me, and they are huge (>10MB per file). Basically, there is this super long equation (with power laws, exponentials, trigonometry, and integration steps somewhere in between, etc) that needs a lot of prior steps to arrive at, and there are a handful of parameters that need to be optimized so that the difference between this model and some measured values are as similar as possible. As you can imagine, each run of the Solver involves easily tens of thousands of calculations. I am just hoping to cut down the run time by directly calling the dll rather then invoking the GUI-based Solver.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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