• 344 views | 9 messages Discussion: LEAP
    Topic: Montecarlo simulation in leapSubscribe | Previous | Next
  • Fredy Ferreira 9/24/2015

    766 Views

    how can I apply Montecarlo simulation in the scripts or have other way in leap? haven't example?
  • Taylor Binnington 9/24/2015
      Best Response

    2 Likes 765 Views

    Hi Fredy,

    Yes, this is possible - in fact, recent versions of LEAP have substantially reduced calculation time, which enables a modeler to achieve better statistics for Monte Carlo analysis by allowing a larger sampling of inputs.

    While we do not have a demonstration that we are prepared to release to the public, I can briefly describe the necessary steps to conduct your own Monte Carlo analysis. This hinges on LEAP's Application Programming Interface (API), which allows you to use a Windows scripting language to automate modeling tasks. One strategy would be to use the MS Excel plugin "Crystal Ball" (www.oracle.com/technetwork/middleware/crystalball/overview/index.html) as an interface for generating sampling sets of randomly selected parameters, and then use the API to pass these to LEAP and run the model. Alternatively you may build your own simple iterator instead of using Crystal Ball, which is a commercial product.

    In either case, some familiarity with a Windows scripting language will be required (such as VBScript, which you may use directly in LEAP by selecting Advanced: Edit Scripts). You will also need to invest some time to learn the basic functions of the API. I would recommend beginning at this help page:

    http://www.energycommunity.org/WebHelpPro/API/API.htm

    I hope this points you in the right direction.

    Taylor
  • Amrit Nakarmi 5/29/2017
      Best Response

    Dear Taylor
    I would like to know any development of using "Crystal Ball" with LEAP for uncertainty analysis of results of LEAP.

  • Taylor Binnington 6/5/2017
      Best Response

    Hi Amrit -

    This is not an active area of development for us, however, the LEAP API will facilitate iterative calculations with LEAP that pull data from MS Excel. You would then use Crystal Ball within Excel to generate new (random) inputs, and recalculate your model.

    Best,
    Taylor

  • Amrit Nakarmi 6/8/2017
      Best Response

    Hi, Taylor
    Thank you very much.We shall try the LEAP API for iterative calculations and develop simple uncertainty analysis on the results of emissions.
    Warm regards
    Amrit

  • Chibulu Luo 11/17/2017
      Best Response

    Hi Taylor,

    Thank you for this background. I would like to use Monte Carlo Simulation on my model and now learning to use VBScript (never programmed before!) and have downloaded Crystal Ball in Excel. Just a question: once I feed the model inputs to leap using the API, is it possible to have outputs/results fed back to excel for further statistical analysis of the results? If so, can you explain the general process?

    Thanks,
    Chibulu

  • Taylor Binnington 11/28/2017
      Best Response

    Hi Chibulu,

    Yes, this is possible. The general process would be:
    1. Use Crystal Ball to feed inputs into LEAP using the API.
    2. Calculate LEAP results using these inputs.
    3. Use the API to dump key results variables into an Excel workbook (or whichever output format you prefer).
    4. Return to Step 1, allowing Crystal Ball to select a different set of random inputs using your specified distribution.
    5. Once satisfied with the number of iterations, perform whatever analysis that you like on the outputs, accumulated from a large number of runs.
    Best,
    Taylor

  • Chibulu Luo 11/28/2017
      Best Response

    Great, thanks Taylor. Just to follow up -

    So currently my VBA code is as follows:

    Sub ChangingModelAssumptions()
    Set L = CreateObject("LEAP.LEAPApplication")
    L.ActiveArea = "Dar es Salaam and Lusaka"
    L.ActiveRegion = "Lusaka"
    L.ActiveView = Analysis
    L.ActiveScenario = "Current Accounts"
    'Changing electrification rate
    'L.Branch("Demand\Urban Households\Electrified Households").Variable("Activity Level").Expression = Sheets("InputDataDar").Range("B20").Value
    'Changing travel distance
    L.Branch("Key\Average Trip Distance").Variable("Activity Level").Expression = Sheets("InputDataDar").Range("B10").Value
    End Sub

    My question is: how do I print results from say 100 simulations to excel, using randomly generated inputs to cell B20 and B10 in my worksheet? I would also like to analyze results directly within Crystal Ball. I know Charles Heaps has mentioned previously that this is possible using a few lines of VBA code. Would you be able to share some example code to do this?

    Thank you!

  • Emily Ghosh 12/9/2017
      Best Response

    Dear Chibulu,

    An example script for exporting results can be found in the following thread (scroll to the very end to see the final code):


    Hope this helps!
    Emily