How to remove agents from population at a similar "Rate" that a Source block is creating agents - anylogic

I am creating a model where I require agents from a population to be removed at a certain rate after a certain moment in time. This rate should be similar and have the same variability as a "Rate" in a source block. My current method runs, but I would like to know whether this method is accurate and if there exists a more elegant solution.
To begin the removal, I set up a Timeout Event that creates a Dynamic Event.
create_dynamicEvent(exponential(rate));
My dynamic event then removes the agent by sending it through an enter block to a sink block, and sets up another instance of itself.
enter_sink.take(population.get(0));
create_dynamicEvent(exponential(rate));
Thank you for your help

I would also use Dynamic Events. You may want to create the DE in the Source block, though, i.e. each created agent already "schedules" its destruction. May be more appropriate, but it depends on the real system.
Apart from that: all good

Related

Multiple agents arrival based on Variable and database column

In my source block I want to be the amount of agents based on two different factors namely the amount of beds and visitors per bed. The visitors per bed is just a variable (e.g. visitors=3) and the amount of beds is loaded from the database table which is an excel file (see first image). Now I want to code this in the code block as shown in the example in image 2, but I do not know the correct code and do not know if it is even possible.
Simplest solution is just to do the pre-calcs in the input file and have in the dbase.
The more complex solution is to set the Source arrivals as:
Now, you read your dbase code at the start of the model using SQL (i.e. the query constructor). Make the necessary computations and create a Dynamic Event for each arrival when you want it to happen, relative to the model start. Each dynamic event then calls the source.inject(1) method.
Better still is to not use Source at all but a simple Enter block. The dynamic event creates the agent with all relevant properties from your dbase and pushes it into the Enter block using enter.take(myNewAgent)
But as I said: this is not trivial

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)

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.

My goal is that all resources of a resourcePool perform an action at a specific time. How do I create this iteration?

I am simulating a hospital stay with anylogic, on multiple levels. Each level has its own staff, represented by different ResourcePool (doctor, nurses, OSS) I created the flowchart of the actions concerning the patient. Now I would like, at a specific time (lunch and dinner), the OSS do tour the patients.
How do I set up that all OSS of a ResourcePool go to the rooms?
I would like to create a very small parallel flowchart, with sieze, moveTo, delay and release.
TNX
Easiest way is to use the "Downtime" element to prescribe your resources to do some action, see image below:
Under the "task type" selection, you can send them to a separate flow chart using a "ResourceTaskStart" element and they will do what you put downstream of that (moveto, delay...). Make sure to finish that with a ResourceTaskEnd block.
PS: The "Downtime" block can easily be triggered via a schedule. Make sure to read the help on that block (and the ResourceTaskStart/End blocks) and study the example models that use those.

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