-
Notifications
You must be signed in to change notification settings - Fork 1
/
AreSheepClusteredUpdatedForFurthestSheepFromGoal.m
38 lines (33 loc) · 1.33 KB
/
AreSheepClusteredUpdatedForFurthestSheepFromGoal.m
1
2
3
4
5
6
7
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
function Target = AreSheepClusteredUpdatedForFurthestSheepFromGoal(NumberOfSheep, Iteration, SheepX, SheepY, GCMX, GCMY, Goal, CollisionRange)
%Author: Hussein Abbass
%LastModified: 07-Aug-2020
%Explanation: This function checks if the sheep are clusterd, and if not,
%it finds the furthest sheep from the centroid of the cluster
NeighbourhoodRange = CollisionRange * sqrt(2 * NumberOfSheep);
Clustered = false;
FurthestSheepDistance = 0;
FurthestSheepIndex = 0;
X = SheepX(:,Iteration) - GCMX;
Y = SheepY(:,Iteration) - GCMY;
Distances = hypot(X,Y);
NumbersWithinCluster = sum(Distances<=NeighbourhoodRange);
if NumbersWithinCluster == NumberOfSheep
Clustered = true;
else
FurthestSheepDistance = 0;
FurthestSheepIndex = 0;
for i = 1 : NumberOfSheep
Value = FormEquation(GCMX,GCMY,Goal(1),Goal(2),SheepX(i,Iteration),SheepY(i,Iteration));
if Value == 1
Distance = hypot((SheepX(i,Iteration)-GCMX),(SheepY(i,Iteration)-GCMY));
if Distance > FurthestSheepDistance
FurthestSheepDistance = Distance;
FurthestSheepIndex = i;
end
end
end
if FurthestSheepDistance <= NeighbourhoodRange
Clustered = true;
end
end
Target = [NeighbourhoodRange,Clustered,FurthestSheepDistance,FurthestSheepIndex];