Info

This question is closed. Reopen it to edit or answer.

A question regarding a optimization problem by using "fmincon" solver.

1 view (last 30 days)
Hi, I've faced with an error in my optimization code. When I consider the parameter "options.MaxFunEvals" as a large number (like 10000), the system will be busy. Otherwise, if this parameter be a small number (e.g., 5), the output will be equal to the primary value of parameters. The code is presented as follows.
clear
clc
sc=5;
sp=4;
lo=21;
t=0.5;
A=[-1 -2 -2;...
1 2 2];
b=[0;72];
x0=10*ones(11073,1);
lb=2*ones(11073,1);
ub=100*ones(11073,1);
options = optimoptions(@fmincon,...
'Display','iter','Algorithm','interior-point');
options.MaxFunEvals=1000000;
[x,fval,exitflag,output]=fmincon(@(x)OFT(x),x0,[],[],[],[],lb,ub,[],options);
Also, the function namely OFT is called via below code:
function f=OFT(x)
% f=-x(1,1)*x(2,1)*x(3,1);
f=0;
for i=1:1:11073;
f=f+((cos(i*(pi))*x(i,1)^.2)/125);
end
end
Thank you so much for your considerations, in advance.
  3 Comments
Matt J
Matt J on 28 Aug 2018
Edited: Matt J on 28 Aug 2018
You have defined what look like inequality constraint data,
A=[-1 -2 -2;...
1 2 2];
b=[0;72];
but they are for only a 3-dimensional problem and are never passed to fmincon. Is this deliberate? Are there only supposed to be lb,ub constraints?
Stephan
Stephan on 28 Aug 2018
Edited: Stephan on 28 Aug 2018
Your code is confusing a little bit - seeing what you wrote you have 11073 decision variables - considering the inequalities Matt has commented above, it could also be three decision variables and you were confused when you wrote the code.
I am looking forward to the solution of the riddle ?

Answers (3)

Matt J
Matt J on 28 Aug 2018
Edited: Matt J on 28 Aug 2018
Use the default MaxFunEvals, but you need to vectorize OFT for faster performance. You also need to provide vectorized computations of the gradient and Hessian, or you will incur a lot of overhead from finite difference calculations.
e=(-1).^(1:11073)/125;
g=2*e;
OTF= @(x) deal( e*x(:).^2 , g(:).*x(:) ); %provide objective AND gradient
options = optimoptions(@fmincon,'Algorithm','interior-point',...
'SpecifyObjectiveGradient',true,'SpecifyConstraintGradient',true,...
'SubproblemAlgorithm','cg','HessianMultiplyFcn',@(x,l,v) g(:).*v(:));
[x,fval,exitflag,output]=fmincon(OTF,x0,[],[],[],[],lb,ub,[],options);
However, your objective is quite non-convex, so I expect it could be difficult for fmincon to minimize. ga() might be a better choice.
  3 Comments
Stephan
Stephan on 28 Aug 2018
Edited: Stephan on 28 Aug 2018
You're right - without A & b it works ... Still not sure if there is not a 3-dimensional problem here. Your question about inequality conditions has brought me to it.

Stephan
Stephan on 28 Aug 2018
Edited: Stephan on 28 Aug 2018
Hi,
is it what you want:
A=[-1 -2 -2;...
1 2 2];
b=[0;72];
x0=10*ones(1,3);
lb=2*ones(1,3);
ub=100*ones(1,3);
options = optimoptions(@fmincon,...
'Display','iter','Algorithm','interior-point');
[x,fval,exitflag,output]=fmincon(@(x)OFT(x),x0,A,b,[],[],lb,ub,[],options);
function f=OFT(x)
% f=-x(1,1)*x(2,1)*x(3,1);
f=0;
for i=1:11073
f=f+((cos(i*(pi))*x(:,1)^.2)/125);
end
end
This results in:
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 4 -1.267915e-02 0.000e+00 2.530e-04
1 8 -1.267923e-02 0.000e+00 2.530e-04 3.428e-04
2 12 -1.267967e-02 0.000e+00 2.530e-04 1.765e-03
3 16 -1.268120e-02 0.000e+00 2.529e-04 6.190e-03
4 20 -1.268883e-02 0.000e+00 2.523e-04 3.095e-02
5 24 -1.272666e-02 0.000e+00 2.493e-04 1.544e-01
6 28 -1.290714e-02 0.000e+00 2.356e-04 7.622e-01
7 32 -1.364494e-02 0.000e+00 1.885e-04 3.592e+00
8 36 -1.502162e-02 0.000e+00 1.271e-04 9.135e+00
9 48 -1.501503e-02 0.000e+00 1.140e-04 5.251e-02
10 54 -1.501813e-02 0.000e+00 9.823e-05 2.465e-02
11 58 -1.501774e-02 0.000e+00 9.824e-05 5.967e-03
12 62 -1.502349e-02 0.000e+00 9.804e-05 4.631e-02
13 66 -1.504799e-02 0.000e+00 9.721e-05 2.028e-01
14 70 -1.516734e-02 0.000e+00 9.323e-05 1.007e+00
15 74 -1.569717e-02 0.000e+00 7.734e-05 4.869e+00
16 78 -1.741822e-02 0.000e+00 4.758e-05 2.106e+01
17 82 -1.835169e-02 0.000e+00 4.540e-05 1.550e+01
18 87 -1.834569e-02 0.000e+00 2.897e-05 1.495e-01
19 92 -1.834905e-02 0.000e+00 1.454e-05 5.888e-02
20 96 -1.834932e-02 0.000e+00 9.991e-06 4.905e-03
21 100 -1.837306e-02 0.000e+00 2.047e-06 4.230e-01
22 104 -1.837911e-02 0.000e+00 2.214e-08 1.081e-01
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the optimality tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
with x:
x =
64.0000 2.0000 2.0000
and
>> fval
fval =
-32.7680
This x meets the inequality conditions you made. It was very confusing that you made x0, lb and ub a size of 11073 --> So i first thought your solution needs to have 11073 components...
Best regards
Stephan

Abdollah Louni
Abdollah Louni on 31 Aug 2018
Hi everybody, Thank you for your help and considerations.
Best wishes, A. Louni

This question is closed.

Community Treasure Hunt

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

Start Hunting!