using gamultiobj with 24 variables

My fitness function (fit_KotPol) calculate two values for 24 variables. I want to define the inti
fitnessfcn = @fit_KotPol;
nvars = 24;
lb=[22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 0 0 0 0 0 0 0 0 0 0 0 0];
ub=[172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 140 140 140 140 140 140 140 140 140 140 140 140];
A = [ ]; b = [ ]; Aeq = [ ]; beq = [ ];
startTime = tic;
options = optimoptions('gamultiobj','UseParallel',true,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
[x,fval,exitflag,output] = gamultiobj(fitnessfcn,nvars,lb,ub,options);
stopTime = toc(startTime);
I got the error
Error using gamultiobj (line 281)
GAMULTIOBJ requires the following inputs to be of data type double: 'Aeq'.
Help me to use the gamultiobj

Answers (2)

Stephan
Stephan on 23 Sep 2018
Edited: Stephan on 23 Sep 2018
Hi,
the input syntax for gamultiobj has no option for passing lb and ub to gamultiobj without also passing A,b Aeq, beq. You defined them all, but you dont use them in your function call.
Use:
[x,fval,exitflag,output] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
Best regards
Stephan

16 Comments

Hi Stephan thank you for the reply. One following question for the same problem. I can't see the pareto plot and blank graph is appeared with the message "gaplotpareto not supported for this algorithm". Can you pl explain. Thanks.
I would expect this to work:
options = optimoptions(@gamultiobj,'UseParallel',true,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
I used the same as shown above, but didn't work. I think the problem is with defining my objectives. It is as follows.
function [A, B] = fit_KotPol( x )
function name: fit_KotPol calculate the two objectives (A and B) using xi (24 vars). So I have defined fitnessfcn = @fit_KotPol; nvars = 24;
From the above codes what I got one set of x values and one value for objective. What I want to have an array of 2 obtectives as points at Pareto plot and corresponding x values (sets of 24 values). Please help me to revise the code.
Can you attach the code you have tried so far?
function [A, B] = fit_KotPol( x )
...several calculations
A=
B=
end
The above function (fit_KotPol(x)) is for calculating the A and B, which are the values for two objectives for each set x values.
fitnessfcn = @fit_KotPol;
nvars = 24;
lb=[22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 22.2 0 0 0 0 0 0 0 0 0 0 0 0];
ub=[172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 172.9 140 140 140 140 140 140 140 140 140 140 140 140];
A = [ ]; b = [ ];
Aeq = [ ]; beq = [ ];
startTime = tic;
options = optimoptions('gamultiobj','UseParallel',true,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
[x,fval,exitflag,output] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
stopTime = toc(startTime);
fprintf('The number of points on the Pareto front was: %d\n', size(x,1));
fprintf('The average distance measure of the solutions on the Pareto front was: %g\n', Output.averagedistance);
fprintf('The spread measure of the Pareto front was: %g\n', Output.spread);
fprintf('The number of generations was : %d\n', Output.generations);
You could try:
function A = fit_KotPol(x)
...several calculations
A(1) = A;
A(2) = B;
end
Since this is a difference to the examples given in the documentation. The objectives in documentation are stored in one vector. I could imagine that this is the problem.
thank you for the reply. This optimization runs for 3 days, although I use parallel operation. Do you know any other method to increase the speed of optimization. Also please tell me how to measure the optimization time. I got value for start time as 69686032139 and stop time as 300833.162771188 from the previous run. I cannot figure out what those values mean.
parallel does not have to be fast. I recommend you to vectorize the function. then you can choose the option
'UseVectorized',true
instead of parallel.
I read the documents of UseVectorized. I don't how to write indexing of vaiable when calling a function for optimization. variables x is 24 long array (24 vars) and population size =200. please help.
function [obj] = fit_KotPol( x)
P = x(:,1:12); Q =x(:,13:24);
This code bring the error "When 'Vectorized' is 'on', your fitness function must return a vector of length equal to the size of the population."
Can you attach the code of your function?
fitnessfcn = @ fit_KotPol;
nvars = 24;
options = optimoptions('gamultiobj','UseVectorized',true,'PopulationSize',200,'InitialPopulationMatrix',Initial,'PlotFcn',{@gaplotpareto,@gaplotscorediversity});
[x,fval,exitflag,output,population,scores] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
function [obj] = fit_KotPol(x)
P = x(:,1:12); Q =x(:,13:24);
...several steps for calculation
obj(1) =
obj(2) =
further to above, there are two for loops inside the function (fit_KotPol). Actually codes for the function are 500 lines.
for j=1:1000
for 1=1:12
end
end
obj(1)=
obj(2)=
How often does your code run? Is it worth revising the code, or is it better to wait 3 days for the calculation to finish, because the code is only used a few times?
yes. you are right, it is few times. So better to wait 3 days. One last question, before I start the new model run. From the below code can I get the set of solution (values) for variables (24 x n) for n Pareto points. For 200 population, 100 generation what is the n?
[x,fval,exitflag,output,population,scores] = gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options);
The number of pareto points returned by gamultiobj is not known in advance.
x will be m by nvars, so something by 24 in your case, where m is however many pareto points the function detected during the limits it was given on execution.
Thank you Walter Roberson and Stephan Jung for the reply. Those are really helpful.

Sign in to comment.

Thushara De Silva
Thushara De Silva on 27 Sep 2018
Edited: Walter Roberson on 28 Sep 2018
Further to the above question how can I initialize the population? I want to give initial values for 24 variables as below.
InitialPopulationMatrix_Data = [93.2 66.6 40 59 78 97 116 135 154 172.9 146.3 119 39 76 104 120 107 58 80 80 53 61 60 36]
However, the population size is 200 as default. How do I do it?
Please help.

1 Comment

When you supply a population matrix in the options, if the number of rows you provide is less than the population size, then it will initialize the remaining rows randomly.

Sign in to comment.

Asked:

on 23 Sep 2018

Commented:

on 28 Sep 2018

Community Treasure Hunt

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

Start Hunting!