How to solve implicitly constrained optimization in Matlab?
Show older comments
As we know, we can easily use fmincon to solve any optimization problem that contains some explicit linear and non linear, equality and inequality constraints ( such as Case 1) .
%Case 1
f(x) = –x1x2x3
Sub:-x1–2x2–2x3 ≤ 0
x1 + 2x2 + 2x3≤ 72
But, I have some additional implicit constraints , which are in a form of a nonlinear system (such as Case2) .
%Case 2
f(x) = –x1x2x3
Sub: -x1–2x2–2x3 ≤ 0
x1 + 2x2 + 2x3≤ 72
%Here is the Additional implicit constraints in a form of nonlinear system
X1^2+ln(u1)+sqrt(u3)=0
X2^2+X3+ln(u2)=0
sqrt(x1)+X3+u1=0
X2+X1+u2^2=0
X1^2+X2+ln(u3)=0
X1^2+X3+ln(u1)=0
% finally this constraints which is derived from the above system must be %satisfied:
0.9<real(u1,u2,u3)<1.1
As a possible but inefficient approach, I have tried to use fsolve Matlab built-in function within the constraint function file (e.g., mycon.m ) to solve the additional nonlinear system and then evaluate the added constraint 0.9<real(u1,u2,u3)<1.1 which uses new implicit variables i.e., u1,u2,u3. fimincon is a iterative method, so generally it calls mycon.m function many times (1000) to evaluate the candidate optimization vector x1,x2,x3. Thus, The nonlinear system along the added implicit constraint must be solved and evaluated as well many times. This bring a huge computational burden to this problem as fsolve is a iterative and time consuming method too.
Is this a correct approach? Is there any efficient method to include this implicit constraints 0.9<real(u1,u2,u3)<1.1 in my problem with a reasonable computational burden? Is there a way to include these implicit constraint variables (u1,u2,u3) as the optimization variables x1,x2,x3 so that fmincon evaluate them without solving the nonlinear system by fsolve? Can I consider this nonlinear system outside of 'mycon.m' so that it will be calculated once and then obtained u1,u2,u are supplied to 'mycon' for verifying the last constraint? 0.9<real(u1,u2,u3)<1.1
Note: my actual problem is huge itself and its nonlinear system contains few hundreds of equations, so using ` fsolve ` in this way, is not possible for me .
Please tell me your suggestions.
Here I post my code for evaluating the implicit constraint using fsolve in mycon.m
%Main file
x0 = [10;10;10]; % Starting guess at the solution
[x,fval] = fmincon('myfun',x0,[],[],[],[],[],[],'mycon');
% Objective function
function f = myfun(x)
f = -x(1) * x(2) * x(3);
% Constraint function
function [c, ceq]=mycon(x)
c(1)=-x(1)-2*x(2)-2*x(3);
c(2)=x(1) + 2*x(2 )+ 2*x(3)-72;
Y=zeros(6,1);
Y(1)=x(1);Y(2)=x(2);Y(3)=x(3);
Y(4)=1;Y(5)=1;Y(6)=1;
options = optimoptions('fsolve','Display','off');
Y = fsolve(@mysys,Y,options); % Call solver
Y=real(Y);
c(3)=Y(4)-1.1;
c(4)=Y(5)-1.1;
c(5)=Y(6)-1.1;
c(6)=-Y(4)+0.9;
c(7)=-Y(5)+0.9;
c(8)=-Y(6)+0.9;
ceq=[];
% Nonlinear System equations.
function eq=mysys(Y)
x(1)=Y(1);x(2)=Y(2);x(3)=Y(3);
u(1)=Y(4);u(2)=Y(5);u(3)=Y(6);
eq(1)=x(1)^2+log(u(1))+sqrt(u(3));
eq(2)=x(2)^2+x(3)+log(u(2));
eq(3)=sqrt(x(1))+x(3)+u(1);
eq(4)=x(2)+x(1)+u(2)^2;
eq(5)=x(1)^2+x(2)+log(u(3));
eq(6)=x(1)^2+x(3)+log(u(1));
2 Comments
Titus Edelhofer
on 23 Apr 2015
Just to be sure, I understood:
- You already tried to have variables [x1, x2 x3, u1, u2, u3] instead of "only" [x1 x2 x3]?
- You are able to formulate the objective function and constraints and call fmincon?
But since your real problem has more like x1,...x100,u1,...,u100 the overall problem is to hard to solve using fmincon? Is that the challenge?
Titus
Jamais avenir
on 23 Apr 2015
Accepted Answer
More Answers (1)
Torsten
on 23 Apr 2015
0 votes
There is no other way as to use the nonlcon-function within fmincon.
Best wishes
Torsten.
1 Comment
Jamais avenir
on 23 Apr 2015
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!