The delay1 can only contain agent.paint
. On the exit of the delay1, a new agent gets released from the delay.
But the released agent is not an agent.paint
instead it is an agent.repair
or agent.bwork
.
The delay2, delay4, and delay7 can contain agent.repair
and agent.bwork
but these delays are full, so now the agent is a problem, which is not supposed to happen.
Problem:
In delay1 only agent.paint
can go, after getting free from delay and In delay2, delay4 or delay7 only agent.repair
or agent.bwork
can go, if delay have them.
And that is not happening in the existing model.
There are several things that are incorrect in your model. First of all, please keep in mind that when you use the word agent in a flowchart block, it always refers to the agent contained in the current flowchart block from where you are calling it.
I assume, in the "on exit" function of delay1
you want to release an agent from delay
which has a parameter paint == true
. However, you wrote the function as
if (delay.size() > 0 && agent.paint == true) delay.stopDelay(delay.get(0));
The second condition agent.paint == true
refers to the current agent in delay1
flowchart block and not the agent in the delay
that you want to release. Additionally, you are calling stopDelay()
for the agent at position 0 in the delay block, regardless of whether this agent is the correct agent.
Instead, you need to iterate over all agents contained in the delay
flowchart block, find the agent that meets your condition and release this specific agent. Your code can look like this:
if (delay.size() > 0) {
Agent agentToRelease = null;
for (int i = 0; i++; i < delay.size() {
if (delay.get(i).paint == true) { // Note: The function delay.get(i) is very slow. See if you can use Collection instead.
agentToRelease = delay.get(i);
break;
}
}
if (agentToRelease != null) {
delay.stopDelay(agentToRelease);
}
}
The same goes for delay2
, delay4
and delay7
.
The "on enter" function of delay
is always called by the agent that is currently entering the delay. Because you check the condition for this specific agent here, you can directly call stopDelay()
for this agent in case the condition returns true. So the first part of your code should look like this (the same goes for the remaining conditions)
if (agent.paint == true && delay1.size() + moveTo.size() < 2) {
delay.stopDelay(agent);
} else if (...)