1、 objective(i).range = . sorted(i).individual(length(sorted(i).individual) - . sorted(i).individual(1); % Maximum and minimum objectives value for the ith objective% Caluclate the crowding distance for front one. distance(j).individual = distance(j).individual + . (sorted(i).individual(j + 1) - sorte
2、d(i).individual(j - 1)/. objective(i).range; y(sorted(i).index(j),M + V + 2) = distance(j).individual;/PRE Published with MATLAB 7.0function f = genetic_operator(parent_chromosome,pro,mu,mum);% This function is utilized to produce offsprings from parent chromosomes.% The genetic operators corssover
3、and mutation which are carried out with% slight modifications from the original design. For more information read% the document enclosed.N,M = size(parent_chromosome);switch prop = 1;was_crossover = 0;was_mutation = 0;l_limit = 0;u_limit = 1; N if rand(1) 0.9 child_1 = ; child_2 = ; parent_1 = round
4、(N*rand(1); if parent_1 1 parent_1 = 1; parent_2 = round(N*rand(1); if parent_2 parent_2 = 1; while isequal(parent_chromosome(parent_1,:),parent_chromosome(parent_2,:) parent_1 = parent_chromosome(parent_1,: parent_2 = parent_chromosome(parent_2,: for j = 1 : V % SBX (Simulated Binary Crossover) % G
5、enerate a random number u(j) = rand(1); if u(j) u_limit child_1(j) = u_limit; elseif child_1(j) child_2(j) = u_limit; elseif child_2(j) child_2(j) = l_limit; child_1(:,V + 1: M + V) = evaluate_objective(child_1,pro); child_2(: M + V) = evaluate_objective(child_2,pro); was_crossover = 1; was_mutation
6、 = 0; parent_3 = round(N*rand(1); if parent_3 parent_3 = 1; % Make sure that the mutation does not result in variables out of % the search space. For both the MOPs the range for decision space % is 0,1. In case different variables have different decision % space each variable can be assigned a range
7、. child_3 = parent_chromosome(parent_3,: r(j) = rand(1); if r(j) child_3(j) = u_limit; elseif child_3(j) child_3(j) = l_limit; child_3(: M + V) = evaluate_objective(child_3,pro); was_mutation = 1; was_crossover = 0; if was_crossover child(p,:) = child_1; child(p+1,:) = child_2; was_cossover = 0; p =
8、 p + 2; elseif was_mutation) = child_3(1,1 : M + V); p = p + 1;f = child;Published with MATLABfunction f = initialize_variables(N,problem)% function f = initialize_variables(N,problem)% N - Population size% problem - takes integer values 1 and 2 where,% 1 for MOP12 for MOP2% This function initialize
9、s the population with N individuals and each% individual having M decision variables based on the selected problem.% M = 6 for problem MOP1 and M = 12 for problem MOP2. The objective space% for MOP1 is 2 dimensional while for MOP2 is 3 dimensional.% Both the MOPs has 0 to 1 as its range for all the
10、decision variables.min = 0;max = 1; M = 6; K = 8; M = 12; K = 15; % Initialize the decision variables f(i,j) = rand(1); % i.e f(i,j) = min + (max - min)*rand(1); % Evaluate the objective function f(i,M + 1: K) = evaluate_objective(f(i,:),problem); Non-Donimation SortThis function sort the current po
11、pultion based on non-domination. All the individuals in the first front are given a rank of 1, the second front individuals are assigned rank 2 and so on. After assigning the rank the crowding in each front is calculated. front = 1;% There is nothing to this assignment, used only to manipulate easil
12、y in% MATLAB.F(front).f = ;individual = ; % Number of individuals that dominate this individual individual(i).n = 0; % Individuals which this individual dominate individual(i).p = ; dom_less = 0; dom_equal = 0; dom_more = 0; for k = 1 : if (x(i,V + k) x(j,V + k) dom_less = dom_less + 1; elseif (x(i,
13、V + k) = x(j,V + k) dom_equal = dom_equal + 1; dom_more = dom_more + 1; if dom_less = 0 & dom_equal = M individual(i).n = individual(i).n + 1; elseif dom_more = 0 & individual(i).p = individual(i).p j; if individual(i).n = 0 x(i,M + V + 1) = 1; F(front).f = F(front).f i;% Find the subsequent frontsw
14、hile isempty(F(front).f) Q = ; for i = 1 : if isempty(individual(F(front).f(i).p) for j = 1 : length(individual(F(front).f(i).p) individual(individual(F(front).f(i).p(j).n = . individual(individual(F(front).f(i).p(j).n - 1; if individual(individual(F(front).f(i).p(j).n = 0 x(individual(F(front).f(i)
15、.p(j),M + V + 1) = . front + 1; Q = Q individual(F(front).f(i).p(j); front = front + 1; F(front).f = Q;temp,index_of_fronts = sort(x(:,M + V + 1); length(index_of_fronts) sorted_based_on_front(i,:) = x(index_of_fronts(i),:current_index = 0;% Find the crowding distance for each individual in each fro
16、ntfor front = 1 : (length(F) - 1) objective = ; distance = 0; y = ; previous_index = current_index + 1;) = sorted_based_on_front(current_index + i,: current_index = current_index + i; % Sort each individual based on the objective sorted_based_on_objective = ; sorted_based_on_objective, index_of_obje
17、ctives = . sort(y(: length(index_of_objectives) sorted_based_on_objective(j,:) = y(index_of_objectives(j),: f_max = . sorted_based_on_objective(length(index_of_objectives), V + i); f_min = sorted_based_on_objective(1, V + i); y(index_of_objectives(length(index_of_objectives),M + V + 1 + i). = Inf; y
18、(index_of_objectives(1),M + V + 1 + i) = Inf; length(index_of_objectives) - 1 next_obj = sorted_based_on_objective(j + 1,V + i); previous_obj = sorted_based_on_objective(j - 1,V + i); if (f_max - f_min = 0) y(index_of_objectives(j),M + V + 1 + i) = Inf; y(index_of_objectives(j),M + V + 1 + i) = . (n
19、ext_obj - previous_obj)/(f_max - f_min); distance = ; distance(:,1) = zeros(length(F(front).f),1);,1) = distance(:,1) + y(:,M + V + 1 + i); y(:,M + V + 2) = distance; y = y(:,1 : M + V + 2); z(previous_index:current_index,:) = y;f = z();Main FunctionMain program to run the NSGA-II MOEA. Read the cor
20、responding 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. corresponds to MOP1 and corresponds to MOP2. ContentsInitialize the variables Sort the in
21、itialized population Start the evolution process Result Visualize Initialize the variablesDeclare the variables and initialize their values pop - population gen - generations pro - problem numberpop = 200;gen = 1;pro = 1; % M is the number of objectives. % V is the number of decision variables. In t
22、his case it is % difficult to visualize the decision variables space while the % objective space is just two dimensional.% Initialize the populationchromosome = initialize_variables(pop,pro);Sort the initialized populationSort the population using non-domination-sort. This returns two columns for ea
23、ch 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% The following are performed in each generation% Select the parents% Perfrom crossover and Mutation op
24、erator% Perform Selection gen % Select the parents % Parents are selected for reproduction to generate offspring. The % original NSGA-II uses a binary tournament selection based on the % crowded-comparision operator. The arguments are % pool - size of the mating pool. It is common to have this to be half the % population size. % tour - Tournament siz
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1