You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: artificialintelligence/assignments/flocking/README.md
+13-15Lines changed: 13 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,21 +9,22 @@ Flocking is a behavior that is observed in birds, fish and other animals that mo
9
9
!!! note "Formal Notation Review"
10
10
11
11
- $\overrightarrow{F}$ means a vector $F$ that has components. In a 2 dimensional vector it will hold $F_x$ and $F_y$. For example, if $F_x = 1$ and $F_y = 1$, then $\overrightarrow{F} = (1,1)$
12
+
- Simple math operations between vectors are done component-wise. For example, if $\overrightarrow{F} = (1,1)$ and $\overrightarrow{G} = (2,2)$, then $\overrightarrow{F} + \overrightarrow{G} = (3,3)$
12
13
- $\overrightarrow{P_1P_2}$ means the vector that goes from $P_1$ to $P_2$. It is the same as $P_2-P_1$
13
14
- The modulus notation means the length (magnitude) of the vector. $|\overrightarrow{F}| = \sqrt{F_x^2+F_y^2}$ For example, if $\overrightarrow{F} = (1,1)$, then $|\overrightarrow{F}| = \sqrt{2}$
14
15
- The hat ^ notation means the unitary vector of the vector. $\hat{F} = \frac{\overrightarrow{F}}{|\overrightarrow{F}|}$ For example, if $\overrightarrow{F} = (1,1)$, then $\hat{F} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$
15
16
- The hat notation over 2 points means the unit vector that goes from the first point to the second point. $\widehat{P_1P_2} = \frac{\overrightarrow{P_1P_2}}{|\overrightarrow{P_1P_2}|}$ For example, if $P_1 = (0,0)$ and $P_2 = (1,1)$, then $\widehat{P_1P_2} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$
17
+
- The sum $\sum$ notation means the sum of all elements in the list going from `0` to `n-1`. Ex. $\sum_{i=0}^{n-1} \overrightarrow{V_i} = \overrightarrow{V_0} + \overrightarrow{V_1} + \overrightarrow{V_2} + ... + \overrightarrow{V_{n-1}}$
16
18
17
19
It is your job to implement those 3 behaviors following the ruleset below:
18
20
19
21
### Cohesion
20
22
21
23
Apply a force towards the center of mass of the group.
22
24
23
-
1. The neighbors of an agent are all the other agents that are within a certain radius of the agent;
25
+
1. The $n$ neighbors of an agent are all the other agents that are within a certain radius of the agent;
24
26
2. Compute the location of the center of mass of the group ($P_{CM}$);
25
-
3. Compute the force that will move the agent towards the center of mass($F_{cohesion}$);
26
-
4. The farther the agent is from the center of mass, the force increases linearly up to the limit of the cohesion radius $r_c$.
27
+
3. Compute the force that will move the agent towards the center of mass($\overrightarrow{F_{c}}$); The farther the agent is from the center of mass, the force increases linearly up to the limit of the cohesion radius $r_c$.
27
28
28
29
$$
29
30
P_{CM} = \frac{\sum_{i=0}^{n-1} P_i}{n}
@@ -44,10 +45,9 @@ $$
44
45
45
46
It will move the agent away from other agents when they get too close.
46
47
47
-
1. The neighbors of an agent are all the other agents that are within the separation radius of the agent;
48
+
1. The $n$ neighbors of an agent are all the other agents that are within the separation radius of the agent;
48
49
2. If the distance to a neighbor is less than the separation radius, then the agent will move away from it inversely proportionally to the distance between them.
49
-
3. Accumulate the forces that will move the agent away from each neighbor ($F_{separation}$);
50
-
4. Clamp the force to a maximum value of $F_{Smax}$.
50
+
3. Accumulate the forces that will move the agent away from each neighbor ($\overrightarrow{F_{s}}$). And then, clamp the force to a maximum value of $F_{Smax}$.
Here you can see that if we have more than one neighbor and one of them is way too close, the force will be very high and make the influence of the other neighbors irrelevant. This is the expected behavior.
63
63
64
-
The force will go near infinite when the distance between the agent and the neighbor is 0. To avoid this, after accumulating all the influences from every neighbor, the force will be clamped to a maximum magnitude of $F_{Smax}$.
64
+
The force will go near infinite when the distance between the agent and the $n$ neighbor is 0. To avoid this, after accumulating all the influences from every neighbor, the force will be clamped to a maximum magnitude of $F_{Smax}$.
The force composition is made by a weighted sum of the influences of those 3 behaviors. This is the way we are going to work, this is not the only way to do it, nor the more correct. It is just a way to do it.
93
93
94
-
- $ \overrightarrow{F} = K_c*\overrightarrow{F_c} + K_s*\overrightarrow{F_s} + K_a*\overrightarrow{F_a} $ `This is a weighted sum!`
- $ \overrightarrow{V_{new}} = \overrightarrow{V_{cur}} + \overrightarrow{F} \cdot \Delta t $ `This is a simplification!`
96
96
- $ P_{new} = P_{cur}+\overrightarrow{V_{new}} \cdot \Delta t $ `This is an approximation!`
97
97
@@ -155,11 +155,9 @@ EOF
155
155
156
156
## Output
157
157
158
-
The expected output are the position and velocity for each simulation step after the time frame. After printing each simulation step, the program should wait for the next time frame and then simulate the next step.
158
+
The expected output are the position and velocity for each agent after the simulation step using the time frame. After printing each simulation step, the program should wait for the next time frame and then simulate the next step.
0 commit comments