Is there a way to stop the "Source" block from generating agents after a specific time in AnyLogic? - simulation

Utilizing a source generating agents on an Interarrival time basis, I would like to stop the source block from generating agents after a certain amount of time passing so that the model can continue to process the agents.

One option to encapsulate all the logic inside the source block, without external events or variables, would be to select Multiple agents per arrival as true and then have a conditional statement for the number of agents, for example time() > 10 ? 0 : 1, so that after 10 model time units there will no agents arriving

Sure. If it is a inter-arrival source block, make it use a variable as the interrarrival time, of type double:
Then, create an event that triggers once only, after your specific time. Make it change the variable to 0 as below. Make SURE to trigger it not at time 0 (as in the screen but when you need it!):
NOTE: Do not set myRate = 0;. Instead, set it to infinity` to actually have no more arrivals.

Related

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

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

extract agents stored as a parameter inside one agent in anylogic

[extract agents from a parameter]
[1]: https://i.stack.imgur.com/sXoOk.jpg
I have an agent (shipment) with amount parameter. I want to make decisions according to every single shipment to decide where to go. the problem i've struggled with is how to transform my one agent per arrival to many agents equals to the parameter (amount) after he gets out of the queue, queue1 .I used unbatch block to illustrate what i am trying to do.
you can't unbatch things if you haven't batched them before..instead to achieve the same thing you can use a split block
With the split block you can define the number of copies based on that amount parameter and you can define the type of agent copied as well

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.

Anylogic, how can I create a dynamic batch size that depends on the number of arriving agents every day?

Multiple agents X that are determined by a distribution arrive at source with a defined interarrival time. I need X to be also my batchSize, this means that every time there is a new arrival, the batchSize needs to change and adjust to X number of agents in that arrival.
I've tried using source.count() On Exit and then batch.set_batchSize(), but since source.count() won't set to 0 before a new arrival, it doesn't work.
Any ideas? Thank VERY much for your help.
Create a variable called batchSize of type int. In the source's On before arrival: field, type the following:
batchSize = uniform_disc(1, 10);
Of course, instead of the distribution I used, use whichever you need.
Then, in the source properties again, for the Agents per arrival: field, write batchSize.
In the batch block's On enter: field, write:
batchBlock.set_batchSize(batchSize);
Replace batchBlock with whatever your block is named.
That should do it.

how to set 'warm-up period' in AnyLogic

I want to set the warm-up period in AnyLogic Personal Learning Edition. I searched for the warm-up period place in AnyLogic, but I couldn't find any thing about the warm-up period.
Is there a warm up period in Anylogic or something like this?
There is no default warm-up setting as it would not make sense given the vast flexibility of the tool and user needs.
It is easy, however, to set it up yourself. As usual, there are many different options, here is one:
create a variable v_WarmupDuration on Main, set it to whatever many time units you need
any data object you want to only record after the warmup period, ensure it only captures data if time() > v_WarmupDuration.
Events can have a custom initial time which you can use v_WarmupDuration for.
Functions that log data can only do so if time() > v_WarmupDuration, and so on.
Alternatively, log all your data as normal but add time stamps to them. Then, you can
Creating a warmup variable works fine for metrics you create yourself.
But if you want to use the built in functionality like histograms created from timeMeasureStart and timeMeasureEnd blocks in Anylogic, you will also need to add an extra select option so e.g. assuming you set v_WarmupDuration to 60 minutes, then you need a select block with a decision on false that goes straight to sink block or the next element after the timeMeasureEnd.
Condition if true: time(MINUTE) > v_warmupDuration
That way, the warmup period will not accumulate into the dataset of the timeMeasureEnd.
If you want to set this as a parmeter to an experiment, then ...
Add a variable to the experiment page off the screen e.g. v_warmupMins
Add a control like a slider on the experiment page and link to the variable v_warmupMins
Add a parameter to hold the warmup time in the Main canvas e.g. p_warmupMins
On the experiment properties, set the parameter p_warmupMins = v_warmupMins
to programmatically add this time onto the StopTime, add this to the Before Simulation Runs
getEngine().setStopTime( getEngine().getStopTime(MINUTE) + v_warmupMins );
Now when i run experiment with slider set to 60 mins, it adds 60 mins onto the stoptime and runs the experiment without accumulating metrics until that time has passed.
Hope that helps.