JuliaDynamics / Agents.jl

Agent-based modeling framework in Julia
https://juliadynamics.github.io/Agents.jl/stable/
MIT License
734 stars 119 forks source link

Allow interactive abmplot to initialize new starting models #1056

Open amynang opened 3 months ago

amynang commented 3 months ago

This issue has been discussed here

In short, it would be great if agent number could be controlled with a slider. I realize that this change could not be dynamic.

Describe the solution you'd like This is possible in NetLogo (e.g. here). Changing the density of the agents does not affect a started run, but it does take effect once you press setup. The same is not possible in the Agents version of the model (here, see lines 65-86).

Datseris commented 3 months ago

Hi, I can't run NetLogo. Are you able to provide a video of how what you want looks like?

Ideally what we would like to achieve is for the user to provide a "model generating function", that takes various keywords and generates a new model, which is then used to reset the current model to. My conceptual difficulty with this is that typically the inputs to this argument would be different to the formal model parameters. This means you would need two sets of sliders: one for the formal interactive parameters, and one for the "re-initialization" parameters. It may make the interface ugly. We are already rather tight on space... But the way I outlined above is at least easy to do in code, as all the infrastructure is already there and used for other parts: the current model resetting and the current model updating from parameter sliders.

amynang commented 3 months ago

Sure here it is. There is no difference between sliders that control setup conditions like agent density and parameters like "similarity threshold" that can be modified while the model runs. What is different in Netlogo is that on pressing setup you re-initialize the model so that n agents (according to density) are redeployed to random positions. Similarity on the other hand is a step related parameter so it can be manipulated on the fly (between steps).

to setup
  clear-all
  make-turtles
  update-turtles
  update-globals
  reset-ticks
end

to make-turtles
  ask patches [
    if random-float 1 < density [            ;;here
      sprout 1 [ ;;create an agent here
        set shape "square"
        set color one-of [14 35]
      ]
    ]
  ]
end

Screencast from 08 07 2024 08_01_55

Datseris commented 3 months ago

There is no difference between sliders that control setup conditions like agent density and parameters like "similarity threshold" that can be modified while the model runs.

There is a difference. How NetLogo conveys this difference may be obscure to you. Or it may even not attempt to convey the difference because it uses global scoping for everything. But, think about it: at least in Agents.jl everything is a self contained function that doesn't use the global scope. One needs to be able to convey the information of what slider is for re-initializing the model and what slider is for adjusting a model parameter. Model parameters are stored in model.properties while re-initializing the model is given as a one-time input argument to a function that outputs a new model. To know which of these two aspects to update means that you need to know whether you slider is for "parameters" or for "re-init".

How we do this separation I don't know yet. Perhaps it makes sense to vertically concatenate both sets of parameters into one overarching set of sliders. But it would make it difficult to separate which is which I guess. I am open to PRs proposing a GUI design.