编写AnyLogic的if-then语句 – 系统动力学(库存 + 流动)

huangapple go评论68阅读模式
英文:

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

问题

The equation you've entered appears to have a syntax issue. Here's the corrected version:

if (Police < 7500)
  return 10;
else
  return 5;

Please try using this corrected syntax in the equation field of the flow properties, and it should resolve the issue you're encountering.

英文:

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&lt;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&#39;t parse expression for police_graduates - Flow: syntax error.
Please check expressions of this variable.
java.lang.RuntimeException: ERROR during variable generation:
Couldn&#39;t parse expression for police_graduates - Flow: syntax error.
Please check expressions of this variable.
	at model2.Main.&lt;init&gt;(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?

答案1

得分: 1

Police<7500 ? 10 : 5

英文:

Use conditional operators, you can only write 1 line of code in those fields:

Police&lt;7500 ? 10 : 5

答案2

得分: 1

以下是翻译好的内容:

你必须使用以下格式:

Police&lt;7500 ? 10 : 5

或者你可以使用返回双精度数值的函数:

function(Police)

并且该函数应该具有以下内容:

如果(Police&lt;7500) 返回 10.0;
否则返回 5.0;
英文:

you have to use the following format:

Police&lt;7500 ? 10 : 5

or you can use a function that returns a double

function(Police)

and the function would have the following

if(Police&lt;7500) return 10.0;
else return 5.0;

huangapple
  • 本文由 发表于 2023年6月13日 08:31:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76461036.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定