Discussion:
How to use gamultiobj to optimize 2 objective functions in Simulink
(too old to reply)
Faezeh
2015-06-10 19:53:37 UTC
Permalink
Hello;

I am trying to use "gamultiobj" to optimize two objective functions which are being generated in a Simulink model. I am using the following code:

-----------------------------------------------------------------------------------------------------------------------

function [FlowRate] = runtracklsq

SolarTroughSystem_Storage_Heating_PV_Opt % Load the model FlowRate = 0.7; % Initialize model plant variables

options = gaoptimset('PopulationSize',10, 'PlotFcns',{@gaplotpareto}); options=gaoptimset(options,'PopulationType','doubleVector'); P = gamultiobj(@Fitness,1,[],[],[],[],0.2,1.5,options);

function F = Fitness(P)
FlowRate=P;
set_param('SolarTroughSystem_Storage_Heating_PV_Opt/constant','Value',num2str(FlowRate))
% Set sim options and compute function value
myobj = sim('SolarTroughSystem_Storage_Heating_PV_Opt','SrcWorkspace','base');
F = (-1) * myobj.get('yout');
end
end
-----------------------------------------------------------------------------------------------------------------------

When I run the code it gives me the following error:

------------------------------------------------------------------

Subscripted assignment dimension mismatch.

Error in objAndConVectorizer (line 33) Fvals(i,:) = feval(objFcn,(pop(i,:)));

Error in gamultiobjMakeState (line 78) [Score,C,Ceq,isFeas] = objAndConVectorizer(state.Population(initScoreProvided+1:end,:), ...

Error in gamultiobjsolve (line 8) state = gamultiobjMakeState(GenomeLength,FitnessFcn,ConstrFcn,output.problemtype,options);

Error in gamultiobj (line 261) [x,fval,exitFlag,output,population,scores] = gamultiobjsolve(FitnessFcn,nvars, ...

Error in runtracklsq (line 10) P = gamultiobj(@Fitness,1,[],[],[],[],0.2,1.5,options);

Caused by: Failure in user-supplied fitness function evaluation. Cannot continue.

-----------------------------------------------------------------------------------------------------------------------

I put a break point on the line "F = (-1) * myobj.get('yout');" and when I run the code it makes the Simulink model run for 2 times and for the 3rd time I get the above error.

Could you please help me figure out what the problem is?

Thank you
Steven Lord
2015-06-10 20:27:59 UTC
Permalink
Post by Faezeh
Hello;
I am trying to use "gamultiobj" to optimize two objective functions which
*snip*
Post by Faezeh
------------------------------------------------------------------
Subscripted assignment dimension mismatch.
Error in objAndConVectorizer (line 33) Fvals(i,:) =
feval(objFcn,(pop(i,:)));
That suggests to me that your objective function is returning different
sized outputs when called with different inputs. Add a line to your
objective function that displays the SIZE of the output immediately before
it returns. If I'm right, the size displayed immediately before you receive
that error will be different than the size displayed in the previous
iterations.
--
Steve Lord
***@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Faezeh
2015-06-10 22:34:36 UTC
Permalink
Post by Steven Lord
Post by Faezeh
Hello;
I am trying to use "gamultiobj" to optimize two objective functions which
*snip*
Post by Faezeh
------------------------------------------------------------------
Subscripted assignment dimension mismatch.
Error in objAndConVectorizer (line 33) Fvals(i,:) =
feval(objFcn,(pop(i,:)));
That suggests to me that your objective function is returning different
sized outputs when called with different inputs. Add a line to your
objective function that displays the SIZE of the output immediately before
it returns. If I'm right, the size displayed immediately before you receive
that error will be different than the size displayed in the previous
iterations.
--
Steve Lord
To contact Technical Support use the Contact Us link on
http://www.mathworks.com
Hello Steve;

I checked the objective function size and it is always 3601 x 2.
I use the output block in Simulink to transfer the two objective function values to the m.file. As long as I consider just one output for one of the objective functions, the code works. As soon as I add the second output port the mentioned error occurs.

Thank you

Loading...