Anylogic: StopDelay() is not working due to which agent is not able to leave the Delay block - simulation

StopDelay() is not working due to which agent is not able to leave the Delay3 block.

of course your stopDelay won't work because no agent ever reaches delay4
delay3 REQUIRES a call for stopDelay, but there's nothing doing that since the only time stopDelay is called, is further in the flow.
What you need to do instead is on the on enter action of the delay3:
if(delay4.size()==0){
delay3.stopDelay(agent);
}
and on the on exit of the delay4 you do:
if(delay3.size()>0){
delay3.stopDelay(delay3.get(0));
}

Related

AnyLogic - inheritance of properties in batch block

I want to store process times in my model for each agent of type Box. For this purpose I have created a Java class ProcessData.
My problem is that I always get NullPointerExceptions. I don't know if it's because of my code or the functionality of the batch block.
When the wait block reaches a certain size, all agents of type Box are routed to the batch block. The batch agent then waits in the seize block for staff member. If the agent is then seized, each agent of type Box contained in the batch agent should then get a start processing time. This is my code at enter of the delay block: box.getProcessData().add(new ProcessData(date(), duration()));. Using a constructor, I add the start time and duration as new variables to a new ProcessData entry.
To determine the end time of each Box agent I have the following code at unbatch block entry: box.getProcessData().getLast().setEnd(date());
Since I have a NullPointerException I can't tell exactly where it came from. My guess is that I have a bug with addressing the code: should I use agent. (from batch) or box. (name of original agent before batch)? Or is it not possible to give the batch agent properties that are inherited by the box agent?
First error is at unbatch, so the second code from above and second error is the following public void onExit( Box batch, Box agent ) { _unbatch_onExit_xjal( this, batch, agent ); }.
Following the screenshot of my error:
The problem you have with this model first,is that you are seizing a resource for the batch without releasing that resource... you need to release before unbatch
your error nevertheless is related to some code that you wrote in the on exit action of the unbatch block that you are unfortunately not telling us
But to discover what is null, check with a traceln() the value of the variables that are present in the on exit section of the unbatch in order to print on the screen what is null

Anylogic detect that agent stopped on conveyor

is there any easy way to detect that agent stopped on a roller conveyor because there are other agents ahead? I tried to use dynamic variable and conditional event but it is consuming too much performence. I donĀ“t want to go for dynamically checking condition (with cyclic event) because I have some bad experience with it.
Thanks!
Try this:
Create a LinkedList<YourAgentType> agentsOnConveyor.
Whenever an agent enters the conveyor, call agentsOnConveyor.addLast(agent). When it leaves, call agentsOnConveyor.removeFirst(agent).
Now you have a linked representation of the agents on the conveyor.
Last, you use the "on stopped" field in the conveyor and pass the message "upstream" through the linked list, i.e. use a for-loop from the first to the last entry and send them a msg "conveyor stopped".
You may still need to check if the individual agent is moving itself or has also stopped, but it might put you on a working path

How to set agents hight in delay block?

By seizeTransporter block my AGV seizes an agent called "Sitz" and transports it via Move by Transporter block to a Delay Block.
When AGV enters the delay block the transported agent "Sitz" is changing its cargo location to 0.
I tried to fix that issue with creating an parameter on main called p_assemblyHight with default value 1.0 and the following code in Actions section of the delay Block: agent.setHight(p_assemblyHight, METER);
Anyway this action will not execute.
What can I do so that my transported product (called "Sitz") stays on the agv and not dropping in delay block?
Check the two screenshots for better understanding.
Thank you a lot!
The setHeight method does not change the z-component, but the height of an agent presentation. Irrelevant for you.
You need to access your Sitz in the delay block and change its z-component.
In the Delay block call:
agent.setXYZ(agent.getX(), agent.getY(), 10);
The last argument is the Z component, adjust as needed. The first 2 just make sure the XY components are not changed

Start Loading with Enter Block

I would like to start loading my truck when the truck arrives at the dock. How could I activate the enter block startloading? When it comes to the block pickupOrders, the truck doesn't load my pallets because I don't know how to activate the block enter "startloading". The source block is part of the agent "truck", the enter block is part of the agent "pallet".
process_logic_simulation
process
As per the Help article, you need to fill the queue for the Pickup block yourself.
Your Enter block cannot create agents that fill up your queue (see the help on what an Enter block does). Replace it with a Source block to actually create agents directly.
If, however, your agents for the queue already exist, you can push them into your Enter block using an Exit block from where they live. In the Exit block "on Exit" code, write myEnterBlock.take(agent) to push them in.
Also, many example models showing you Enter/Exit setup in more detail.

Trouble with agent state chart

I'm trying to create an agent statechart where a transition should happen every day at 4 pm (except weekends).
I have already tried:
1. a conditional transition (condition: getHourOfDay() == 16)
2: A timeout transition that will "reinsert" my agent into the chart every 1 s and check if time = 16.
My code is still not running, does anyone have any idea how to solve it?
This is my statechart view. Customer is a single resource that is supposed to "get" the products out of my stock everyday at 4pm. It is supposed to happen in the "Active" state.
I have set a timeout transition (from Active-Active) that runs every 1s.
Inside my "Active" state in the "entrance action" i wrote my code to check if it is 4 pm and run my action if so.
I thought since i set a timeout transition it would check my condition every 1s, but apparently it is not working.
Your agent does not enter the Active state via an internal transition.
Redraw the transition to actually go out of the Active state and then enter it again as below:
Don't use condition-based transitions, for performance reasons. In your case, it also never triggers because it is only evaluated when something happens in the model. Incidentally, that is not the case at 4pm.
re your timeout approach: Why would you "reinsert" your agent into its own statechart? Not sure I understand...
Why not set up a schedule or event with your recurrence requirement and make it send a message to the statechart: stateChart.fireEvent("trigger!");. In your statechart, add a message-based transition that waits for this message. This will work.
Be careful to understand the difference between the Statechart.fireEvent() and the Statechart.receiveMessage() functions, though.
PS: and agree with Felipe: please start using SOF the way it is meant, i.e. also mark replies as solved. It helps us but also future users to quickly find solutions :-) cheers