How to measure the total time in the system in AnyLogic - anylogic

I would like to know how to measure the total time one agent expend in the system in discrete events simulation.
Can I use this code? Time=time() timeDS.add(time()-Time); but allocating the agent.Time+time() in the exit in the source and timeDs.add(time() agent.Time); at on enter in the sink?
Thank you

Short answer: Yes you can.
You can also use the "On startup" and "on destroy" code fields of the agent properties, this is the true life span of your agent.
(And next time, maybe try it first ;) )

Related

Anylogic count and store values at data base Table with agent

Anylogic How to count agent enter and leave the charging block with time constraint. I am wondering how to compute the total agent present at charging station .
enter image description here
Example
Add an int variable next to the charge2 block called counterIn.
In the charge2 block's "on enter" code, write counterIn++.
Do the same for exiting and you have your counters.
PS: You may want to clarify/improve your future questions, this one is quite hard to understand. Some tips: https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow

Source Block: How can I set a custom rate of agent generation?

I want to generate agents from Source blocks on a custom schedule
For example: 2000 agents in 1st hour, 4000 agents in 2nd hour, 2000 in the third hour
How can I create such a Source block?
I am trying with
"Arrival Schedule" and "Rate Schedule" but not sure if thats the right approach
Arrival Schedule is indeed a good way to approach the problem.
The above should reflect the scenario you mentioned.

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

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.

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.

Adding labor cost as the model simulates on AnyLogic?

I created a variable, called labour cost. And I want this to increase, for example by 40 every 900s that the simulation is run. Can this be done?
Add an event with the following properties:
Instead of variable, use the name of your total cost variable of course.
Anything can be done with AnyLogic ;)
Use a recurring event that triggers this code every 900s:
myVariable+=40;
This is very basic so I also suggest you dig into all step-by-step tutorials that come with the help :)