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.
Related
When I create a ParametersVariation simulation, the main model does not run. All I see is the default UI with iterations completed and replication. My end goal (as with most people) is to have a model go through a certain number of replications, but nothing is even running. There is limited documentation available on this. Please advise.
This is how Parameters Variation is intended to work. If you're running 1000 runs and multiple replications with parallel runs, how can you see what's happening in Main in each?
Typically, the best way to benefit from such an experiment is to track the results of each run using elements from the Analysis palette or even better to export results to Excel or similar.
To be able to collect data, you need to write your code in Java actions fields with root. to access elements in main (or top-level agent).
Check the example below, where after each run a variable from main is added to a dataset in the Parameters Variation experiment. At the end of 100 runs for example, the dataset will have 100 values of the main variable, with 1 value for each run.
Good day
I'm a new user trying to find my with Anylogic.
Any help with the following question will be appreciated.
Is it possible to start a model with initial values/quantities given to certain blocks/sections in a model? In other words not have the model start from 0 but from the values given.
You can run a "warmup" period manually and save that as a model snapshot. In future runs, you can start off from that snapshot by loading it. See the help on model snapshots
This is the general problem of model initialisation (e.g., if you're modelling a manufacturing facility, you may want the run to start with the facility at the state it would be at on 9am next Monday morning). There is no generic answer: what initialisation you need is 100% model-dependent (as is how easy/hard this is).
In particular, process models make this difficult because entities (agents) are expected to have flowed through the process up to the point they 'start' in. You can use things like extra initialisation-only Source/Enter blocks to 'inject' agents into the appropriate process points, but in most models it's not this easy: you will have all kinds of model state that needs to be made consistent with this (e.g., the agents flowing through the process might have attributes which have changed based on what's happened to them so far, so this would have to be made consistent).
That's why warm-up periods (letting the model run 'from empty' for a period until its state is qualitatively what you want as your starting point) is a common approach. Model snapshots can help you here (see Ben's answer) but they're not the only way of doing it. (You can also just 'reset' all your metrics/output gathering at the point when you determine the warm-up period has ended --- i.e., you are effectively establishing a new 'time zero' --- but, again, exactly what you need to do is 100% model dependent.)
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.
I am writing a piece of code in which investment simulations for different types of factories are run. To calculate if an investment is worth the try, the to-be-build factory (say, steel-factory) is analyzed for revenues and costs in the future. To do that, the turtle (e.g. a company) calculating the investment needs to know the production capacity of the steel-factory.
to test
let future-steel-production ([max-processing-capacity * operational-time] of one-of steel-factories
end
But if no steel-factory is build yet (i.e. created), I get the error code:
OF expected input to be an agent or agentset but got NOBODY instead.
Is there any way to access an agent's variable, when the agent hasn't been created yet?
Is there any way to access an agent's variable, when the agent hasn't been created yet?
No. That's a logical impossibility.
But that doesn't mean that you can't figure out the future values of these variables.
You need to ask yourself how you would initialize these variables if you were to actually create the agent. These values (max-processing-capacity and operational-time) have to come from somewhere, right? Do you some have some definition of factory types stored in a file? Accessed via a reporter or some global variable?
If you were to create a factory with something like:
create-factories 1 [
set max-processing-capacity ???
set operational-time ???
]
...what would you replace ??? with? That's your answer. You need to use whatever you would use at factory creation time when calculating future steel production.
Basically I've got a Service which can work with two alternatives of ResourceSets. Let's say, the Service would optimally work with one Doctor and one Nurse, but it is also possible to work with only one Doctor if a Nurse isn't available.
Now, assuming the Doctor works slower without a Nurse, the Service's delay time must depend upon the resourceSet being employed at the moment (Doctor+Nurse or Doctor). Any idea how can I program this?
You should also have in mind that my model has various Services in parallel working in the same way, it's not just only one Service line.
Thanks!
You're using Services but, to me, using the combination of Seize, Delay and Release gives you more flexibility.
What I've done is set the resource choice according to the image bellow:
It is important to have the nurses prior to the doctors in the first set (for some reason anylogic would opt for using only the doctor if otherwise - even with a nurse available).
Than, I would write this code:
Which means that if the agent was only able to seize one resource it will take longer (15 is just a random value).
In the delay block, I would set the processing time to agent.processTime
The topology I'm using is this:
Obviously this is a workaround and will not work for every case. You can always change the conditions you verify. I couldn't find a way to check which resource set was picked by the seize operation. If you're in a hurry this will do the trick.
Hope that helps,
Luís