villaviral.blogg.se

Agentset netlogo
Agentset netlogo








agentset netlogo

Agentset netlogo code#

You can also ask the patches to execute some code and this is the difficult part.įor example to turn all the patches green you could use: You can set the number of patches and hence their size using commands in the setup function. They form a rectangular grid that the turtles move over. You don't create patches like you create turtles. Patches are parts of the simulation that don't move and they can be the most difficult idea for the beginner to come to terms with. In this way turtles can be people, atoms, ants - whatever you need within the simulation. They don't have to look like turtles, you can create any graphic you want for them. Turtles provide the all-purpose moving agent. simulation time doesn't advance until all of the moves have been completed. You can change this so that each turtle obeys one instruction and then gives the next turtle a turn - this is ask-concurrent.Īlso notice that the tick doesn't move on. By default each agent runs the complete list of instructions in the ask before the next turtle gets a go. This can be important in some algorithms. The simulation is not a true parallel algorithm where all the turtles move at the same time - they each take a turn. If you slow down the program you can also see the turtles each taking a turn to move. The result is quite a pretty pattern for such a simple program. You can control the rate at which the go function is called using the speed slider at the top. By manually clicking the go button we can step thought the simulation but by changing the buttons type to Forever - simply click the Forever box - then the go function is called repeatedly until the button is clicked a second time. When we click the go button a step of the simulation is computed and displayed. the simulation, is reset and then then turtles are created. Now we place two buttons on the interface and set the first to the setup function and the second to the go function. The reset-ticks command sets the count to zero and tick increments it - you don't have to use this but it is very useful in most simulations.

agentset netlogo

The system keeps count of each step of the simulation and shows it at the top of the window. Notice that we have now got two extra commands - reset-ticks and tick. However this is such a standard requirement for a simulation that NetLogo has a special built in mechanism.įirst we separate out the setup and go functions: Now you could do this by writing the code for a single step of the simulation and enclosing it in a loop so that it repeats. The go part is a bit more complicated because generally what we have is a single step of the simulation that has to be run more than once to allow things to develop. The setup part is generally easy in that it just has to happen once and so you can associate it with a button exactly as we have been doing. The setup routine initializes everything ready for the simulation to start and the go does the actual running of the simulation. In most cases there are two distinct parts to a simulation - setup and go. So far we have just used a single button to setup and run our program.










Agentset netlogo