Netlogo - Dynamically change the running time per experiment using Behavior Space - netlogo

I am running a model multiple times from behavior space. Each time the running length of time needs to be different according to the data imported from the external data source (e.g. the ending time of the last shift of production during a typical day). How to do this in behavior space?

You can manually limit the length of a run using the Stop condition in your BehaviorSpace experiment. You'll need a global to track the number of ticks to run, and then you'll need to populate it in the setup portion of your model:
globals [ ticks-to-run ]
to setup
reset-ticks
set ticks-to-run random 150 ; replace `random 150` by the data you load from your external source
end
to go
tick
end
This assumes you're running setup in your Setup commands and go in your Go commands. Then in your Stop condition add ticks > ticks-to-run and your model will stop once it has ticked past your ticks-to-run. Also make sure your Time limit is 0 in this case, as any value there would stop a model run before your custom ticks-to-run limit.

Related

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.

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.

Force NetLogo Behaviorspace start running from a specific behaviorspace-run-number

So, after a very long time workimg on my NetLogo code, I started running it using Behaviorspace. I saved all my required results for each run until it encountered an error in my code and stopped writing outputs. As the number of runs is so big and it will take so many days repeating the first runs, I was wondering if there is a way I could force NetLogo start from a specific behaviorspace-run-number.

How to re-run a Netlogo run?

Is there any way to re-run a Netlogo model exactly as before? (i.e. effectively press Go again and have the run be exactly the same as the last one.)
As I understand it, all you would need to be able to do this is to find out the random seed that was used in the last run - can this be done? Then all you would need to do is include the code "random-seed xxx" in the setup.
This feature would be really useful, so if it can't be done, maybe it could be implemented in future versions.
Thanks.
I'm assuming here you still want each run of your model to be different (change the random seed each time). According to the NetLogo Programming Guide:
If you don't set the random seed yourself, NetLogo sets it to a value based on the current date and time. There is no way to find out what random seed it chose, so if you want your model run to be reproducible, you must set the random seed yourself ahead of time.
So we can do this, we just need to handle "remembering" the random seed ourselves. Assuming you've got a standard setup procedure that has to be executed before the model runs:
globals [ run-seed ]
to setup
set run-seed new-seed ; get a random seed to use for our run
random-seed run-seed
; do the rest of our normal setup
end
Now when your model run is done you can show run-seed in the command center, or print it out in code to record it. Then you can use that seed instead of the new-seed in the setup procedure to reproduce the model run exactly in the future.

Simevents save and reload current state/status

I'm running some Simulink Simevents models. Every time I need to start from certain initial condition, such as certain number of entities in different queues and certain resource/server states. What I do currently is to let the model run for some time until the initial condition is researched, stop it, then test different parameters. Is there a way to save and rerun from certain initial condition, so every time I can run from the same state?