Asking for Guidance to Weighted-Sum Multiobjective Optimization
Ältere Kommentare anzeigen
Hi,
Frankly speaking I am quite new in multiobjective and also using MATLAB. I have two objective functions which are quadratic.
One I define f1(x) as
and the second one f2(x)
with the same constraints let say A1x = b1, A2x >= b2 .
Somehow I want to create them as a weighted sum w1 * f1(x) + w2 * f2(x).
But I am not sure whether the code that I have written is correct or not. In the end, I want to find the pareto of the objective function. Could you suggest me what's not correct with the code below?
clc, clear, close all;
% c = [36., 44., 50.50, 64.5, 44.50, 37.];
% c = [51., 42.50, 62., 76.50, 52.50];
% c = [62., 97.50, 95.50, 59.];
% c = [117.5, 87.50, 119.];
c = [187., 165.5];
s = [30, 36, 41, 44, 39, 31];
A1 = kron(eye(length(s)), ones(1,length(c))); % Equality constraints
A2 = kron(ones(1,length(s)), eye(length(c))); % Inequality constraints
b1 = ones(1,length(s))';
b2 = ones(1,length(c))';
%% Set parameter for objective function 1
alpha = 0.7;
q = kron(s, eye(length(c)));
% Positive - negative definite
% Q = 2 * (q' * q);
% Negative Definite
Q = 2 * (q' * q - (max(eig(q' * q)) + alpha) * eye(length(q' * q)));
% Positive Definite
% Q = 2 * (q' * q + (min(eig(q' * q)) + alpha) * eye(length(q' * q)));
% p and r value
p = -2 * c * q;
r = c * c';
%% Objective function 2
m_values = length(c);
% Initialize pairs
pairs = [];
% Generate pairs
for i = 1:(m_values - 1)
for j = (i + 1):m_values
pairs = [pairs; [i, j]];
end
end
% Display pairs
fprintf('For m = %d, pairs are: %s\n', m_values, mat2str(pairs));
% Initialize matrices_B and matrices_P
matrices_B = cell(1, length(pairs));
matrices_P = cell(1, length(pairs));
% Populate matrices_B and matrices_P
for k = 1:pairs
i = pairs(k, 1);
j = pairs(k, 2);
% Initialize matrix_B
matrix_B = zeros(m_values, m_values);
matrix_B(i, i) = 1;
matrix_B(j, j) = 1;
matrices_B{k} = matrix_B;
% Initialize matrix_P using Kronecker product
matrix_P = kron(s' * s, matrix_B);
matrices_P{k} = matrix_P;
end
% Sum all P_i matrices
sum_matrices_P = sum(cat(3, matrices_P{:}), 3);
% Calculate the final P matrix
% Set P to be negative definite
P = 2 * (sum_matrices_P - (max(eig(sum_matrices_P)) + alpha) * eye(size(sum_matrices_P)));
% P = 2 * (sum_matrices_P );
%% Optimize
options = optimoptions('gamultiobj','PlotFcn','gaplotpareto','UseParallel',true,'UseVectorized',true,'HybridFcn','fgoalattain');
% options = optimoptions('paretosearch','PlotFcn',{'psplotparetof' 'psplotparetox'});
x = optimvar("x",length(c)*length(s),'Type','continuous','LowerBound',0,'UpperBound',1);
w1 = 0.7;
w2 = 1 - w1;
w = [w1, w2]; % Weight vector
prob = optimproblem;
obj1 = 0.5 * x' * Q * x + p * x + r;
obj2 = 0.5 * x' * P * x;
% Combine objectives with the weighted sum
% prob.Objective.obj = w(1) * obj1 + w(2) * obj2;
% Represent the combined objective as two separate objectives
prob.Objective.obj1 = w(1) * obj1;
prob.Objective.obj2 = w(2) * obj2;
cons1 = A1 * x == b1;
cons2 = A2 * x >= b2;
% cons3 = obj2 <= 0.3;
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
% prob.Constraints.cons3 = cons3;
show(prob)
[sol,fval] = solve(prob, Solver="paretosearch");
% Sort the Pareto front solutions
[sorted_obj1, sort_index] = sort(sol.obj1);
sorted_obj2 = sol.obj2(sort_index);
h = paretoplot(sol);
% grid on
% axis auto
h.Marker = "hexagram";
h.MarkerEdgeColor = "b";
% figure;
% scatter(sol.obj1, sol.obj2, Marker="hexagram", MarkerFaceColor="flat", MarkerEdgeColor="flat")
% hold on
% xlabel("obj1");
% ylabel("obj2");
% title("Pareto Front");
% grid on
Thank you!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Multiobjective Optimization finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!