HOW CAN I CHANGE THE disp(['Iteration #', num2str(gen), ' completed. Archive size: ',…
- User
HOW CAN I CHANGE THE disp(['Iteration #', num2str(gen), ' completed. Archive size: ', num2str(size(archive.pop, 1))]);. MAKE IT ONLY DISPLAY 10 ITERATION THEN 10 THEN
function [paretoFront, paretoSet, Trajectories, fitness_history, position_history] = MOEMA(NPop, T, lb, ub, dim, FITNESSFCN) % Multi-Objective Evolutionary Mating Algorithm (MOEMA) with improvements
% Preallocation fitness_history = zeros(NPop, T, 2); % Assuming 2 objectives position_history = zeros(NPop, T, dim); Trajectories = zeros(dim, T);
% Generation of initial population pop = initialization(NPop, dim, ub, lb); pop_dad = pop(1:NPop/2, :); % Eqn (1) in the paper pop_mum = pop(NPop/2+1:end, :); % Eqn (2) in the paper
% Evaluation of objective function for initialization obj_dad = evaluate_population(pop_dad, FITNESSFCN); obj_mum = evaluate_population(pop_mum, FITNESSFCN); obj = [obj_dad; obj_mum];
% Initialize archive with non-dominated solutions archive = update_archive([], [], pop, obj);
for gen = 1:T % Start iteration k1 = randperm(NPop/2); k2 = randperm(NPop/2); k1x = pop_dad(k1, :); k2x = pop_mum(k2, :);
code - Assistant
To modify the existing code to display a message every tenth iteration (i.e., on iterations (10, 20, 30, \ldots)) instead of after every iteration, you can add a conditional statement to check whether the current iteration number is divisible by 10. Here’s how you can implement this change:
matlabfor gen = 1:T % Start iteration % ... (the body of the loop remains unchanged) % Update the archive, history and trajectories archive = update_archive(archive.pop, archive.obj, pop, obj); fitness_history(:, gen, :) = obj; position_history(:, gen, :) = pop; if ~isempty(archive.pop) Trajectories(:, gen) = archive.pop(randi(size(archive.pop, 1)), :)'; end % Display progress every 10 iterations if mod(gen, 10) == 0 disp(['Iteration #', num2str(gen), ' completed. Archive size: ', num2str(size(archive.pop, 1))]); end end