Swarm Intelligence 2
Last updated
Last updated
Behaviours of swarm entities are expressed as forces which do not capture a physical meaning. They are constructed to express desired actions given certain circumstances within a local context. Physics is used because of the capability to resolve multiple and potentially contradicting directives, via force balance equilibrium and/or energy minimization, supported by the system of differential equations. We will implement only a basic set of swarm forces, namely “cohesion”, “separation” and “alignment”.
Cohesion expresses the idea of an entity desiring to be close to other entities ie. not being alone. Its implementation is highly geometric as for every group of entities we first compute the centroid and then construct force vectors from each entity to the centre of the cluster. In this sense, particles are attracted to one another and want to meet somewhere in the middle of their group.
The graph selects for each particle all its neighbours and computes the centroid using the “average” component. Force vectors are constructed and normalized using the “vector by two points” component. As there may be particles with no neighbours the operations may result to “null” values which we need to substitute with zero vectors. Finally, we scale the forces by a “strength” scalar to express how strongly particles desire to be come together.
The animation illustrates the effects of using cohesion and the dynamic update of particle relationships using the nearest neighbours logic. It is fascinating to observe how particles form clusters when they come into proximity; how stationary particles gravitate towards clusters but also how clusters are also being pulled by solitary particles, as the centre of gravity shifts; and finally how momentum can also cause detachment of particles from clusters. The natural analogy is of schools of fish and flocks of birds forming clusters to protect themselves from predators.
Separation is the opposite of cohesion. It expresses the idea of particles desire to be spaced apart or not too close to one another. While cohesion can be thought of as a electromagnetic attraction, separations is the equivalent of repulsion. Its computation is equally simple: we aggregate all vectors between a particle and its neighbours and scale the normalized vector by a strength factor. Because the vector direction is from the neighbours towards the particle, the result is motion away from them.
The animation illustrates the effects of separation applied to eight particles trapped in a bounding box. Overtime they push one another up to the edges and nodes of the spatial container. Using more particles has the effect of space filling or somewhat evenly distributing within the available domain.
Another way to consider the separation behaviour in a systemic sense that of collision avoidance. By instantaneously exerting a repulsion force once a particle detects it is too close with another it causes it to change direction and avoid clashing. This can be also attributes with a natural analogy of flocks trying to avoid restricting each others motion by keeping some internal distances.
Alignment conveys a particle’s desire to move along the same direction as the others in the same group. Unlike cohesion and separation, both being position dependent forces, alignment is depending on velocity. The implementation is equally trivial: we compute the sum of all neighbours’ velocities and reinterpret the aggregate direction vector as a force. For symmetry we also use a “strength” scaling factor.
The animation below illustrates the effects the alignment force. As alignment requires velocity for exerting forces, we either need to initialize the swarm with random values or incorporate additional forces to initiate motion. The net effect of particles moving towards the same direction emerges overtime.
Alignment being dependent to velocity in a positive manner has the effect of adding energy to the system. Thus overtime the swarm accelerates and velocities explode. To restraint this behaviour we may either apply a speed limit constraint or incorporate a force that resists motion. The “resistance” force is just the drag we used in previous sessions; it is just renamed to match the swarm behavioural thematic.
Having developed the nearest neighbours logic and core behaviours, we integrate them in the force analysis cluster as seen below. Unlike previous implementations, where details of the force parameters were kept private within the force analysis scope, here we make them public by exposing them via input parameters. In addition, we also expose the per particle nearest neighbours topology for visualization purposes.
The motivation for exposing the force scaling factors is for allowing to dynamically change their values while the simulation is being active. This make the overall, graph a bit messier but as a remedy all parameters follow the same conceptual framework of being weights or strengths.
The animation illustrates the effects of modifying strength ratios dynamically. The swarm starts from a condition where cohesion and alignment has forced particles to collapse into one small cluster. Reducing cohesion and letting separation become prominent scatters the cluster. Additionally, we may modify the proximity range to visualize the effects of nearest neighbours dynamic topology.
The visualization cluster is also updated to incorporate the dynamic topology update feature. This merely implemented by a Cartesian product between each particle and its nearest neighbours.
Another addition to the display cluster is the addition of a computation of the total kinetic energy of the system. The value is emitted as an output of the cluster. The use of kinetic energy is helpful for tracking whether the system is moving towards halting or exploding. This is critical because alignment requires balancing using resistance to keep the system in a reasonable stable state.
We may also visualize systemic quantities, such the kinetic energy, using the “value tracker” component. It produces a graph that captures overtime the system’s energy fluctuations.
Practice
Develop visualizations using mesh instancing to attach geometries per particle. Define a coordinate system from a particle’s position and velocity.
Swarms are interesting when they interact with their environment. Here they are trapped within a box. It is possible constrain them on surfaces or more complex solids. You may use one of the point-in-shape and closest-point-to-shape components to achieve such complex interactions.
In this session we extended the physics engine to simulate nature-inspired swarms and flocks. We studied the notion of nearest neighbours as means to define a local support or context. We expressed abstract behaviours using simple forces that do not represent particular laws of physics but constructed ideas. Swam intelligence may be used for cinematic computer graphics, crowd simulations as well as artistic designs.
An interesting outcome from the study of swarm intelligence is the idea of “behaviour” appears as an attribute we project when encountered with complex interactions of information expressed under specific representations. There is absolutely nothing inherently swarm-like about the three constituent forces we defined, yet the result of their interaction resembles properties we associate with swarming. In this sense behavior is perhaps emergent and contingent to observation in as much as creativity to experimentation.
If we imagine for a moment removing the entire physics backbone, except from the part of persisting state over time, we may foresee the steps towards creating an agent based simulation environment where at each time step we use information from the past and the current context to make decisions about the future. To create any other type of simulation we thus need a system state description and a set of update rules