Anylogic: Source-block - Arrivals defined by stock of queue - anylogic

I am testing some production simulations in Anylogic.
Is it possible to link the arrival of multiple Agents (in my case: 20 pcs/arrival) to the actual stock of agents in a queue-block?
For example if there are less than 5 pcs of agents in queue then create a new arrival of 20 agents.
At the beginning of the Simulation the source-block should generate 20 agents. But in the course of the simulation the condition for new arrivals should change to the stock condition in the queue.
Thank you.

You can create an event for time=0 (or at the Main agent startup) such as source.inject(20);. You can have the queue block after this source. This would inject 20 agents into the queue. New arrivals can follow the same logic triggered by the conditions.
if (yourCondition==true){
source.inject(20);
}

Related

How to create an hourly arrival rate schedule based on route costs and agent choices?

I am building a model in Anylogic where customers order containers at terminals with a starting hourly rate (which differs per hour), which I load from database to a schedule and then let the customers order at every terminal with the rate of the schedule. When they have ordered, a truck will bring the container from terminal to customer.
However, I want to give each possible route for the trucks (directly or via a hub that is open at night) some costs (depends on time of day and travel time). Depending on these costs, the agents choose which route to take and (as the hub route is partly done at night) at what time to travel. The choices are:
Travel directly (arrive at the terminal at day time)
Travel via hub (arrive at the terminal at night time)
Thus, I want to let the hourly arrival rate schedule change based on the choices agents make after calculations. Does anybody know how to let the arrival rate schedule (different per hour) change depending on agent choices (based on route costs)?
Based on your answers, you don't really need to change the hourly order rate schedule, rather you need to choose when to deliver the containers to the customers. For this, place the arrived orders in a queue and process them with FIFO principle (or LIFO, whichever priority you assign them).
But if you insist on having different hourly order rates, you can use the following approach. So, if you want to distribute 10 arrivals during an hour, you can use exponential(10) as the interarrival distribution. Please see the screenshot below. I update the variable trucks1 dynamically during the simulation to have different number of arrivals for different hours.

Schedule the arrival of resources (ex. trucks) in Anylogic

I have a rackPick block where I am using Trucks as resources to pickup the agents. Is there any way to schedule the arrival of those resources? I want 2 trucks to arrive in a day. I didn't find any property in rackPick or resource Pool regarding scheduling.
Simply define your ResourcePool capacity to be driven "by schedule". Then, define a schedule to define your resources schedule:
There are several example models showing you how to do it, just search for "schedule" in the example models. And check the help, you can make this combination very powerful :)

Give agents different priorities in a queue

In my AnyLogic simulation model, I have two sources and going through two service blocks in a closed loop. At starting time I inject 1 50T Truck and 2 20T Trucks.
Descriptive image here:
Image of Model
At the second service block, "crusher1", I want the queue to always prioritize the agent "truck50ts" over "truck20ts". How can this be done?
Replace your Service block with Seize, Queue, Delay and Release blocks (same as a Service but more options for you).
in the Queue properties, set the queue priority to "agent comparison".
In the conditional code, write agent1 instanceof Truck_50tons ? true : false as below:
This assumes your 50t truck is an agent of a custom agent type called Truck_50tons (create those at the sources)

Priority based queue in Anylogic

I am using a priority based queue to pick agents from a pallet rack. Priority of agents can be 0 or 1. If there are 10 agents in palletRack, I want to pick all the agents having priority=1 first. My problem in the current flowchart is: Agents with priority=0 are pickup up before agents with priority=1. May be because the agents enter & leave the Queue block one by one, multiple agents aren't present in the Queue block at the same time so that they can be sorted. How to resolve this?
put a hold block between queueStorage2 and pickFromStorage1 and on the on enter action of queueStorage2, you check if all your agents are there, and if they are (with whatever condition you need to check to be sure everything is there) you unblock the hold with hold.unblock();

Create a database with an arrival time and access to it in the process flow

I would like to create a database with different arrival times that my forklifts pick the pallets (rack pick) to the certain times. How could I do this? Which process blocks could I use to access to a database with arrival times?
For example at 10am on May 20 45 pallets should pick out of the pallet rack. I tested it with a delay block and it works but only with different hours where the pallets get picked and not an specific date. The important thing is the date which I get from a database.
process
Probably the easiest way is to have your in-rack agents (after your RackStore block) sit in a Wait block, and be freed from there (using the Wait block's free function) --- to then carry on to a RackPick block --- via AnyLogic dynamic events whose timings come from a database table.
(Your model as-is will just have your agents immediately exiting the rack and going to the Sink because the Queue does not stop them leaving.)
Your model startup would loop through the rows in the table and create dynamic event instances with the appropriate timeouts (delays from model start), and with a dynamic event parameter which specified the number of pallets to pick (and thus the number to free from the Wait block).