-
Notifications
You must be signed in to change notification settings - Fork 1
/
foraging_with_Vornoi.m
54 lines (45 loc) · 1.24 KB
/
foraging_with_Vornoi.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
% Create an environment of length x length
length = 500;
data = 150.*ones(length,length);
nest = round(length/2);
% Create APF environment
ph_size = 5;
APF_size = round(length/ph_size)+1;
APF = 255.*ones(APF_size,APF_size);
%Create a 40x40 food source at x_food,y_food
data = spawn_food(data);
% Initializing
% Max Iterations
max_iter = 2000;
% Robot Spawn position;
N = 10;
[x,y] = spawn_robot(N, nest,length);
for i = 1:N
data(x(i),y(i)) = 255;
end
% Food found flag
found = 0;
% Cover the centroids of Voronoi regions
for k = 1:N
s = levy_step;
[dx,dy] = rand_direction;
[x(k), y(k), data, APF] = next_step(x(k), y(k), s, dx, dy, data, APF, nest);
end
[x, y, data, classifications] = voronoi_coverage(x,y,data,APF);
figure(2);
image(classifications.*(255/N))
colormap(turbo(256));
for i = 1:max_iter
for k = 1:N
%s = levy_step;
%[dx,dy] = rand_direction;
[s,dx,dy] = step_within_voronoi(x(k),y(k),classifications(x(k),y(k)),classifications);
[x(k), y(k), data, APF] = next_step(x(k), y(k), s, dx, dy, data, APF, nest);
end
APF = APF_decay(APF);
% Display it.
display_sim(data,APF);
display(i);
end
% Display it.
display_sim(data,APF);