Any Logic Step Method - anylogic

I am building a dashboard for my System Dynamics model on Any Logic. I want to create a button that runs the model for 12 time units using getEngine().step() code. The method runs the model for only one time step of the simulation but I need 12 time units which is 1200 times the step. I was wondering if there any way to run the model for 12 time units and then pause it.
Also I want to start the model on a pause mode. I mean after clicking the Run button.
UPDATE: I found an answer to my second question. I created an event and set the following action to happen at time 12. getEngine().pause();

create an event (from the agent palette)
Make the event happen after 12 time units (seconds, minutes or whatever you have)
Add this code to the event:
pauseSimulation();

Related

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.

Incorporating tide times into AnyLogic

What would be the best way to incorporate changing tide times into an AnyLogic model? I would like to use the times to effectively block and unblock a port. I have looked at the schedule option and the format (Start: Day1, Time) doesn't seem the best way to do it.
You can model the tide by a reoccuring timed trigger.
AnyLogic offers the Dynamic Event for this, an event that can reschedule itself.
Depending on how you have the time data for the tides (list of DateTimes, fixed periods, database), you can retrieve that value for each new rescheduling of the dynamic event.
I attached a screenshot of a simple sample model. Here I assume you have got a list with the interval in minutes between each port-affecting tide moment (Low Tide/Port Blocked - High Tide/Port Open - Low Tide/Port Blocked - and so on....) . The dynamic event then sets a boolean variable portBlocked, but depending on your needs you could also trigger a Statechart Transition, block flowchart modules, or trigger a function.
The Action code of the Dynamic Event:
portBlocked=!portBlocked;
create_MyDynamicEvent(tideIntervalsInMinutes.get(tideCounter),MINUTE);
tideCounter++;
Explanation of the code:
Trigger your needed actions (here simple boolean variable)
Reschedule the event for the next tide change
Update the tide counter (used to retrieve the corresponding tide interval time from the list)
In the startup code of the model you will have to trigger the Dynamic Event once initially, for this just use the same code as point 2 above.

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.

Day Exception in Events in AnyLogic

I am currently doing a simulation model in AnyLogic of a Distribution Center where from Monday to Saturday I use an event to trigger the loading of a truck. I wish to program this loading every day at the same time, but how can I do it so it happens everyday EXCEPT Sundays. I currently have it as triggered: timeout and mode: cyclic, using calendar dates...
sure, the easy way is to just add a manual exception to the schedule as below:
And the more advanced way is to use a Dynamic Event that executes your daily action.
In the model start code, call create_MyDynamicEvent(7, DAY) to make it trigger after the first 7 days of the sim.
Then in the Dynamic Event action code, add whatever should happen every day. And also add a line that re-creates the same Dynamic event in 1 day, like
create_MyDynamicEvent(1, DAY)
This would then trigger every day, even Sunday. To avoid that, you can add an if-clause in the dynamic event action code to only execute your code if it is not Sunday.

How to refresh field calculation in live time

I've created a function to calculate time difference between current time and time recorded as StartTime. All calculations are perfect but my "StopWatch" won't update every second. Is there a way of updating it, so it can display every second elapsed since start point?
Window refreshing script isn't an option really.
Short answer: no.
There is nothing in Filemaker that will happen as a result of merely time passing - except for a script paused for a duration or installed on a timer.
To show a live, ticking clock, your best option would be to use a web viewer - see an example file here: http://fmforums.com/forums/topic/71934-calculating-elapsed-time-realtime/?do=findComment&comment=340205