How can I ensure the nonlinear constraints are met before running the objective function?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I am using te Pareto front function available from the MATLAB Global Optimisation toolbox with 6 input variables, in conjunction with a simscape model. The model consists of 2 members and 2 revolute joints. The 6 input variables are:
[joint 1 initial angle, joint 2 initial angle, joint 1 lower limit, joint 1 upper limit, joint 2 lower limit, joint 2 upper limit]
you can see below that the pareto function is similar to the recommended from the documentation on mathworks.
set_param('SimpleV1_Joint_Min_and_Max_Limits','FastRestart','off')
Pterosaur_Parameters %Loading in model parameters
Weight_Obj1 = 0.7;
options = optimoptions('gamultiobj','PopulationSize',60,...
'ParetoFraction',Weight_Obj1,'PlotFcn',@gaplotpareto);
lb = [0 0 0 0 0 0];
ub = [180 360 360 360 360 360];
set_param('SimpleV1_Joint_Min_and_Max_Limits','SimMechanicsOpenEditorOnUpdate','off')
set_param('SimpleV1_Joint_Min_and_Max_Limits','FastRestart','on')
[solution,ObjectiveValue] = gamultiobj(@Angle_Lim_FUN,6,[],[],[],[],lb,ub,@NONLCON,options);
This is the objective function where I run the Simulink, simscape model and minimize my desired outputs.
function [f] = Angle_Lim_FUN(x)
Arm = evalin('base', 'Arm');
Arm.One.Angle.Initial = x(1); %Applying variables to the model
Arm.Two.Angle.Initial = x(2);
Arm.One.Angle.Min = x(3);
Arm.One.Angle.Max = x(4);
Arm.Two.Angle.Min = x(5);
Arm.Two.Angle.Max = x(6);
assignin('base', 'Arm', Arm);
out = sim('SimpleV1_Joint_Min_and_Max_Limits'); %running the model
Z = out.yout{2}.Values.Data;
X_Velocity = out.yout{4}.Values.Data;
%Objective functions to be minimised
f(1) = 100 - max(Z); % Max Height
f(2) = 100 - X_Velocity(find(Z==max(Z))); % Lateral Velocity at max height
end
This is the non linear constraint for the pareto function:
function [c, ceq] = NONLCON(x)
ceq = 0;
c = zeros(6,1);
c(1) = -(x(1)-x(3));%initial larger than min
c(2) = -(x(4)-x(1));%Initial smaller than max
c(3) = -(x(2)-x(5));%initial larger than mini
c(4) = -(x(6)-x(2));%Initial smaller than max
c(5) = -(x(4)-x(3));%max larger than min
c(6) = -(x(6)-x(5));%max larger than min
end
The goal of the non linear constraint function is to ensure no error occurs in the simulink model as this will stop the Pareto front process.
However, this is not the case all of the time. Sometimes when I run the script, the Pareto front begins compiling, but most of the time when I run the script, an error occurs: the lower bound must be strictly less than the upper bound.
This is the purpose of the nonlinear constraints.
How can I ensure that the nonlinear constraints are satisfied before the objective function is executed to avoid this error entierly?
Kind regards,
Barnaby Pine
댓글 수: 0
채택된 답변
Alan Weiss
2022년 3월 3일
You are in luck: all of your "nonlinear" constraints are, in fact, linear constraints. Simply rewrite your constraints as linear constraints (see Linear Constraints) and they will be satisfied at every iteration by default.
Alan Weiss
MATLAB mathematical toolbox documentation
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Model Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!