-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_script.m
47 lines (40 loc) · 1.07 KB
/
run_script.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
clc
close all
clear all
%define parameters
sideLength = 4;
popSize = 64;
nWorker = 6;
iteration = 10;
logInterval = 2;
%generate a population of genome
pop = Population(popSize, sideLength);
%loop:
for j = 1 : iteration
t0 = tic;
%produce new generation
children = zeros(nWorker, sideLength, sideLength, sideLength);
speeds = zeros(nWorker, 1);
speed = 0;
parfor i = 1 : nWorker
%select parents
parent1 = pop.group{randi(popSize), 1};
parent2 = pop.group{randi(popSize), 1};
%make new genomes
child = pop.crossover(parent1, parent2); %needs testing
child = pop.mutate(child); %needs testing
children(i, :, :, :) = child;
sim = Simulation(child);
speed = sim.evaluate();
speeds(i) = speed;
end
%sort and select
pop = pop.insertSortSelect(children, speeds);
%visualize and save
pop = pop.plotCurve();
if rem(j, logInterval) == 0
pop = pop.save();
end
t_iter = toc(t0);
disp(strcat('iteration: ', num2str(j), ' time: ', num2str(t_iter)));
end