How to access a unit of a resource pool for condition in function - anylogic

I am currently utilizing a hold block to restrict agent of type Patient passing to a seize block. Upstream in the model, Patient are assigned only 1 unit of Doctor that it will interact with downstream in the model every time is seizes Doctor (This is shown in photo one, in the Doctor resource pool).
The problem is that I would like to access this particular unit of Doctors in a function that I have, in order to check if that specific unit of Doctor is idle. Photo 2 is the function im using at the moment, and I would like to add this solution as the third condition in the if statements. It already checks if an Surgeon is available, but I need to add a check to see if their specific Doctor is available.
Photo 1
Photo 2

Why does agent.doctor not work? Or did you not try it?

I honestly didn't understand why you need to use a Hold block? After all, if the resource (Doctors) is busy, it will not be assigned to your agent (Patient).

The units of a pool have to be accessed using the functions specific to them, and not their resource pool. Here, to check if the desired doctor is available, the third condition would be
myPatient.doctor.isIdle() == true

Related

AnyLogic: Changing ResourcePool based on programmatically created schedule

I refer to a similar problem here.
I implemented a programmatically created schedule same as in the example model from AnyLogic Cloud. Then I added the suggested code in the capacity field.
Still, my problem is the following runtime error: "The parameter capacitySchedule cannot be changed dynamically". Does it just basically does not work with the resource pool compared to the Transporter Fleet presented in the similar problem? Unfortunately it does not work with a fake schedule either.
Here are some screenshots from my model. Thanks in advance.
To work with dynamic capacity of ResourcePool, I use a schedule shift by plan.
in some cases it meets the need.
The implementation of this is simple, in the schedule you give values 1,2,3 etc. They actually point to a position in the array.
Example of the schedule
And inside the ResourcePool you define it as follows:
Example of the ResourcePool by plane
In my example, at times when the schedule value is 4 the capacity of the ResourcePool is 0 and at other times it is as per my parameters.
Change the "Kapaziät definiert" to "By schedule".
Create a fake schedule object fakeSchedule (normally, not programmatically). Make sure it always returns 0 as the value.
Then, use this call for "Kapazität":
' mySchedule == null ? fakeSchedule : mySchedule`
This will tell the pool to use your schedule if it exists, else the fake one

AnyLogic: Select specific resource set based on condition

I have created a simple model in AnyLogic (see screenshot). Now I want to add a condition that selects one of the two resource sets in the service block. As an example the following scenario shall apply: If there are more than 5 parts in the queue, worker 3 and worker 4 should perform the service. If there are <= 5 parts in the queue, the service shall be performed by worker 1 and worker 2. This is only meant to be a simplified example. I am primarily interested in solving this problem using a condition. I have already tried different approaches, but without success. Does anyone have an idea how the Java code for this condition could look like?
First, you don't need the queue since the service block already has a queue... So For this particular example in your resource choice conditions you will do the following:
service.queueSize()>5 ? (worker3.containsUnit(unit) || worker4.containsUnit(unit))
:
(worker1.containsUnit(unit) || worker2.containsUnit(unit))
You can change service.queueSize() with queue.size() if you insist in using a queue. After that you need to be sure to recalculate the conditions when needed, for this particular example i think you only need to recalculate them on exit action of the service block:
self.recalculateResourceChoiceConditions();
One easy approach is to use Seize and Delay (and Release once done) blocks instead of Service. Before Seize, you can place your condition in a SelectOutputOut block. Like this:

AnyLogic if condition selectOutput

I'm modelling a manufacturing line in anylogic. Two agents are being processed and transported via the same conveyor. Both Agents need to spend diffent delay times in a service station. Because of that i added two parallel services and now i want to sort the agents arriving on the conveyor to their corrosponding service stations.
flowchart
Agent1 needs to go to service and Agent2 to serviceT.
I assigned parameters to both Agents, Agent1 has the boolean parameter "S" set to true and Agent2 the same parameter set to false.
To sort the Agents in the selectOutput block i typed in the if condition agent.S == true as seen in the next screenshot.
selectOutput
Anylogic prompts following error: "Unresolved compilation problem: S cannot be resolved or is not a field"
What can i do about this?
Thank you!
I would like to answer this question in two parts:
Instead of using a selectOutput to model different delay times for the SAME station, it would be more reasonable to have only ONE service representing that ONE station. To model different times, set the delay time equal to agent.S where S is the delay time for each agent.
Regardless of whether you choose what I suggested or what you are already using, you will still get the same error. The reason for this error is most likely that you haven't specified the agent type going through the select output properly. In fact, if you look at the image of the select output properties you shared, under the "Advanced" tab, the agent type is set as the default type Agent. Make sure to replace that by the agent type that contains the parameter S.

How do I connect agents by name in AnyLogic?

I am trying to connect different agent types by names. So, for example, I have a dataset where I have a list of patient names and their doctors name. I would first like to create two different populations of patients and doctors where each individual agent is assigned a name from the dataset. Then I need to create connections between the two different populations based on the corresponding connections in the data. Anyone know how to do this? Any help appreciated!
AT
Let's assume your doctor and patient agent populations are created, and the patient having a parameter called doctorName, and the doctor having a parameter called name. You have to figure out how to do this based on where you get the info from. I will also assume that all doctor names are different.
the doctor will have a link to agents object (from the agent palette) called patientLink as a collection of links and bidirectional, but as a single link on the patient side (called doctorLink on the patient side).
now you can use the following function to connect them:
for(Patient p : patients){
Doctor doctor=findFirst(doctors,d->d.name.equals(p.doctorName));
p.doctorLink.connectTo(doctor);
}
You should use the "Agent Link" object. This does exactly what you need.
In your case, you will need to write some code looping across your data and setup the links accordingly. Check the example models using AgentLink objects to learn about it and read in the help, there is a lot of stuff on it.
Here are just a few quick thoughts on this that I hope are helpful in your process:
1) If you want to keep doctors and patients linked, you can craft an agent as a doctor-patient dyad--this could make a lot of sense depending on what your research question is; or
2) If one doctor handles more than one patient, you could also consider forming an agent that is actually a network-type arrangement with the doctor as the central node--again, this depends what your research question is and what your data looks like; or
3) If you want to link doctors with patients based on some rule, consider using a discrete event approach by using a "Match" function from the "Process Modeling Library" palette.
Best wishes,
LCG

Anylogic: How to set Service delay time depending on the resourceSet being used

Basically I've got a Service which can work with two alternatives of ResourceSets. Let's say, the Service would optimally work with one Doctor and one Nurse, but it is also possible to work with only one Doctor if a Nurse isn't available.
Now, assuming the Doctor works slower without a Nurse, the Service's delay time must depend upon the resourceSet being employed at the moment (Doctor+Nurse or Doctor). Any idea how can I program this?
You should also have in mind that my model has various Services in parallel working in the same way, it's not just only one Service line.
Thanks!
You're using Services but, to me, using the combination of Seize, Delay and Release gives you more flexibility.
What I've done is set the resource choice according to the image bellow:
It is important to have the nurses prior to the doctors in the first set (for some reason anylogic would opt for using only the doctor if otherwise - even with a nurse available).
Than, I would write this code:
Which means that if the agent was only able to seize one resource it will take longer (15 is just a random value).
In the delay block, I would set the processing time to agent.processTime
The topology I'm using is this:
Obviously this is a workaround and will not work for every case. You can always change the conditions you verify. I couldn't find a way to check which resource set was picked by the seize operation. If you're in a hurry this will do the trick.
Hope that helps,
Luís