英文:
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<7500 )
10
else
5
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?
答案1
得分: 1
Police<7500 ? 10 : 5
英文:
Use conditional operators, you can only write 1 line of code in those fields:
Police<7500 ? 10 : 5
答案2
得分: 1
以下是翻译好的内容:
你必须使用以下格式:
Police<7500 ? 10 : 5
或者你可以使用返回双精度数值的函数:
function(Police)
并且该函数应该具有以下内容:
如果(Police<7500) 返回 10.0;
否则返回 5.0;
英文:
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;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论