Main Function
Main program to run the NSGA-II MOEA. Read the corresponding documentation to learn more about multiobjective optimization
using evolutionary algorithms. initialize_variables has two arguments; First being the population size and the second the
problem number. '1' corresponds to MOP1 and '2' corresponds to MOP2.
Contents
Initialize the variables
Declare the variables and initialize their values pop - population gen - generations pro - problem number
pop = 200;
gen = 1;
pro = 1;
switch pro
case 1
M = 2;
V = 6;
case 2
M = 3;
V = 12;
end
chromosome = initialize_variables(pop,pro);
Sort the initialized population
Sort the population using non-domination-sort. This returns two columns for each individual which are the rank and the crowding
distance corresponding to their position in the front they belong.
chromosome = non_domination_sort_mod(chromosome,pro);
Start the evolution process
for i = 1 : gen
pool = round(pop/2);
tour = 2;
parent_chromosome = tournament_selection(chromosome,pool,tour);
mu = 20;
mum = 20;
offspring_chromosome = genetic_operator(parent_chromosome,pro,mu,mum);
[main_pop,temp] = size(chromosome);
[offspring_pop,temp] = size(offspring_chromosome);
intermediate_chromosome(1:main_pop,:) = chromosome;
intermediate_chromosome(main_pop + 1 : main_pop + offspring_pop,1 : M+V) = ...
offspring_chromosome;
intermediate_chromosome = ...
non_domination_sort_mod(intermediate_chromosome,pro);
chromosome = replace_chromosome(intermediate_chromosome,pro,pop);
if ~mod(i,10)
fprintf('%d\n',i);
end
end
Result
Save the result in ASCII text format.
save solution.txt chromosome -ASCII
Visualize
The following is used to visualize the result for the given problem.
switch pro
case 1
plot(chromosome(:,V + 1),chromosome(:,V + 2),'*');
title('MOP1 using NSGA-II');
xlabel('f(x_1)');
ylabel('f(x_2)');
case 2
plot3(chromosome(:,V + 1),chromosome(:,V + 2),chromosome(:,V + 3),'*');
title('MOP2 using NSGA-II');
xlabel('f(x_1)');
ylabel('f(x_2)');
zlabel('f(x_3)');
end