msg can't reach the stat chart for multiple deliveries - anylogic

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

Related

Considering differences in the same materials - Stations

I am trying to simulate a manufacturing assembly process, where material items are processed following an unique line. In the quality control stations, when a failure is detected, the object is sent to the repair area (by a truckpallet) and, when it is repaired, the same resource takes it and puts it at the start of the line. Until this point, I already programmed it.
The problem is the following: when it is a repaired object, is has to follow the same conveyor but with no stops in the stations. The object must enter a station and leave it, with no delays (as the works related with the stations have already been made).
I thought the best would be to consider the difference (repaired vs. not repaired) in the Agent, but then I can't work with it in the Main agent... I have also tried alternative solutions, for example defining variables in each station 1 and consider that in the stations delays and in the following station:
triangular( 109.1*delay_bec, delaytime_bec*delay_bec, 307.6*delay_bec)
Actions - in finished process:
if(delay_bec==0){
delay_headers=0;
delay_bec=1;}
But nothing worked... Any help?
I thought the best would be to consider the difference (repaired vs. not repaired) in the Agent, but then I can't work with it in the Main agent...
This is actually the correct approach. You need to create a custom agent type, give in a boolean variable isRepaired (or similar) and then in the delay you can dynamically adjust the duration using that characteristic:
agent.isRepaired ? 0. : 100
This will delay normal agents by 100 time units and repaired agents not at all.
Obviously, you must make sure that the agents flowing through the flow blocks are of your custom agent type (see the help how to do that)

How do i recreate a loading truck case with a limited number of trucks?

I have a warehouse with many palletrack which contains raw materials that have to be loaded on trucks and moved to a second warehouse. The loading zones (where trucks are loaded) are the green rectangular nodes (see image). The problem is that I don't know how to recreate the loading. If I use a seize then every single agent will seize a truck, but if I used the pickup block (like the pickup model tutorial), the source would create more trucks than I want(they are limited).
Any tips? (i want to say thanks to all the people who are helping me this week by the way)
Although there are many ways to model this I think the best option would be to batch your agents into truckloads and then to seize the trucks. Trucks must live inside a resource pool, so that you can have a fixed number of trucks.
Since you are using a network model I would then suggest you attach the truck to the batch you created and move it around and then detach the truck and release it afterward. You can however simply seize the truck and have the batch object use the animation of a truck.

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

AnyLogic how to link one agent to another

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.