"Calculated Column" in AnyLogic Database

Viewed 55

I can create an Anylogic database with one column (Column1) being a date/time, and a second (Column2) being a value, representing minutes. How can I create agents that arrive into the model based on the time Column1 - Column2?

2 Answers

Here are the steps to do:

  1. Create a for-loop at the start of your model that loops through all rows in that table (use the Database Query if unsure)
  2. Do the maths to subtract the mins from the date (Learn about Java Date and how to subtract values via StackOverflow, millions of people had similar issues)
  3. Create a "Dynamic Event" (not an "Event") that creates an agent. Name it MyDynamicEvent or similar
  4. in your for-loop, after calculating the duration from model start to the agent creation, call create_MyDynamicEvent(timeToStart, timeunit) and provide it the ime to be called. If unsure what this is, check the help and example models on Dynamic Events
  5. In the Dynamic event, create your agent, for example into a population myAgents by calling add_MyAgents()

This will create 1 agent for each data row at the point col1-col2

(There will be several hurdles along the way: If you get stuck, please add new questions, see https://www.benjamin-schumann.com/blog/2021/4/1/how-to-win-at-anylogic-on-stackoverflow )

Good luck

Unless there is a specific reason you can't add a third column that has the arrival time calculated for you (i.e. Column 3 = Column 1 - Column 2) I would strongly suggest that you make use of the standard AnyLogic functionality in the source block to create your agents.

See example below and more details in this questions - https://stackoverflow.com/a/68708035/4019094

enter image description here

Then you can effortlessly not only setup the arrival of agents but also populate their parameters from the DB table.

If you cant make changes to the DB table then dynamic events as per Benjamin's answer is the only way to go.

Related