Flock
Flock behaviour based on the Boids algorithm.
Flock
Flock behaviour.
The flock operates via a species rule matrix, which is a 2D matrix of species
rules, such that every species has a separate relationship with every other
species including itself. As in the Boids algorithm, the rules are:
- separate
: how much a particle should separate from its neighbours.
- align
: how much a particle should align (match velocity) with its neighbours.
- cohere
: how much a particle should cohere (move towards) its neighbours.
Taichi Boids implementation inspired by: https://forum.taichi-lang.cn/t/homework0-boids/563
Source code in src/tolvera/vera/flock.py
8 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 |
|
__call__(particles, weight=1.0)
Call the Flock behaviour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles |
Particles
|
Particles to step. |
required |
weight |
f32
|
The weight of the Flock behaviour. Defaults to 1.0. |
1.0
|
Source code in src/tolvera/vera/flock.py
__init__(tolvera, **kwargs)
Initialise the Flock behaviour.
flock_s
stores the species rule matrix.
flock_p
stores the rule values per particle, and the number of neighbours.
flock_dist
stores the distance between particles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tolvera |
Tolvera
|
A Tolvera instance. |
required |
**kwargs |
Keyword arguments (currently none). |
{}
|
Source code in src/tolvera/vera/flock.py
randomise()
randomise_attr(attr)
Randomise a specific attribute of the Flock behaviour.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attr |
str
|
The attribute to randomise. |
required |
step(particles, weight)
Step the Flock behaviour.
Pairwise comparison is made and inactive particles are ignored. When the distance between two particles is less than the radius of the species, the particles are considered neighbours.
The separation, alignment and cohesion are calculated for each particle and the velocity is updated accordingly.
State is updated in flock_p
and flock_dist
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
particles |
template
|
A template for the particles. |
required |
weight |
f32
|
The weight of the Flock behaviour. |
required |