1

(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 Answers1

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);}
Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • It worked. Thank you. I am able to now create 3 orders that are sent to the idle rooms. When I hit the button for a fourth order I get all of the errors again. It looks like I need to change the code for the exitToSuite action. These are the first errors that show in the console while the rest have (unknown source); at production_2019_08_12.Main._exitToSuite_onExit_xjal(Main.java:935) at production_2019_08_12.Main.access$7(Main.java:933) at production_2019_08_12.Main$4.onExit(Main.java:567) at production_2019_08_12.Main$4.onExit(Main.java:1) – Harrison Pressman Oct 16 '19 at 19:17
  • What is the actual error message? Is it a NPE? A screenshot would be more helpful ;-) Very likely, your fourth button click pushes another agent into the Source object but then, it doesn't know where to go. I suspect some fundamental design problem here, tbh – Benjamin Oct 17 '19 at 05:00
  • Yes It was an NPE in the Console. I linked the image in the original question at the top. – Harrison Pressman Oct 17 '19 at 13:00
  • and what code is on line 935 of Main? (Open the console window in AnyLogic when the error is thrown and click on the blue link within all the red error text. Send a screen of where the NPE is actually occurring). – Benjamin Oct 17 '19 at 13:29
  • I linked the image next to the first one. It is the On exit action code of the exitToSuite Exit that is connected to the sourceProductionOrder on main. – Harrison Pressman Oct 17 '19 at 13:44
  • yeah, your model setup is not correct. You are trying to send the 4th agent to its assignedSuite but that is null, i.e. no assignedSuite was found for that agent (because they were all busy with the first three). You need to account for that possibility. Many ways to do it but I suggest you think how to do it elegantly. – Benjamin Oct 17 '19 at 18:38