-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain Program.m
44 lines (37 loc) · 1.28 KB
/
Main Program.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
clear
close all
clc
%% Some initialization
number_of_cities = 25;
number_of_parents = 20;
number_of_parents_in_next_generation = 10;
number_of_iteration = 1000 ;
approach = 1; % first approach: 1 , second approach: 2
% dimention = 3 % This dimention can be used if the range of each
% dimenttion is the same
%% Generate cities
cities = GenerateCities(number_of_cities);
%% Generate initial parents
parents = GenerateParents(number_of_cities, number_of_parents);
%% Generate next generation
next_generation = parents;
plot_steps = [1,100 , 500 , 1000 , 2000 , 3000 , 4000 , 5000 , 7000 , 10000, 100000 , 1000000];
mean_cost = zeros(1,number_of_iteration);
least_cost = zeros(1,number_of_iteration);
for i = 1:number_of_iteration
[next_generation,next_generation_cost ] = NextGeneration(cities , next_generation , number_of_parents_in_next_generation,approach);
least_cost(i) = min(next_generation_cost);
mean_cost(i) = mean(next_generation_cost);
% min(next_generation_cost)
if (any(plot_steps == i))
disp(i)
[minimum ,index] = min(next_generation_cost);
PlotCities(cities(next_generation(:,index),:),minimum , i);
end
end
%% Plot the trend
figure();
plot(least_cost , "r");
hold on ;
plot (mean_cost,"b");
legend("Least cost" , "mean cost");