Anylogic statechart with loops to set 3 suites as idle or scheduled

寵の児 提交于 2019-12-11 04:33:59

问题


(Main.java:935)__(NPE Error Image) I have 3 identical suites represented as an agent type ProductionOrder. A button on main sends a call to inject to the source on main. The source creates a ProductionOrder agent and has the following code in its On exit action that triggers a statechart transition in the ProductionSuite agent type. The statechart starts at 'idle' and has a message transition that connects to 'scheduled'. When I run the model and hit the button, the source receives a call to inject and sends the ProductionOrder to suite 2. I can see in the tab for suite 2 on the Run window that it does change from the 'idle' to 'scheduled' state when the source is activated. Although it also changes the states to 'scheduled' for suites 0 and 1 when neither of them got the order. When I hit the button again to inject a second ProductionOrder agent, the model gets a bunch of errors and cannot continue. I think it is still grouping the suites together somewhere and that the issue may not be coming from the source code anymore since it now sends the message. Or maybe I need another line of code to further separate the suites.

 sourceProductionOrder--->exitToSuite

 [sourceProductionOrder On Exit Action]

'if ( productionSuite(0).inState(ProductionSuite.idle))
{agent.assignedSuite = productionSuite(0);
deliver("Suite is Scheduled", agent.assignedSuite);}

if ( productionSuite(1).inState(ProductionSuite.idle))
{agent.assignedSuite = productionSuite(1);
deliver("Suite is Scheduled", agent.assignedSuite);}

if ( productionSuite(2).inState(ProductionSuite.idle))
{agent.assignedSuite = productionSuite(2);
deliver("Suite is Scheduled", agent.assignedSuite);}'

[exitToSuite On Exit Action]

'agent.assignedSuite.enterProductionOrder.take(agent);'

回答1:


is it possible that you simply should use a "if... else if ... else if" setup (instead of your current "if... if ... if")? Currently, all your if statements will be triggered because all prodSuites are in idle at the start. This would also explain why you get errors on the second try...

What I mean:

if ( productionSuite(0).inState(ProductionSuite.idle))
    {agent.assignedSuite = productionSuite(0);
    deliver("Suite is Scheduled", agent.assignedSuite);}

else if ( productionSuite(1).inState(ProductionSuite.idle))
    {agent.assignedSuite = productionSuite(1);
    deliver("Suite is Scheduled", agent.assignedSuite);}

else if ( productionSuite(2).inState(ProductionSuite.idle))
    {agent.assignedSuite = productionSuite(2);
    deliver("Suite is Scheduled", agent.assignedSuite);}


来源:https://stackoverflow.com/questions/58419394/anylogic-statechart-with-loops-to-set-3-suites-as-idle-or-scheduled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!