% OBJECTIVE FUNCTION
f = @(x) [-25*(x(:,1)-2).^2 - (x(:,2)-2).^2 - (x(:,3)-1).^2 - (x(:,4)-4).^2 - (x(:,5)-1).^2, sum(x.^2,2)]

% OPTIMIZATION SETTINGS
o = struct	% initializing struct 
g1 = @(x) x(:,1) + x(:,2) - 2
g2 = @(x) 6 - x(:,1) - x(:,2)
g3 = @(x) 2 + x(:,1) - x(:,2)
g4 = @(x) 2 - x(:,1) + 3*x(:,2)
g5 = @(x) 4 - (x(:,3) - 3).^2 - x(:,4)
g6 = @(x) (x(:,5) - 3).^2 + x(:,6) - 4 
o.g = @(x) g1(x).*(g1(x)<0) + g2(x).*(g2(x)<0) + g3(x).*(g3(x)<0) + g4(x).*(g4(x)<0) + g5(x).*(g5(x)<0) + g6(x).*(g6(x)<0)	% constraints
o.d = 6	% dimension of decision variable
o.lb = [0 0 1 0 1 0]	% lower bounds
o.ub = [10 10 5 6 5 10]	% upper bounds

% ALGORITHM OPTIONS

o.maxit = 250	% number of iterations 
o.pop = 100	% number of population 

% OPTIMIZATION 
rng(0)	% for tractability 
[popPos,popFront,popCost,popInfo,traceIt] = nsga2(f,o)	% running minimization  

% ANIMATION
% Uncomment the following code to generate animation % 
% rng(0)
% [~,~,~,~,~,info] = nsga2(f,o)
% info.plot = 'pareto'
% info.animate = true	% plot animation 
% info.animfreq = 14	% frame frequency 
% optimview('nsga2',info)