0

Im a relative noob regarding anylogic but i got a task to do in my homework so here comes my question:

I created a population of agents who are all patients... these patients get ill with a probabilty of lets say 30%... i alrdy implemented this one but now my task is to add a medicine using a new agent for this problem to heal them... but how do I link this new agent with the already existing one? My first agent gets triggered by a message.. therefore we have to use an event sending this message to a first person who gets infected etc..

Can anyone help me how I can create a new agent and link it to the old one to heal the people?

Many thanks in advance!

Hydra1995
  • 1
  • 2
  • 1
    it all depends how you use the medicine... I imagine for example that you could have a medicine with 2 states (used, notUsed) and if someone gets sick, it checks if a medicine has the state notUsed and if it does it sends a message to the medicine in question so it gets used, while at the same time the patient gets to a new state where he is healed... but I don't know... it depends how your system works... this is a design question, so not very suitable for stackoverflow – Felipe Jun 06 '18 at 14:29
  • thanks for your fast reply!yes thats exactly what i want... i just created now a medicine with the 2 states you mentioned above (used and not used)... i got a state in the my patient called "sick" how can i check now if a medicine hast the state notused followed by sending the message to the medicine that it gets used? – Hydra1995 Jun 06 '18 at 15:23

1 Answers1

0

ok so since this is what you need I will post it as an answer

medicine has a state chart called SC with an initial state which is used and a second state notUsed that you get through a message transition from one to the other.

when the patient gets to the state sick, it will need to find an agent Medicine which is in the state notUsed to be able to get healed, so you find it with the following code:

Medicine med=findFirst(main.medicines,m->m.inState(m.notUsed));
if(med!=null){//meaning that there is at least one not used medicine
    med.SC.fireEvent("use medicine");
    send("get better",this);
}

You will have to do the same probably when a new medicine is created you use the same method to find a guy in the state "sick".. I assume you are calling this function in the patient agent, but it may differ depending on when you are calling it.

Felipe
  • 8,311
  • 2
  • 15
  • 31
  • thanks! just some more couple question: 1. where do i need to enter the code? at which state or anywherelse? 2. my agent type name is Medicine & my agent population name is Medicines ... does the code change than or? you safe my life !thanks – Hydra1995 Jun 06 '18 at 22:01
  • i don't know where you should write the code.. it depends on how your model works... probably on the on enter state sick action in the patient and the on enter notUsed action of the medicine... but I'm just guessing – Felipe Jun 06 '18 at 22:11
  • and the code doesn't change except that Medicines has a capital letter – Felipe Jun 06 '18 at 22:12
  • I really cant get it running... I know its probably the easiest thing for you but i just dont get it done. could you please check my file? thank you so much! https://ufile.io/owypa – Hydra1995 Jun 07 '18 at 11:52