Using the same service block for different tasks in anylogic - anylogic

I am currently busy with a project at a hospital. I need to create a simulation model replicating the processes at the hospital. I have a problem with regards to one counter or service desk at the hospital. The staff member at the service desk needs to perform two different tasks, depending on the type of patient. How do I programme the service block to perform two different tasks?. For now,enter image description here I have split the block into two different blocks using the same staff member. Is there another way that I can go about this?

The staff member at the service desk needs to perform two different tasks, depending on the type of patient.
If the task only differs in duration, you can easily adjust the task duration by patient type in the Service delay property (assuming your patients are agents of types PatientType1 and PatientType2):
For more complex tasks, you can create a function that returns the duration and takes your requesting patient as an input argument, for example f_getDelayByPatient(MyPatientType patient)
Then, the service block can use that function in the "Delay time" code section to compute it for each arriving patient using f_getDelayByPatient(agent)

Related

AnyLogic - modeling large number of different ResourcePools

I would like to model a larger number of employees (about 30) as a resource pool. Each employee is given parameters before the model starts, which the simulation end user can enter manually. Each employee has different working hours (shift work, different on each day of the week), different duration of the shift and different tasks assigned to them.
My first thought was to model each employee individually as a resource with their own shift schedule. That would be easiest, but I bet there is a nicer solution - anyone have any ideas?
If your workers have different settings such as different shift hours, they will not belong to the same ResourcePool.
You must build an agent that contains a ResourcePool (so that you can use it as a resource) with its another parameters such as capacity etc.
In my opinion, the most correct thing is to build a Population of them. Each item in the population is an amount of workers with identical parameters.

Batching multiple agents based on location of agent

In my model I only want to batch agent which are at the same location. So my source block generates the agents according to a database to a specific node (which is sometimes different for agents), now I want the agents that occur at the same node to batch in sizes of 2 and the one that are left over need to be batched alone.
How can I model this, I know that I can use the selectoutput (which says for example if location=node1 use this output etc) option, but do I than have to add for example manually 100 outputs if I've 100 different locations where the agents start or is there a more simple solution for this problem?
Added later:
Or is there another way to model my idea:
So I'm simulating an hospital environment, where logistic employees (in this case the transporter) based on predefined times collects the thrash on certain areas for example the databaserow I show in the picture below:
At 9:50, the thrash at thrash collection point at LAB_Office_2_H_T_N can be collected by the logistic employee.
So in my model I create this 2 agents (which are 2 containers, last column) based on this time and seize a transporter to collect this thrash. Since a logistic employee is able to collect 2 thrash in one time I want to batch it and let the logistic employee collect 2 thrash containers at once.
After that he transports it to the thrash dump area and is released.
The colors changed after the added information. You can use pickup and dropoff blocks instead. You can define your node requirements in the condition cell. You can use local variables like container and agent to code whatever you want. Or use "Quantity (if available)" option. There you can programmatically define how many units will be picked up by using your own function.

In Anylogic How can I model truck that deliver orders to multiple clients

I'm creating a model based on the product delivery example provided by AnyLogic. In my own model, I want a truck to deliver multiple orders in one trip instead of one. My process diagram is shown below. Here, an order enters via the enter block and several orders are accumulated in the batch block. Every order has a specified destination. How do I model the truck such that it combines two orders and move to the nearest delivery location first and then the second etc?
The main problem is that I don't know the code that accesses the parameter "Delivery location" in each order.
enter image description here
enter image description here
Additional information:
The orders agents are generated and the delivery location is stored in a parameter called "client"
The batch block combines (lets say 2) orders into a batch of the type Order ( advanced settings set to population of agents)
The service block pulls a truck from the resource poule and send the batch of orders to the truck agent using send(batch.unit)
The truck agent stores the order/orders(?) in a variable called "order"
Then, a moveTo function should deliver the order to the first destination
What would be the code to move to the first, second etc., destination?
Here is the conceptual piece you are probably not aware of, and that should help you move in the right direction:
you can have "for loops" as part of your process flows. Below, you see an example where an agent keeps driving to places until it has no more parcels.
Obviously, the details of the blocks depend on your model but in each, you can access the truck's orders if you have them in your Truck agent type (which is needed, obviously).

How to use "wait" in anylogic?

I have a stock agent which is created in the end of my production line. My products are characterized by their model. I'm trying to create a logic to take out the products from this stock agent when they are to be delivered to the client. This delivery is controlled by an excel sheet and I'm taking the information through a SQL code. However, I was not able to find the right code to take out the products which are to be delivered. My agent population is called ProdutoStock and it's located in my main screen.
I have tried: Main.remove_ProdutoStock() but i couldn't figure out the arguments that i need for this function, since i have to take out of the agent a specific number of agents and also of a specific model.
So, I decided to create a wait block and use the free function to free the specific agents i wanted main.waiting_delivery.free() but i also can't figure out the necessary arguments for this function.
Would someone have any idea how I can take out of my agent/line the products that I need to deliver for my client (considering quality and also model)? This code is not being typed into my main screen.
the argument of the free method is the agent itself.
So you have to do main.waiting_delivery.free(yourAgent);
If you want to free the last agent that entered the wait block:
if(main.waiting_delivery.size()>0)
main.waiting_delivery.free(main.waiting_delivery.get(0));
If you want to free agents following a certain condition
List <YourAgent> theAgents=findAll(main.yourAgentPopulation,a->a.condition==true);
for(YourAgent a : theAgents){
main.waiting_delivery.free(a);
}

How to programmatically manage startWatch and stopWatch in an AnyLogic model

I'm building a model with AnyLogic using the Process Model Library (PML).
In my network I have 4 "source" elements that emits agents, they are all of the same type but with a different "category" string ID inside them (saved as a variable) to differentiate them; they are purchase order from different departments. I have also inserted blocks to measure the time the agents spend to exit from the assembler elements (you will see in the picture inside the red circles). This is the time that I will want to plot in a graph to show how fast they are.
After some test and reading the documentation I have see that when an agent pass under the start photocell (agent of any department) a timer is activated and the opposite when an agent (agent of any department) pass under the stop photocell the timer is stopped. Also in case of agent with different category IDs.
How can I synchronize the timers to measure time of object with the same category ID? I want that if the first source element "Category Nilo&Salmoni" produce an agent the stopWatch measure the time of this one and not of another one, emitted from another category, that reach the stopwatch first.