0

I have 3 identical suites represented by one agent type for productionSuite and I want to use loops to set the suites as idle and busy. The agent of productionOrder needs to be sent to only the idle rooms.

I have a parameter of assignedSuite in the ProductionOrder agent that equals a random suite that is picked in the source on main. I started to try loops in this source that relate to the statechart for ProductionSuite agent. I think I need a piece of code to defines the ProductionSuite as 0,1,2 and then checks with a loop if they have an ProductionOrder or not.

[Source]

(Original Code)

agent=ProductionOrder
agent.assignedSuite = productionSuite(uniform_discr(0,2));
deliver("Suite is Scheduled", agent.assignedSuite);

(new code)

Action:

`if ( productionSuite(0).inState(idle))
agent.assignedSuite = productionSuite(0);
agent.receive("Suite is Scheduled");

if ( productionSuite(1).inState(idle))
agent.assignedSuite = productionSuite(1);
agent.receive("Suite is Scheduled");

if ( productionSuite(2).inState(idle))
agent.assignedSuite = productionSuite(2);
agent.receive("Suite is Scheduled");`

The error I get is that idle cannot be resolved as a variable. Though I am not sure this is the best method to use. Could also use some direction on when to group the suites or if I should define them separately.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52

1 Answers1

0

that error is caused because your Source object doesn't know "idle". You need to rewrite it as follows:

if (productionSuite(0).inState(ProductionSuite.idle))

Assuming that your productionSuite agents are of type ProductionSuite (notice the capital letter). In short, you need to tell the code checking for the state to which agent type the state belongs so it knows where to look.

Hope this helps

Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • Thanks the code works but it keeps assigning each new production order to the same suite. In the ProductionSuite's statechart it starts at 'idle' state and waits for a message in the transition of "Suite is Scheduled" before it goes into the 'scheduled' state. I think now I am looking for a way to seize or turn off the specific suite that was assigned the order since moving into the 'scheduled' state doesn't seem to be enough. – Harrison Pressman Oct 16 '19 at 14:34
  • I just rewrote some of the message code and I got it to change states now. But when I hit the button to create a second new order the model gets a ton of errors and crashes. It also now changes the states for all 3 suites to ‘scheduled’ even though only one of them got the order. I think all the errors are from it trying to assign an order to a ‘scheduled’ state suite. new code: if(productionSuite(0).inState(ProductionSuite.idle)){agent.assignedSuite= productionSuite(0);deliver("Suite is Scheduled",agent.assignedSuite);} -then repeated for suites 1 and 2 – Harrison Pressman Oct 16 '19 at 15:28
  • Hi Harrison, this is not clear anymore. Suggest you ask a new, clear question showing the errors and making sure it is well structured (check https://stackoverflow.com/help/how-to-ask for support). Happy to help :-) – Benjamin Oct 16 '19 at 16:01
  • I made it into a new question in the link above. – Harrison Pressman Oct 16 '19 at 18:20