How can I find the time it took to run a procedure in NetLogo?
Using 'ticks' defined in NetLogo is inaccurate for my purposes.
A vague idea would to subtract the system time at the start and end of
procedure if possible.
But I am unaware of any methods defined in NetLogo which would allow me to do this.
Charles' suggestion of the profiler extension is a great. The profiler extension is incredibly useful. However, it may be overkill for your situation.
Checkout reset-timer and timer. reset-timer sets an internal timer to 0, and then timer reports the amount of time that has passed since reset-timer was called (in seconds). The resolution is on the order of milliseconds, but depends on the system.
To time a single procedure call, you'd do something like:
reset-timer
my-procedure
print timer
If you want to get a sense of the average time a procedure takes, you can simply put it in a repeat block:
reset-timer
repeat 1000 [ my-procedure ]
print timer
Related
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.
i am new in using Anylogic , and i see in the PedWait block , Delay end on free function call , what does that mean and what is the difference between choosing it and the on delay time expiry ?
Thank you
the free function call is used in case you want to use something different than a time delay to allow the pedestrian to continue to the next block.
For example, a pedestrian can wait until a resource is available... since you don't know if the resource is going to be available in an exact amount of time, you can't use a time delay, so you use a free function call.
And when the resource becomes available, you can free the pedestrian by doing pedWait.free(ped)
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.
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.
I am working on some in which the speed and time are of high importance. I am using profiler to find the bottleneck of my code, but i cannot understand some things in profiler.
first, what does self and total time mean?
second, it has something called workspacefunc>local_min and workspacefunc>local_max, what are they?
self time is the total time spent in a function, not including any spent in any child functions called. As an example, if you had a function which was calling a whole bunch of other functions, the profiler only includes the time spent in the main function called from the profiler and not in any of the other functions defined inside the main function.
total time is the total time spent on a function (makes sense, right?). This includes the timing in all of the child functions called. Also, you need to be careful where the profiler itself can take some time to execute as well, which is included in the results. One small thing as well: the total time can be zero for functions whose running time are inconsequential.
Reference: http://www.mathworks.com/help/matlab/matlab_prog/profiling-for-improving-performance.html
workspacefunc... there doesn't seem to be any documentation on it, but this is the help text that I get when checking what it does:
workspacefunc Support function for Workspace browser component.
The Workspace browser is a window that shows you all of the variables that are defined in your workspace. If I were to take an educated guess, profiler does some analysis on your workspace variables, which include the min and max of certain variables in your workspace. I can't really say much more as there is absolutely no documentation on this, but it's safe to ignore. Simply focus on the functions that you are calling from your own code.