フィルターのクリア

how can I set the options for Genetic Algorithm and SQP optimization? objective function and constraints are defined but I can not get the result.

7 ビュー (過去 30 日間)
function f=objfun(x)
Rd = x(1); Rb = x(2); bd = x(3);
dR=(Rd-Rb)
Td=4/3*pi*40000*dR^3+pi*3.8*45/0.001*dR^4+2*pi*Rd^2*bd*[15+0.1*(45*Rd/0.001)]
f=-Td
function [c ceq]=constraint(x)
Rd = x(1); Rb = x(2); bd = x(3);
dR=(Rd-Rb)
Td=4/3*pi*40000*dR^3+pi*3.8*45/0.001*dR^4+2*pi*Rd^2*bd*[15+0.1*(45*Rd/0.001)]
Td0=4/3*pi*15*dR^3+pi*0.1*45/0.001*dR^4+2*pi*Rd^2*bd*[15+0.1*(45*Rd/0.001)]
muJ=Rd^4*bd/[(0.069)^4*0.022-(0.065)^4*(bd+0.002)]
f=-Td
g1=1-Td/(50*Td0)
g2=1-muJ/0.25
g3=muJ/0.5-1
g4=Rb/Rd-1
c(1)=g1
c(2)=g2
c(3)=g3
c(4)=g4
ceq=[]
clc
clear all
%GA optimization
% seting lower bounds and upper bouds
LB = [0.030;0.010;0.003];
UB = [0.068;0.020;0.012];
% starting point
% x0 = [0.050;0.0010;0.010];
options = gaoptimset('MutationFcn',@mutationadaptfeasible);
[x,fval,exitflag,output] = ga(@objfun,3,[],[],[],[],LB,UB,@constraint,options);
%SQP optimization
clc
clear all
close all
LB = [0.030;0.010;0.003];
UB = [0.068;0.020;0.012];
x0 = [0.060;0.012;0.010];
options = optimoptions('fmincon','display','iter','Algorithm','sqp','PlotFcn','optimplotfval');
%options = struct('MaxFunctionEvaluations',100000);
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(@objfun,x0,[],[],[],[],LB,UB,@constraint,options)

採用された回答

Walter Roberson
Walter Roberson 2022 年 12 月 12 日
It works for me.
Do not expect these kinds of optimizers to output a message that says something like "Optimization terminated, global minima found!". Some of the linear and quadratic problem solvers can prove that they have found a global minima, but none of the optimizers that accept a function handle can prove that they have found a global minima.
When you have an arbitrary function that is not known to be linear or polynomial , the only way to be sure that you have found a global minima is if you do a mathematical analysis of the function. Otherwise how could you be sure that there is no hidden statement along the lines of if x == sqrt(352395.231135); y = -324932523532; end ?
Therefore the best that the optimizers can do is say that they have found as good of a local minima as your configuration asks them to look at.
%GA optimization
% seting lower bounds and upper bouds
LB = [0.030;0.010;0.003];
UB = [0.068;0.020;0.012];
% starting point
% x0 = [0.050;0.0010;0.010];
options = gaoptimset('MutationFcn',@mutationadaptfeasible);
[x,fval,exitflag,output] = ga(@objfun,3,[],[],[],[],LB,UB,@constraint,options)
Optimization terminated: average change in the fitness value less than options.FunctionTolerance and constraint violation is less than options.ConstraintTolerance.
x = 1×3
0.0680 0.0100 0.0076
fval = -38.8418
exitflag = 1
output = struct with fields:
problemtype: 'nonlinearconstr' rngstate: [1×1 struct] generations: 3 funccount: 7400 message: 'Optimization terminated: average change in the fitness value less than options.FunctionTolerance↵ and constraint violation is less than options.ConstraintTolerance.' maxconstraint: 0 hybridflag: []
%SQP optimization
LB = [0.030;0.010;0.003];
UB = [0.068;0.020;0.012];
x0 = [0.060;0.012;0.010];
options = optimoptions('fmincon','display','iter','Algorithm','sqp','PlotFcn','optimplotfval');
%options = struct('MaxFunctionEvaluations',100000);
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(@objfun,x0,[],[],[],[],LB,UB,@constraint,options)
Iter Func-count Fval Feasibility Step Length Norm of First-order step optimality 0 4 -2.144608e+01 0.000e+00 1.000e+00 0.000e+00 1.399e+03 1 8 -3.881789e+01 0.000e+00 1.000e+00 8.660e-03 7.137e+02 2 12 -3.884198e+01 1.023e-03 1.000e+00 3.178e-04 8.001e-01 3 16 -3.884193e+01 3.089e-07 1.000e+00 5.510e-06 1.495e-02 4 20 -3.884193e+01 2.784e-13 1.000e+00 1.665e-09 2.800e-07 Feasible point with lower objective function value found.
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 3×1
0.0680 0.0100 0.0076
fval = -38.8419
exitflag = 1
output = struct with fields:
iterations: 4 funcCount: 20 algorithm: 'sqp' message: 'Local minimum found that satisfies the constraints.↵↵Optimization completed because the objective function is non-decreasing in ↵feasible directions, to within the value of the optimality tolerance,↵and constraints are satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The relative first-order optimality measure, 1.324947e-10,↵is less than options.OptimalityTolerance = 1.000000e-06, and the relative maximum constraint↵violation, 2.784439e-13, is less than options.ConstraintTolerance = 1.000000e-06.' constrviolation: 2.7844e-13 stepsize: 1.6647e-09 lssteplength: 1 firstorderopt: 2.8000e-07 bestfeasible: [1×1 struct]
lambda = struct with fields:
eqlin: [0×1 double] eqnonlin: [0×1 double] ineqlin: [0×1 double] ineqnonlin: [4×1 double] lower: [3×1 double] upper: [3×1 double]
grad = 3×1
1.0e+03 * -2.1133 2.1102 -0.0093
hessian = 3×3
1.0e+03 * 0.0206 0.0007 0.1437 0.0007 0.0017 -0.0000 0.1437 -0.0000 1.0199
function f=objfun(x)
Rd = x(1); Rb = x(2); bd = x(3);
dR=(Rd-Rb);
Td=4/3*pi*40000*dR^3+pi*3.8*45/0.001*dR^4+2*pi*Rd^2*bd*[15+0.1*(45*Rd/0.001)];
f=-Td;
end
function [c ceq]=constraint(x)
Rd = x(1); Rb = x(2); bd = x(3);
dR=(Rd-Rb);
Td=4/3*pi*40000*dR^3+pi*3.8*45/0.001*dR^4+2*pi*Rd^2*bd*[15+0.1*(45*Rd/0.001)];
Td0=4/3*pi*15*dR^3+pi*0.1*45/0.001*dR^4+2*pi*Rd^2*bd*[15+0.1*(45*Rd/0.001)];
muJ=Rd^4*bd/[(0.069)^4*0.022-(0.065)^4*(bd+0.002)];
f=-Td;
g1=1-Td/(50*Td0);
g2=1-muJ/0.25;
g3=muJ/0.5-1;
g4=Rb/Rd-1;
c(1)=g1;
c(2)=g2;
c(3)=g3;
c(4)=g4;
ceq=[];
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by