ndg
ndg

Reputation: 59

Two Worlds in Netlogo at the Same Time

Good day,

We're trying to create something wherein we can visually have two simulations running at the same time in Netlogo. It will be divided into two halves, The first half of the world will be simulating a run, and the other half will simulate another run with different variables.

is that possible?

I simply want to have my current program run on half of the screen.

Upvotes: 1

Views: 1032

Answers (4)

Arthur Hjorth
Arthur Hjorth

Reputation: 889

My suggestion would be to use LevelSpace (which is based on the Controlling API that Seth Tisue linked in one of the other answers). LevelSpace is a NetLogo extension that allows you to open NetLogo models from inside NetLogo.

Basically what you would want to do here is write a NetLogo model that opens two GUI models from your model file, and sets the variables in each of them as you want. You would then have a go procedure in the 'parent' model call 'go' in the two child-models, making them run in tandem.

What's cool about LevelSpace is that you can open as many models as you want, and you don't need to code in Java. You just need to use the extension and its primitives.

Disclosure: We're still working on it. It's stable, but the language (primitives) will change over time. Full disclosure: I am one of the authors of the LevelSpace extension, so I am biased. But it will definitely do what you are asking for here.

Edit: Just to show how relatively easy LevelSpace is, this is the entirety of the code required to do what you want. Download the extension, unzip it, put the ls folder in your extensions folder. Put this code in a separate model, create a setup and a go (repeated) button on its interface, and that's it.:

extensions [ls]

to setup
  ls:reset ; resets the levelspace extension
  repeat 2 [ls:load-gui-model "</path/to/your/model.nlogo>"] ; load two of your models
  ls:ask ls:models "setup" ; call 'setup' in all your models
end

to go
  ls:ask ls:models "go"
end

If you want to just set up the models without shutting them down and closing the windows, just do

to re-setup
  ls:ask ls:models "setup"
end

and call the re-setup procedure, either with a button or by writing it in the command center.

Upvotes: 2

JenB
JenB

Reputation: 17678

Okay, since you keep on asking the same question, I have isolated the bit of my comment that actually gives you the answer.

Wherever you have the turtles select from other turtles (eg finding a mate), they have to select only from ones on their side of the wall. One way would be to set up patchsets such as set left-side patches with [pxcor < 0] and then do the search like let partner-to-be one-of turtles-on left-side.

If all you want to do is restrict them to one side (say right), then you want xcor > 0 (and xcor < 0 for left side). Use the abs function. You will also need to check the position whenever one moves to make sure it stays on its side.

Upvotes: 1

JenB
JenB

Reputation: 17678

If you look carefully at the image, you will see that it is actually a single world (in the NetLogo sense of the word - a specific type of output window) that has been visually separated with a grey wall down the middle. You can see this by looking at the top bar of the window - the normal panning controls and tick counter are at the left corner only and the 3D button is at the right corner only. That is, this has been constructed with clever coding rather than a NetLogo feature.

Assume you have turned the middle patches grey (eg ask patches with [pxcor = 0][set pcolor grey]) then the code for the left hand simulation would control agent movements so they have xcor < -0.5 and the right would use xcor > 0.5

Since you are running the same model with different parameter values, you will probably want the agents to be the same breed. They can have an attribute for whether left or right and use agentsets to construct the left turtles or the right turtles. But you might also want to consider having different breeds.

Here are some suggestions how to achieve the effect entirely within NetLogo language:

  1. Do the clever programming with left / right as in the screenshot that inspired you
  2. Have separate breeds (eg red-turtles and blue-turtles) for the two scenarios and let them occupy the same world without interacting. If they interact with patches (eg eating grass) then you would need to have a patch variable for each breed (eg red-grass and blue-grass). Create plots and monitors to summarise the aspects of interest. The plots could have both scenarios as different lines, making comparison easy.
  3. As for 2, but also have a choose to switch views between breeds (so you could see how they are placed in their world. For example, create an update-view button which calls code to show/hide turtles and colour patches according to the choices on a chooser (which might be red, blue and both).
  4. Use BehaviorSpace and do the comparison after running the simulations based on the output generated.

All of the options 2-4 have the advantage that they can run more than 2 scenarios (eg red, blue and yellow turtles).

Upvotes: 1

Seth Tisue
Seth Tisue

Reputation: 30453

You could use NetLogo's Controlling API to write a program in Java (or Scala or Clojure or any JVM language you want) that embeds two NetLogo models.

Upvotes: 0

Related Questions