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
Related
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
Using previous pick-up blocks, i have an container agent with two different agent types inside (Myagent and Myagent1). I want to insert two different drop-off blocks,the first for Myagent and the second for Myagent1. the problem is which element type i should choose for the drop-off block. For example, if i chose Myagent, it would give me error because of Myagent1:
If i chose Agent then:
Both the agent have a parameter named cc.
(I read other answers on the forum like Drop-off specific custom agents using drop-off block in anylogic, but i still have this error).
thanks for the help.
The best option here is to create a parent agent type that has 'cc' property and have the two types of agents inherit from it as described here. Also as a side note, you should probably take care to name the agents and properties with something meaningful as it will help to understand the model and explain it should you need to ask for help in the future.
I've a problem with a simulation in anylogic.
I have an item (agent) that must be processed by a resource, the result of this service block is the starting object and two different documents which are processed in two separate offices and which at the end of the flow will have to be linked to the article in question.
I can't find a way to do this division into 3 different agents, or in general, to model this flow.
Thanks in advice
You can use 2 split blocks to generate 2 independent documents and connect them through a variable or link to agents... maybe each original agent has an id and the copies in the split block will have something like agent.id=original.id;
Then after, when the documents are processed you can check for which ones have the same id to merge them into an article...
but if you want to get more complicated, there's also the following option:
create 2 enter blocks (enter1 and enter2), one for each document. I will assume your documents correspond to 2 different agent types called Document1 and Document2
On each one of the agent types, you will add a link to agents in order to be able to connect the documents to each other. Read more on link to agents on the help documentation if you don't know what that is.
At the end of the service block, on the on exit action, you can do the following:
Document1 doc1=add_Document1();
Document2 doc2=add_Document2();
doc1.linkToDoc2.connectTo(doc2);
enter1.take(doc1);
enter2.take(doc2);
I don't know if your original agent has to be connected, but you would follow the same principle to do that.
Later, you can just check if the connected docs are completed in order to join them in an article again.
I am having this issue with Anylogic, hope to get some help :)
The situation is the following: I have a population of agents X that has 10 different agents inside it, I need to pick up these different agents and put them in the "container agent" which is my pallet, and finally store them in the Pallet Rack.
The agents are different products being produced in the same location. There is a database stating each product when will it be produced and the amount of it.
I have created the agent X, how can I create 10 different agents within it?
If you want to have an agent population within an agent population, do this:
Have an agent type "Containers"
drag that into Main to create a population "pop_Containers". Load it as you like
Create another agent type "Products"
Open the "Containers" agent type and drag in "Products" to create a "pop_Products" within "Containers"
Load your products for each container as you see fit. This depends on your specifics of your database structure.
For the other questions, please create new questions. StackOverflow works best with specific questions in each topic, see https://stackoverflow.com/help/how-to-ask
I am a beginner user of AnyLogic.
I need to simulate a train station and it would be important to create as many ticket gates (service with lines) as the user wants. Is it possible to create a parameter and create the services based on this parameter?
Sure, but it is a bit un-intuitive.
Define your "Service with lines" to have many services (more than you need), as below:
Now, loop through all and set them suspended (I do it just for the first here):
services.getServices().get(0).setSuspended(true);
Now your parameter can turn them on dynamically by using setSuspended(false) for as many as you like.
hope that helps