Fevzi
2012-05-31 22:48:45 UTC
Permalink
Hello,
I want to solve a nonlinear constrained optimization problem. I prepared 3 m-files which are for constraints, objective function and calling optimization toolbox.
M-File to call the tool box is following:
lb = [12.5;0.000460;0.005];
ub = [75;0.000786;0.160];
A =[];
Aeq= [];
b = [];
beq = [];
x0= [32;0.00058;0.1];
[x,fval,exitflag,output] = fmincon(@microobj,x0,A,b,Aeq,beq,lb,ub,@microcons)
[c,ceq] = microcons(x)
M-File for constraints is following:
function [c,ceq] = microcons(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
w = 0.500;
n = w/x(3);
D = 0.4;
N = (x(1)*1000)/(pi*D);
vL = 12.5;
vU = 75;
fzL = 0.000460;
fzU = 0.000786;
DocL = 0.005;
DocU = 0.160;
TlL = 0;
TlU = 20.5;
nL = 10000;
nU = 60000;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
c = [vL-x(1);x(1)-vU;fzL-x(2);x(2)-fzU;DocL-x(3);x(3)-DocU;TlL-Tl;Tl-TlU;nL-N;N-nU];
ceq = [(n*x(3))-w];
M-File for objective function is following:
function f = microobj(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
ae = 0.7;
D = 0.4;
A = 3.2;
k = (A-D)/(2*ae*D);
L = ((4*k*(k+1)*ae*D) + (2*ae*D));
dL = (k-1)*sqrt(2)*ae*D;
Lc = L + dL;
Lr = (sqrt(2)*(A-D))/2;
w = 0.500;
n = w/x(3);
N = (x(1)*1000)/(pi*D);
z = 2;
frCut = x(2)*z*N;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
Tm = (Lc/frCut)*n;
c0 = 1;
CM = c0* Tm;
Ts = 3;
CS = c0*Ts;
Tc = 3;
CR = c0*Tc*(ceil(Tm/Tl));
tC = 50;
CT = tC*(ceil(Tm/Tl));
f = CM + CS + CR + CT;
However, the tool box ignores "TlL = 0; TlU = 20.5;" limits and finds a negative Tl value. (When the solution is found, the value of 7th row in c vector is positive instead of negative. When I calculated Tl value using x1, x2, x3 and b1 to b10 values, Tl value is sufficiently large negative number). Then I wrote "TlL = 0.0000000001;" (1*10^-10) instead of "TlL = 0;", toolbox finds a reasonable result. Finally I increased the decimals to test whether toolbox always consider the TlL limit or not. When I tested the program for "TlL = 0.0000000000000001;" (1*10^-16), the program again gives a problematic result. I couldn't understand the reason of this problem. If it was a problem with # of decimal digits, it should not give a reasonable results for 1*(10^(-15)) or 1*(10^(-13))
Best Regards,
Matt J
2012-05-31 23:03:12 UTC
Permalink
Post by Fevzi
Hello,
I want to solve a nonlinear constrained optimization problem. I prepared 3 m-files which are for constraints, objective function and calling optimization toolbox.
lb = [12.5;0.000460;0.005];
ub = [75;0.000786;0.160];
A =[];
Aeq= [];
b = [];
beq = [];
x0= [32;0.00058;0.1];
[c,ceq] = microcons(x)
function [c,ceq] = microcons(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
w = 0.500;
n = w/x(3);
D = 0.4;
N = (x(1)*1000)/(pi*D);
vL = 12.5;
vU = 75;
fzL = 0.000460;
fzU = 0.000786;
DocL = 0.005;
DocU = 0.160;
TlL = 0;
TlU = 20.5;
nL = 10000;
nU = 60000;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
c = [vL-x(1);x(1)-vU;fzL-x(2);x(2)-fzU;DocL-x(3);x(3)-DocU;TlL-Tl;Tl-TlU;nL-N;N-nU];
ceq = [(n*x(3))-w];
function f = microobj(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
ae = 0.7;
D = 0.4;
A = 3.2;
k = (A-D)/(2*ae*D);
L = ((4*k*(k+1)*ae*D) + (2*ae*D));
dL = (k-1)*sqrt(2)*ae*D;
Lc = L + dL;
Lr = (sqrt(2)*(A-D))/2;
w = 0.500;
n = w/x(3);
N = (x(1)*1000)/(pi*D);
z = 2;
frCut = x(2)*z*N;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
Tm = (Lc/frCut)*n;
c0 = 1;
CM = c0* Tm;
Ts = 3;
CS = c0*Ts;
Tc = 3;
CR = c0*Tc*(ceil(Tm/Tl));
tC = 50;
CT = tC*(ceil(Tm/Tl));
f = CM + CS + CR + CT;
However, the tool box ignores "TlL = 0; TlU = 20.5;" limits and finds a negative Tl value. (When the solution is found, the value of 7th row in c vector is positive instead of negative. When I calculated Tl value using x1, x2, x3 and b1 to b10 values, Tl value is sufficiently large negative number). Then I wrote "TlL = 0.0000000001;" (1*10^-10) instead of "TlL = 0;", toolbox finds a reasonable result. Finally I increased the decimals to test whether toolbox always consider the TlL limit or not. When I tested the program for "TlL = 0.0000000000000001;" (1*10^-16), the program again gives a problematic result. I couldn't understand the reason of this problem. If it was a problem with # of decimal digits, it should not give a reasonable results for 1*(10^(-15)) or 1*(10^(-13))
================
You haven't shown us the magnitude of the negative number, so there's no reason yet to think the negatives are significantly large. Was the constraint violated by an amount greater than the TolCon tolerance parameter?
Also, you also haven't shown us the exitflag output of FMINCON. It might tell you that convergence failed for some reason.
Finally, if it's important to you to satisfy the bounds all the time then try using the sqp algorithm, or the interior-point algorithm with the AlwaysHonorConstraints option active.
Fevzi
2012-06-02 08:57:28 UTC
Permalink
Post by Matt J
Post by Fevzi
Hello,
I want to solve a nonlinear constrained optimization problem. I prepared 3 m-files which are for constraints, objective function and calling optimization toolbox.
lb = [12.5;0.000460;0.005];
ub = [75;0.000786;0.160];
A =[];
Aeq= [];
b = [];
beq = [];
x0= [32;0.00058;0.1];
[c,ceq] = microcons(x)
function [c,ceq] = microcons(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
w = 0.500;
n = w/x(3);
D = 0.4;
N = (x(1)*1000)/(pi*D);
vL = 12.5;
vU = 75;
fzL = 0.000460;
fzU = 0.000786;
DocL = 0.005;
DocU = 0.160;
TlL = 0;
TlU = 20.5;
nL = 10000;
nU = 60000;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
c = [vL-x(1);x(1)-vU;fzL-x(2);x(2)-fzU;DocL-x(3);x(3)-DocU;TlL-Tl;Tl-TlU;nL-N;N-nU];
ceq = [(n*x(3))-w];
function f = microobj(x)
b1 = -152.103;
b2 = 2.16514;
b3 = 1113.81;
b4 = 204245;
b5 = -0.0179843;
b6 = -3391.78;
b7 = -248075399;
b8 = -7.60179;
b9 = 1242.21;
b10 = -45237.6;
ae = 0.7;
D = 0.4;
A = 3.2;
k = (A-D)/(2*ae*D);
L = ((4*k*(k+1)*ae*D) + (2*ae*D));
dL = (k-1)*sqrt(2)*ae*D;
Lc = L + dL;
Lr = (sqrt(2)*(A-D))/2;
w = 0.500;
n = w/x(3);
N = (x(1)*1000)/(pi*D);
z = 2;
frCut = x(2)*z*N;
Tl = b1+x(1)*b2+x(3)*b3+x(2)*b4+(x(1)^2)*b5+(x(3)^2)*b6+(x(2)^2)*b7+x(1)*x(3)*b8+x(1)*x(2)*b9+x(2)*x(3)*b10;
Tm = (Lc/frCut)*n;
c0 = 1;
CM = c0* Tm;
Ts = 3;
CS = c0*Ts;
Tc = 3;
CR = c0*Tc*(ceil(Tm/Tl));
tC = 50;
CT = tC*(ceil(Tm/Tl));
f = CM + CS + CR + CT;
However, the tool box ignores "TlL = 0; TlU = 20.5;" limits and finds a negative Tl value. (When the solution is found, the value of 7th row in c vector is positive instead of negative. When I calculated Tl value using x1, x2, x3 and b1 to b10 values, Tl value is sufficiently large negative number). Then I wrote "TlL = 0.0000000001;" (1*10^-10) instead of "TlL = 0;", toolbox finds a reasonable result. Finally I increased the decimals to test whether toolbox always consider the TlL limit or not. When I tested the program for "TlL = 0.0000000000000001;" (1*10^-16), the program again gives a problematic result. I couldn't understand the reason of this problem. If it was a problem with # of decimal digits, it should not give a reasonable results for 1*(10^(-15)) or 1*(10^(-13))
================
You haven't shown us the magnitude of the negative number, so there's no reason yet to think the negatives are significantly large. Was the constraint violated by an amount greater than the TolCon tolerance parameter?
Also, you also haven't shown us the exitflag output of FMINCON. It might tell you that convergence failed for some reason.
Finally, if it's important to you to satisfy the bounds all the time then try using the sqp algorithm, or the interior-point algorithm with the AlwaysHonorConstraints option active.
******************************************************************
Here is the Result of the program when "TlL = 0;"
Warning: Trust-region-reflective algorithm does not solve this type of problem,
using active-set algorithm. You could also try the interior-point algorithm: set
the Algorithm option to 'interior-point' and rerun.
Post by Matt J
In fmincon at 460
In micromultipassmillCALL at 17
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints were
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
7
x =
38.6304
0.0007
0.1598
fval =
-5.4256e+008
exitflag =
4
output =
iterations: 17
funcCount: 198
lssteplength: 1
stepsize: 4.2554e-009
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: 3.6404e+016
constrviolation: 2.5720e-007
message: [1x770 char]
c =
-26.1303834688645
-36.3696165311355
-0.000231031509820056
-9.49684901799443e-05
-0.154763343633094
-0.00723665636690607
2.57203129905292e-07
-20.5000002572031
-20741.0824130261
-29258.9175869739
ceq =
************
Here is the Result of the program when "TlL = 0.0000000001;"
Warning: Trust-region-reflective algorithm does not solve this type of problem,
using active-set algorithm. You could also try the interior-point algorithm: set
the Algorithm option to 'interior-point' and rerun.
Post by Matt J
In fmincon at 460
In micromultipassmillCALL at 17
Local minimum possible. Constraints satisfied.
fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance and constraints were
satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
No active inequalities.
x =
32.0000
0.0006
0.1000
fval =
62.0503
exitflag =
4
output =
iterations: 15
funcCount: 157
lssteplength: 0.5000
stepsize: 1.2611e-008
algorithm: 'medium-scale: SQP, Quasi-Newton, line-search'
firstorderopt: []
constrviolation: 0
message: [1x770 char]
c =
-19.5000000000000
-43
-0.000120000000000000
-0.000206000000000000
-0.0950000000000000
-0.0670000000000000
-7.34420137630000
-13.1557986236000
-15464.7908947033
-34535.2091052967
ceq =
Does the problem TolCon? If yes, how can I change TolCon to a smaller tolerance?
In order to use interior-point algorithm with AlwaysHonorConstraints, are the following lines sufficient or do I need to define AlwaysHonorConstraints in some place?
options = optimset('algorithm','interior-point');
[x,fval,exitflag,output] = fmincon(@micromultipassmillobj,x0,A,b,Aeq,beq,lb,ub,@micromultipassmillcons,options)
Sargondjani
2012-06-01 05:18:10 UTC
Permalink
just small advice on programming: i think it is more convenient to pass all your parameters into the two m-files (as inputs) instead of defining them inside your m-file. you can do it like this:
m-file:
function y=fun_obj(x,par1,par2...)
and then you define the values of par1, etc. before calling mfincon. you can call fmincon like this:
fmincon(@(x)fun_obj(x,par1,par,..),A,b,.....)
since you have quite a few parameters you can also store them in a structure:
par.b1=...
par.b2=...
and then your m-file can just just par as an input:
function y=fun_ob(x,par)