This page was automatically generated by NetLogo 5.0.
The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.
powered by NetLogo
view/download model file: formation_newton.nlogo
This is our second physics-based model of a swarm, for the book entitled “Physicomimetics: Physics-Based Swarm Intelligence.”
Multiple particles use F = ma and a “split Newtonian” force law to self-organize into a triangular lattice or a square lattice.
As opposed to Hooke’s law, this simulation uses a “Newtonian” force law that has been modified to include a repulsive component in addition to the normal gravitational attraction. It has also been generalized by allowing the force law to be 1/r^p as opposed to just 1/r^2.
In addition, the simulation model is extended to include square lattices by having two types of particles, as explained in Chapter 3 of the book.
Finally, notice that clustering of particles occurs in the simulation, whereas it did not when Hooke’s law was used. Try lowering the GRAVITATIONAL_CONSTANT. You will notice that the clusters will exhibit a “phase transition” and fall apart suddenly. The book provides an elegant explanation for why this occurs, and shows that clustering depends on the values of the force parameters. The G PHASE TRANSITION monitor gives the approximate value of the gravitational constant where the phase transition occurs. Above this value, clustering occurs. Below this value, the clusters fall apart.
Click SETUP AGENTS to initialize the particles, and click MOVE AGENTS to have them move.
The CLEAR button will clear the graphics, which becomes handy when particles have their pens down (more on this below).
The NUMBER_OF_PARTICLES slider allows you to control the number of particles created at initialization. Changing this slider while the simulation is running will have no effect. You can change the number of particles while the simulation is running by using the ONE IS BORN and KILL ONE buttons. However, the ONE IS BORN and KILL ONE buttons do not change the number of initial particles when the simulation is restarted by clicking SETUP AGENTS.
The ONE IS BORN button creates a new particle.
The KILL ONE button randomly kills an existing particle.
There is also a TOGGLE FORMATION button that allows you to choose between square and triangular lattices. A monitor indicates whether the square or triangular lattice has been selected.
All other sliders will affect the simulation when it is running.
Particles are initialized in a random cluster in the middle of the graphics pane, and self-organize into a triangular lattice. The lattice is not perfect, but that is OK because we are interested in “satisficing systems,” as opposed to “optimal systems.”
The GRAVITATIONAL_CONSTANT controls the G parameter in the split Newtonian force law. The POWER controls the value of “p” in the generalized law. The DESIRED_SEPARATION is the desired distance between neighboring particles.
Again, FRICTION is enabled. This allows the system to stabilize.
This simulation serves to teach you about physics-based swarms, as well as the Conservation of Linear and Angular Momenta. This is covered in detail in Chapter 3 of the book.
The red dot in the simulation shows the center of mass of the system. If the Conservation of Linear Momentum holds in both the x- and y-dimensions, the red dot will not move. This simulation includes a monitor for the Angular Momentum and you will see that it does not change over time, if the system is closed.
This model allows you to add and remove particles. Removing particles allows you to test how robust the system is to particle failure. Adding particles allows you to see how scalable the system is, and illustrates just how nicely new particles are incorporated into the lattice. Adding and removing particles opens the system, and temporary changes in the momenta can occur during these events.
Although it doesn’t look like the linear momentum is shown on the graph, this is because it is overdrawn by the angular momentum curve. If you slow the simulation down (with the speed slider) and add a particle, you will usually see all three curves.
See how the FRICTION changes behavior. Click SETUP AGENTS, lower the friction, and click MOVE AGENTS. What happens?
Similarly, change the GRAVITATIONAL_CONSTANT or the POWER.
Change the DESIRED_SEPARATION while the system is running. Try changing it slowly and then change it quickly. What happens?
Add and remove particles.
See how the G PHASE TRANSITION value is affected when you change the GRAVITATIONAL_CONSTANT, the POWER, and the FORCE_MAXIMUM.
In “formation_hooke.nlogo” we noted that unusual behavior can occur with certain parameter settings. Try similar settings with this simulation (which uses the split Newtonian force law). Do you see the same behavior?
In this model, all particles have the same mass. What happens if particles have different masses?
What happens when you change the sensor view?
What other formations can you create by extending the code to include more types of particles?
Note, in order to change any NetLogo simulation, you must have the source code (i.e., “formation_newton.nlogo”) downloaded to your computer, as well as NetLogo itself. You can not change the code when you are running the simulation with your browser.
This simulation allows the user to create new particles and kill existing ones.
Killing a particle is accomplished via a call to the NetLogo procedure “die.”
To create a particle, the “hatch” command is used - this clones an existing particle and moves it away from the original. Also, the new particle has the “pen down,” which means that you will see the path that the particle takes. If the graphics pane becomes too busy, click on the CLEAR button.
This is our second physics-based swarm simulation, which modifies the force law from Hooke’s law to a generalized split Newtonian force law.
To see our implementation on seven simple robots:
Spears, W. M., Spears, D. F., Hamann, J., and Heil, R. (2004) Distributed, physics-based control of swarms of vehicles. Autonomous Robots, 17 (2-3).
For an explanation of the phase transition:
Gordon-Spears, D. F., and Spears, W. M. (2003) Analysis of a phase transition in a physics-based multiagent system. Lecture Notes in Computer Science, Volume 2699.
To see the first papers that outlined the work presented in this simulation:
Gordon, D. F., Spears, W. M., Sokolsky, O., and Lee, I. (1999) Distributed spatial control, global monitoring and steering of mobile physical agents. In Proceedings of IEEE International Conference on Information, Intelligence, and Systems.
Spears, W. M., and Gordon, D. F. (1999) Using Artificial Physics to control agents. In Proceedings of IEEE International Conference on Information, Intelligence, and Systems.
If you mention this model in an academic publication, we ask that you include these citations for the model itself and for the NetLogo software:
- Spears, W. M. and Spears, D. F. (eds.) Physicomimetics: Physics-Based Swarm Intelligence, Springer-Verlag, (2011).
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
Copyright 2011 William M. Spears. All rights reserved.
Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:
a) this copyright notice is included, and
b) this model will not be redistributed for profit without permission from William M. Spears. Contact William M. Spears for appropriate licenses for redistribution for profit.
; William M. Spears September 2011 ; Triangular and Square Lattices Using the Split Newtonian Force Law ; For research and educational use only breed [particles particle] ; Introduce the "particle" breed globals [total_lmx total_lmy total_angular_mom G p FR D center_of_mass_x center_of_mass_y FMAX DeltaT square? square_button? Gt] turtles-own [hood deltax deltay r F Fx Fy v vx vy dvx dvy mass view lmx lmy theta lever_arm_x lever_arm_y lever_arm_r angular_mom] to setup clear-all ; Clear everything ; Create and initialize particles create-particles Number_of_Particles [setup-particles] set square_button? false ; Start with a triangular lattice update-info ; Computes center of mass and displays location set center_of_mass_x (sum [xcor * mass] of particles) / (sum [mass] of particles) set center_of_mass_y (sum [ycor * mass] of particles) / (sum [mass] of particles) ask patch (round center_of_mass_x) (round center_of_mass_y) [ask patches in-radius 4 [set pcolor red]] reset-ticks end to run-and-monitor if (count turtles < 1) [user-message "Please click HALT and then SETUP AGENTS first" stop] update-info ask particles [ap-particles] ask turtles [move] ; Computes center of mass and displays location set center_of_mass_x (sum [xcor * mass] of particles) / (sum [mass] of particles) set center_of_mass_y (sum [ycor * mass] of particles) / (sum [mass] of particles) ask patch (round center_of_mass_x) (round center_of_mass_y) [ask patches in-radius 4 [set pcolor red]] set total_lmx sum [lmx] of particles ; Total linear momentum, x-component set total_lmy sum [lmy] of particles ; Total linear momentum, y-component set total_angular_mom sum [angular_mom] of particles ; Total angular momentum of objects tick do-plots end to setup-particles ; Set up the particles setxy (random-normal 0 20) (random-normal 0 20) ; Start in a cluster set heading random 360 ; Everyone has a random heading set vx 0 set vy 0 set mass 1 ; Start with no motion and mass = 1 set shape "circle" set size 5 ifelse ((who mod 2) = 0) [set color white] [set color yellow] ; Different colors for square formations set theta 0 end to ap-particles ; Run artificial physics set Fx 0 set Fy 0 ; Initialize force components to zero set vx (1 - FR) * vx ; Slow down according to friction set vy (1 - FR) * vy set hood [who] of other particles ; Get the IDs of your neighbors foreach hood [ set deltax (([xcor] of particle ?) - xcor) set deltay (([ycor] of particle ?) - ycor) set r sqrt (deltax * deltax + deltay * deltay) set view 1.5 ; For triangular lattice if (square?) [ ; For square lattice ifelse ((who mod 2) = (? mod 2)) [set view 1.3 set r (r / (sqrt 2))] ; See Chapter 3 for details [set view 1.7] ] if (r < view * D) [ ; The generalized split Newtonian law set F (G * mass * ([mass] of turtle ?) / (r ^ p)) if (F > FMAX) [set F FMAX] ; Bounds check on force magnitude ifelse (r > D) [set Fx (Fx + F * (deltax / r)) ; Attractive force, x-component set Fy (Fy + F * (deltay / r))] ; Attractive force, y-component [set Fx (Fx - F * (deltax / r)) ; Repulsive force, x-component set Fy (Fy - F * (deltay / r))] ; Repulsive force, y-component ] ] set dvx DeltaT * (Fx / mass) set dvy DeltaT * (Fy / mass) set vx (vx + dvx) ; The x-component of velocity set vy (vy + dvy) ; The y-component of velocity set v sqrt (vx * vx + vy * vy) set deltax DeltaT * vx set deltay DeltaT * vy if ((deltax != 0) or (deltay != 0)) [set heading (atan deltax deltay)] end to move ; Move the turtle fd (sqrt (deltax * deltax + deltay * deltay)) set lmx (mass * vx) ; Linear momentum of the turtle set lmy (mass * vy) set lever_arm_x (xcor - center_of_mass_x) set lever_arm_y (ycor - center_of_mass_y) set lever_arm_r sqrt (lever_arm_x * lever_arm_x + lever_arm_y * lever_arm_y) if (((vx != 0) or (vy != 0)) and ((lever_arm_x != 0) or (lever_arm_y != 0))) [set theta (atan (mass * vy) (mass * vx)) - (atan lever_arm_y lever_arm_x)] set angular_mom (lever_arm_r * mass * v * (sin theta)) ; Angular momentum of the turtle end to update-info ; Update information from the sliders set G Gravitational_Constant set p Power set FMAX Force_Maximum set FR Friction set DeltaT Time_Step set D Desired_Separation set square? square_button? ifelse square? ; G phase transition computation, for [set Gt (FMAX * (D ^ p) / ((2 * sqrt(2)) + 2))] ; square lattice, and for [set Gt (FMAX * (D ^ p) / (2 * sqrt(3)))] ; triangular lattice (see Chapter 3 for details) end to do-plots set-current-plot "Linear and Angular Momenta" ; Select the Momenta plot set-current-plot-pen "Lmx" ; Select the Lmx pen plot total_lmx ; Plot the linear momentum, x-component set-current-plot-pen "Lmy" plot total_lmy ; Plot the linear momentum, y-component set-current-plot-pen "Angular" plot total_angular_mom ; Plot the angular momentum end ; Kill a particle to one-dies if (count (particles with [mass = 1]) > 1) [ ; Don't kill last particle ask one-of particles with [mass = 1] [die] ; Ask one particle to die clear-drawing ; A little cleanup is required ] end ; Create a new particle to one-is-born if (count (particles with [mass = 1]) > 0) [ ask one-of particles with [mass = 1] [hatch 1 [set deltax 0 set deltay 0 pd ; Clone an existing particle ifelse ((who mod 2) = 0) [set color white] [set color yellow] ; Different colors for square formations setxy xcor + (random-normal 0 (D / 2)) ycor + (random-normal 0 (D / 2))]] ] end ; Toggle between triangular and square formations to toggle-formation if (square_button? != 0) [set square_button? not square_button?] end