Problems with fmincon for design optimization
Mostrar comentarios más antiguos
Hi everyone,
I am usign fmincon for the optimization of my problem. details and the source code of problem are provided below. As can be seen there are 12 design variables that should be optimized. There are several random variables and constraints. Two of the constraints “Pfo and Pfa” are for calculating failure probability using MonteCarlo method. My code is not written properly and for example these two constraints are not controled during optimization.
Any solution?


Matlab code is written in four separate files:
1- Main code:
clc;clear all;close all;
tic
objective = @objecfun;
% Optimization Variables: d=[a,b,c,B,hc,hd,t,r,Bt,al,as,at]
% Initial Guess
x0 = [2; 1; 6; 4.5; 4; 2.5; 1.75; 3.5; 4.5; 0.5; 0.5; 0.5];
% Statistical Model Parameters
% Hs = normrnd(2.5,0.11);
% T = normrnd(5,1.5);
% gamma = normrnd(26,0.11);
% Nod = normrnd(1.25,0.375);
% Kd = normrnd(1.075,0.0375);
% S = (2*pi().*Hs)/9.81./(T.^2);
% a = normrnd(2.5,0.25); a is x(1)
% b = normrnd(1.25,0.125); b is x(2)
% c = normrnd(6,0.5); c is x(3)
% B = normrnd(5.5,0.25); B is x(4)
% al = normrnd(0.59,0.0963); al is x(10)
% as = normrnd(0.59,0.0963); as is x(11)
% Variable Bounds
lb = [1; 0.5; 5; 3; 3; 1; 0.5; 1; 3; 0.4; 0.4; 0.4];
ub = [3; 1.5; 7; 6; 5; 4; 3; 6; 6; 0.59; 0.59; 0.59];
% Show Initial Objective
disp(['Initial Objective: ' num2str(objective(x0))])
% Linear Constraints
A = [0,0,-1,0,0,0,-1,0,0,0,0,0];
b = -5.99;
Aeq = [1,1,1,0,-1,0,0,0,0,0,0,0;
0,0,0,0,0,0,-2,1,0,0,0,0];
beq = [5.99;0];
% Nonlinear Constraints
nonlincon = @nonlconstr;
% Optimize with fmincon
%[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]
% = fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS)
options = optimoptions('fmincon','Algorithm','active-set','PlotFcn',{@optimplotfval},'display','iter');
[x,fval,exitflag,output] = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon,options);
% Show Final Objective
disp(['Final Objective: ' num2str(objective(x))])
% Print Solution
disp('Solution')
disp(['a = ' num2str(x(1))])
disp(['b = ' num2str(x(2))])
disp(['c = ' num2str(x(3))])
disp(['B = ' num2str(x(4))])
disp(['hc = ' num2str(x(5))])
disp(['hd = ' num2str(x(6))])
disp(['t = ' num2str(x(7))])
disp(['r = ' num2str(x(8))])
disp(['Bt = ' num2str(x(9))])
disp(['al = ' num2str(x(10))])
disp(['as = ' num2str(x(11))])
disp(['at = ' num2str(x(12))])
output
toc
2- Objective function:
function f = objecfun(x)
Val = x(1).*(x(1)./tan(x(10)) + x(3)./tan(x(10))) + (x(1)./2).*(2.*x(4) - x(1)./tan(x(10)) - ...
x(1)./tan(x(11))) + x(1).*x(3)./sin(x(11));
ht = x(1)+x(2)+x(3)-x(5)-x(6);
Vul = x(2).*(x(2)./tan(x(10)) + x(3)./tan(x(10))) + (x(2)./2).*(2.*x(4) - 2*x(1)./tan(x(10)) - ...
2*x(1)./tan(x(11)) - x(2)./tan(x(10)) - x(2)./tan(x(11))) ...
+ x(2).*x(3)./sin(x(11)) + ht.*(x(9) + ht./tan(x(12)));
Vcl = x(7).*(x(8) + (x(1)+x(2))./sin(x(11))) + (x(3)+x(7)).*(x(4) - x(1)./tan(x(10)) - x(1)./tan(x(11)) - ...
x(2)./tan(x(10)) - x(2)./tan(x(11))...
+0.5*(x(3)+x(7))./tan(x(11))+0.5*(x(3)+x(7))./tan(x(10)));
f = 822*Val + 166*Vul + 131*Vcl;
3- Nonlinear constraints:
function [c,ceq] = nonlconstr(x)
Hs = normrnd(2.5,0.11);
T = normrnd(5,1.5);
gamma = normrnd(26,0.11);
S = (2*pi().*Hs)/9.81./(T.^2);
c = [9.81.*Hs.*T.*0.013.*exp(-22.*(x(5)./Hs).*sqrt(S./2./pi())./gamma) - 0.4;
cot(x(10))-3;
1.5-cot(x(10));
cot(x(11))-3;
1.5-cot(x(11));
cot(x(12))-3;
1.5-cot(x(12));
1-x(5);
x(5)-6;
Pfo(x(5))-0.001;
Pfa(x(1),x(10),x(3),x(4),x(11))-0.01];
ceq = [];
4- Function for calculation of failure probability using monte carlo method:
function p = Pfo(x)
n = 10^6;
Hs = normrnd(2.5,0.11,[1 n]);
T = normrnd(5,1.5,[1 n]);
gamma = normrnd(26,0.11,[1 n]);
Ss = (2*pi().*Hs)/9.81./(T.^2);
G = 0.4 - 9.81.*Hs.*T.*0.013.*exp(-22.*(x./Hs).*sqrt(Ss./2./pi())./gamma);
isuccess=zeros(1,n);
isuccess(G<=0)=1;
p = sum(isuccess)/n;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
function p = Pfa(x1,x10,x3,x4,x11)
n = 10^6;
Hs = normrnd(2.5,0.11,[1 n]);
KD = normrnd(2.75,0.375,[1 n]);
Val = x1.*(x1./tan(x10) + x3./tan(x10)) + (x1./2).*(2.*x4 - x1./tan(x10) - ...
x1./tan(x11)) + x1.*x3./sin(x11);
Dn = (Val).^(1/3);
delta = 1.512;
G = delta*Dn.*(KD.*cot(x10)).^(1/3) - Hs;
isuccess=zeros(1,n);
isuccess(G<=0)=1;
p = sum(isuccess)/n;
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 18 de Oct. de 2019
1 voto
Jeff Miller told you this, the first time you asked this question. I'll repeat it, since you don't seem to believe him.
You CANNOT use FMINCON with randomly generated values inside the objective function, or the constraints. This will cause it to fail. It simply will not perform an optimization properly. This is true of almost any optimmization tool. Why?
Because any optimization tool assumes several things about the functions you will pass in.
- The function must be repeatable. So called with the same set of parameters, you need to get out exactly the same result. This applies to both the objective function and to the constraints.
- The function must be continuous and differentiable. Again, random functions are not that at all. They are not continuous, and certainly not differentiable.
Point #2 can be relaxed somewhat, for SOME optimizers. For example, tools like GA can often tolerate non-differentiable objective functions and constraints, to some extent, but there is no assurance of good convergence properties then.
But make things non-repeatable, and you are asking for random garbage as a result, from any optimizer.
2 comentarios
soheil radfar
el 18 de Oct. de 2019
If you are true, then probably this paper reported fake results. Yes?!
No. As Jeff told you, the random generation of the model parameters is not supposed to be repeated each time the cost/constraint function is evaluated. The cost function and constraints in the paper are based on values for the parameters that have already been observed and therefore don't fluctuate randomly anymore.
Categorías
Más información sobre Systems of Nonlinear Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!