Using Script element to find max/min of a function

Answered

Comments

7 comments

  • Avatar
    Jason

    Robin,

    Thanks for writing in our forum!

    In GoldSim, you can use built-in functions "min()" and "max()" take 1 or more arguments and returns the min or max. But in GoldSim, you cannot define a function as an object and pass that as an argument. Can you tell me more about why you need to pass a function in this way?

    -Jason

    0
    Comment actions Permalink
  • Avatar
    Robin MacDonald

    Hi Jason, this model is simulating the operations of an industrial plant. We have an efficiency function which varies with operating capacity, and an element representing plant production is being multiplied by the efficiency at that particular point along the curve. It is important for us to understand where the point of maximum efficiency lies on that curve; currently, this point is calculated by hand and inputted into the model as a data input. It would be preferable for the model to calculate this point so that a hand calculation isn't necessary. Is this something that GoldSim is able to do?

    0
    Comment actions Permalink
  • Avatar
    Jason

    What if you used GoldSim's built-in optimization routine to let it find the maximum for you? 

     

    0
    Comment actions Permalink
  • Avatar
    Robin MacDonald

    The optimization feature definitely looks like a good option! The issue is that we need to generate the system's production as a time series using the result of the optimization (within the same model). I'm guessing we need to do this using a sub-model or looping container that optimizes this particular function within the larger model, so that the result can be used elsewhere in the model.

    Alternatively, I'm wondering if the script element will be a clearer, simpler way to do this. What do you think is the best approach?

    0
    Comment actions Permalink
  • Avatar
    Jason

    The best approach I can think of is to use a Script element with a FOR loop that solves the problem iteratively if you can. That will be the cleanest, simplest, and easiest way to read and understand it. But if it requires optimization that includes the entire model or a large portion of the model to be included within the calculation of the optimization's objective function, then you will need to put the whole model into a submodel that is set to run as an Optimization on each time step of the main model.

    Here is one of our many Script examples that employs a loop to solve a problem: Root Finder Script – GoldSim Help Center

    Does that help?

    0
    Comment actions Permalink
  • Avatar
    Robin MacDonald

    Hi Jason, we decided the simplest approach is to determine the maximum of the function separately from the model and input this as a data element into GoldSim, so as to not bog down the simulation with an iterative submodel. Thanks so much for your help!

    0
    Comment actions Permalink
  • Avatar
    Jason

    Robin,

    I'm glad you found a solution that works for you. Another approach if you have a submodel is to trigger the submodel to execute only when you tell it to. This way, it will hold any outputs from it's most recent run. Then, you can run the main model while the submodel is dormant. 

    -Jason

    0
    Comment actions Permalink

Please sign in to leave a comment.