javaanylogicsystemdynamics

Writing an AnyLogic if-then statements - System Dynamics (stocks + flows)


New to AnyLogic and trying to create conditional, if-then equations within flow elements.

For example, I would like the flow of ‘police_graduates’ to be 10, on the condition that the stock of ‘Police’ is less than 7500; if the stock surpasses 7500, I would like the flow of ‘police_graduates’ to be 5.

I entered the following equation into the equation field of the flow properties:

if( Police<7500 )
  10
  else 
  5

See here

But the model does not run and I get the following error message:

Error during model creation:
ERROR during variable generation:
Couldn't parse expression for police_graduates - Flow: syntax error.
Please check expressions of this variable.
java.lang.RuntimeException: ERROR during variable generation:
Couldn't parse expression for police_graduates - Flow: syntax error.
Please check expressions of this variable.
    at model2.Main.<init>(Main.java:162)
    at model2.Simulation.createRoot(Simulation.java:158)
    at model2.Simulation.createRoot(Simulation.java:1)

Is there something wrong with the syntax in which I’ve written the equation?


Solution

  • you have to use the following format:

    Police<7500 ? 10 : 5
    

    or you can use a function that returns a double

    function(Police)
    

    and the function would have the following

    if(Police<7500) return 10.0;
    else return 5.0;