AnyLogic how to link one agent to another - anylogic

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!

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.

Related

msg can't reach the stat chart for multiple deliveries

I'm trying to change the existing model in Anylogic (product delivery) and trying to move trucks to various locations. in manufacturing processes I add batch and hold to put 5 orders in the truck, but after I can't communicate with truck state chart and can't make it read the trigger (msg). I tried various methods but couldn't make it work. I'm new in anylogic and your help will be appreciated.
the first thing you should do is go to the truck agent, to the connections object, and verify if your message is being sent
Also to understand better how messages work, i suggest you watch the following video which is part of the course available at noorjax.teachable.com
https://www.youtube.com/watch?v=Fe2U8IAhlHM

Anylogic ‘how to’ questions

I am using Anylogic for a simulation-modeling class, and I am not anylogic or coding smart. My last and only coding class was MatLab based about 16 yrs ago. I have a few questions about how to implement modeling concepts in a discrete model with anylogic.
How can I add/inject agents directly into a queue downstream from a source? I have tried adding an additional source to use the “Calls of inject() function,” but I am not sure how to implement it after selecting it ( example: what do I do after selecting the Calls of inject() function). I have the new source feeding directly into the queue where I want the inject.
How can I set the release of an agent to a defined schedule instead of a rate? Currently, I have my working model set to interarrival time. But I would like to set the agent release to a defined schedule. (example: agent-1 released at 120 seconds, agent-2 released at 150 seconds, agent-3 released at 270 seconds)
Any help would be greatly appreciated, especially if it can be written in a “explain to me like I am 5yrs old” format.
Question 1:
If you have a source connected directly to a queue, then when you call source.inject() an agent will be created at the source block and go to the queue. If you have 1 source with multiple possible destinations, then you will have to use select output blocks and some criteria to go from the source to the desired queue.
Since you mentioned not being a strong programmer, this probably wouldn't be for you, but I often find myself creating agents via add_population and then just adding them to an ArrayList until I am ready to pull them into the DES flow. Really, there are near infinite ways to control agent flow within AnyLogic.
Question 2:
Option a: Arrivals by "Arrival Table in Database" You can link an AnyLogic database table to Excel, and then the source block will just have an agent arrive based on that table.
Option b: Arrival Schedule - you could set this up manually within the development environment or load your schedule from a database. I prefer option a over option b given your brief description.
Option c: Read in data to variable and then write code to release based on next arrival time. 1,000s of ways to do this, but one example could be a list of doubles (your arrival times), set an event to delay until next arrival, call inject function, remove that arrival from the list. I think option a would be best for you, but given that AnyLogic allows you to add java code, there are no limits to how sophisticated you could make your arrival logic.
For 2) You could also use an event or a dynamic event. The action could be source.inject(1); and you can schedule them to your preferences with variables. Just be vigilant that you re-start the events if necessary.
There is a demo-model from AnyLogic for dynamic events.

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);
}

Bluemix Conversation, advancing the conversation

I have two conversation nodes defined. The first is triggered on conversation_start and asks the users's name. The second stores the user name from input.text in a context variable and asks if the user wants to take a brief survey or do something else. The second one never executes. What should the trigger be on the second one in order to advance the conversation? There is no intent or condition set yet. Basically, I just want to follow a string-of-pearls pattern where every question gets asked and let the user opt out of some of the questions.
there are two main ways to achieve this. The one I recommend is to create an intent for each possible way. For example, you could create an intent called #affirmative, with values like "Yes", "Yeah", "Sure", "Ok", etc. All you have to do is to create the intent and then use it in the condition field.
But you can also check the user's input directly, using input.text. For example, you could use input.text.toLowerCase() == 'yes' as the condition. Have in mind that this should only be used if you are controlling the input and only allowing a few possible values. If not, use an intent and let Watson Conversation handle the input parsing for you.
Another really cool feature that Watson Conversation provides that can benefit is you is to have a node with a condition like intents[0].confidence < 0.6 and a response like "Sorry, I didn't get that". That way you make sure your flow will only trigger a condition with a high confidence for the intent.
Hope it helps!
You can use the jump to function to route the system to arbitrary dialog_node - this is great for creating directed dialogs. So whenever you want to continue with the next question (user answered the previous question), you can use jump to from the node processing the answer to the previous question to ask the user another question (jump to the body part of the next dialog node asking new question).
Now for "get name" use case you want the second node gathering the name from the user input hanging off the conversation_start node. If the conversation encounters a node that has children, the processing of the next dialog round will start at the first child of this dialog node - this way the contextual dialogs are defined in the conversation.
Bluemix Conversation can be thought of as a state machine. Each transition is diagrammed in the tooling, but each node can only be triggered by a condition. So that if you're on a node asking a question, and the answer that comes back does not trigger one of the child nodes, the state will not transition to a child. Answers entered into a node are processed by Watson, who provides "intents", which are essentially keywords found in the sentence he just analyzed. So one way to advance the conversation is to match named "intents" using the # prefix to the trigger of in a child node. Another way it to match named "entities" using the # prefex, although it is less clear how Watson builds entities. The third way is to match context variables using the $ prefix and simple conditional operators such as ==. Context variables are entirely managed by you, the developer. You are allowed to set one context variable at each node. And then you can use it to trigger a child node. This appears to be a good approach to managing the type of conversation I want to implement. The fourth way is to use the previous parent node's input value using along with simple conditional operators.

How CreateEntity PDU works?

I'm trying to learn DIS for a small project that I've in mind.
Basically I've a process that run a scenario, and it can receive external commands for creating and removing entities.
I've another process, a map, that can send commands to the scenario process, and I've two cases:
The map process send a command for creating a new entity, the scenario process receives it, and creates the new entity.
The map process can create a new entity without external commands (i.e. triggered by internal scenario logic). This new entity should be notified in DIS.
DIS CreateEntity PDU has following fields:
OriginatingEntityID
ReceivingEntityID
Which data should be inserted here by the map process in order to send the CreteEntity command? How can I specify which kind of player I want to create (F15, Soldier)?
In the second case, how can I notify that a new player was created without external commands?
In second case
It all depends on the design of your simulation.
A SM (simulation manager - that you have to create) would create EntityIDs and you would use these ID in your CreateEntity PDU. You can also hard-coded them or create your own custom algorithm to generate them. DIS, by itself, doesn't define an EntityIDs generation mechanism but it does require that each EntityID to be unique.
That being said, DIS requires all entities to be updated at least once per 5 secs (not that much true for DIS v7 since that delay can now be managed per entity).
Most of the DIS compatible software I know monitor the EntityState PDU to detect new objects. If an object hasn't been seen for more than 5 sec, you can assume it has been destroyed.
Hope this helps.