Question Regarding MultiObjective Optimization - gamultiobj

9 views (last 30 days)
Hi. I want to create a model for multi objective optimization.
I have 300 items and three variables for each. Objective is the a function of using 300 items * 3 variables. So I don't want to write 900 seperate variables in the function, if possible. Thanks a lot in advance.
My code is as follows. Also I receive the following error.
error message
++
Not enough input arguments.
Error in globalfun (line 6)
y(1) = sum((1-x(1,1)*0.99)+(1-x(1,2)*0.95)+(1-x(1,3)*0.90));
Error in MCICv2 (line 26)
[x,fval] = gamultiobj(globalfun,numberOfVariables);
++
Script part
++
clc;clear all;close all;
global leadtime
data = readmatrix('Data.xlsx');
data(:,1) = [1:301];
ProductCodes = data(:,1);
LeadTime = data(:,4); %This is the value I use for Multi-Objective Optimization
[widthdata, heightdata]= size(data);
numberOfVariables = i*3;
[x,fval] = gamultiobj(globalfun,numberOfVariables);
++
Function Part
+++
function y = globalfun(x)
global LeadTime
y(1) = sum((1-x(:,1)*0.99)+(1-x(:,2)*0.95)+(1-x(:,3)*0.90)); %minimize the sum of all 301 items
y(2) = (x(:,1)*norminv(0.99))+(x(:,2)*norminv(0.95))+(x(:,3)*norminv(0.90))*sqrt(LeadTime(:)); %minimize the sum of this function for 301 items
end
+++
  3 Comments
Fatih Yigit
Fatih Yigit on 25 Jan 2022
To be more precise; I attach the script, function, error in the following lines. If I manually assign x e.g [1:301] function works. But not via "gamultiobj".
This is the main script
++
clc;clear all;close all;
global LeadTime; %301 items
data = readmatrix('Data.xlsx');
data(:,1) = [1:301];
ProductCodes = data(:,1);
LeadTime = data(:,4); %This is the value I use for Multi-Objective Optimization
[widthdata, heightdata]= size(data);
result = gamultiobj(globalv6, 903);
++
this is the function
+++
function y = globalv6(x)
global LeadTime
[width, height] = size(LeadTime); %width is 301
j=0;
for i=1:3:(3*width)
j=j+1;
result(j,1) = x(i)+x(i+1)+x(i+2);
result(j,2) = ((1-x(i)*0.99)+(1-x(i+1)*0.95)+(1-x(i+2)*0.90));
end
y(1) = sum(result(:,1));
y(2) = sum(result(:,2));
end
++
error;
Not enough input arguments.
Error in globalv6 (line 8)
result(j,1) = x(i)+x(i+1)+x(i+2);
Error in MCICv3 (line 13)
result = gamultiobj(globalv6, 903);

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 26 Jan 2022
I have a hard time understanding you because you use vocabulary that is not standard. You say that you have items. I ask about control variables and data. Is an item a control variable or data?
data(:,1) = [1:301];
I wonder whether this should be transposed:
data(:,1) = [1:301]';
You show your function call as
result = gamultiobj(globalv6, 903);
Is globalv6 a function handle? I mean, I would expect the function call to be
result = gamultiobj(@globalv6, 903); % Note the @ sign
But the more important question is, do you have no constraints on x, not even bounds? For example, should your x variables be positive? Less than 1? I think so, so you would want to incorporate bounds
lb = zeros(1,903);
ub = ones(1,903);
result = gamultiobj(@globalv6, 903,[],[],[],[],lb,ub);
Alan Weiss
MATLAB mathematical toolbox documentation

More Answers (1)

Fatih Yigit
Fatih Yigit on 26 Jan 2022
Thanks for your help. You are right. Items are actually that have values used as parameters.
I now know that the main problem is not using "@".
My model will have multiple constraints but I just want to start understanding the use use of "gamultiobj" first. Now it is clear.
For the time being mty problem is solved. Again thanks for your help.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by