Slime
Slime behaviour based on the Physarum polycephalum slime mould.
Slime
Slime behaviour based on the Physarum polycephalum slime mould.
The slime mould is a single-celled organism that exhibits complex behaviour such as foraging, migration, and decision-making. It is a popular model for emergent behaviour in nature-inspired computing.
The slime mould is simulated by a set of particles that move around the simulation space. The particles sense their environment and move in response to the sensed information. The particles leave a "pheromone trail" behind them, which evaporates over time. The particles can be of different species, which have different sensing and moving parameters.
Taichi Physarum implementation inspired by: https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/simulation/physarum.py
Source code in src/tolvera/vera/slime.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
__call__(particles, species, weight=1.0)
Call the Slime behaviour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles |
Particles
|
A Particles instance. |
required |
species |
Species
|
A Species instance. |
required |
weight |
f32
|
Weight parameter. Defaults to 1.0. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
Pixels |
A Pixels instance containing the pheromone trail. |
Source code in src/tolvera/vera/slime.py
__init__(tolvera, **kwargs)
Initialise the Slime behaviour.
slime_p
stores the particle state.
slime_s
stores the species state.
trail
is a Pixels instance that stores the pheromone trail.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tolvera |
Tolvera
|
A Tolvera instance. |
required |
evaporate |
f32
|
Evaporation rate. Defaults to 0.99. |
required |
**kwargs |
Keyword arguments. brightness (ti.f32, optional): Brightness of the pheromone trail. Defaults to 1.0. |
{}
|
Source code in src/tolvera/vera/slime.py
deposit_particles(particles, species)
Deposit particles onto the trail.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles |
template
|
Particle field. |
required |
species |
template
|
Species field. |
required |
Source code in src/tolvera/vera/slime.py
move(field, weight)
Move the particles based on the sensed environment.
Each particle senses the trail to its left, centre and right. Depending on the strength of the sensed trail in each direction, and the species parameters, a movement angle is calculated. The particle moves in this direction by a distance proportional to its active state and the weight parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
template
|
Particle field. |
required |
weight |
f32
|
Weight of the movement. |
required |
Source code in src/tolvera/vera/slime.py
randomise()
sense(pos, ang, dist)
Sense the trail at a given position and angle.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos |
vec2
|
Position. |
required |
ang |
f32
|
Angle. |
required |
dist |
f32
|
Distance. |
required |
Returns:
Type | Description |
---|---|
vec4
|
ti.math.vec4: RGBA value of the sensed trail point. |
Source code in src/tolvera/vera/slime.py
sense_rgba(pos, ang, dist, rgba)
Sense the trail at a given position and angle and return a weighted RGBA value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pos |
vec2
|
Position. |
required |
ang |
f32
|
Angle. |
required |
dist |
f32
|
Distance. |
required |
rgba |
vec4
|
RGBA value. |
required |
Returns:
Type | Description |
---|---|
vec4
|
ti.math.vec4: Weighted RGBA value. |
Source code in src/tolvera/vera/slime.py
step(particles, species, weight=1.0)
Step the Slime behaviour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles |
Particles
|
A Particles instance. |
required |
species |
Species
|
A Species instance. |
required |
weight |
f32
|
Weight parameter. Defaults to 1.0. |
1.0
|