Optimization of a function with constraints containing 15 variables

5 views (last 30 days)
I am trying to solve an optimization problem of a function to find its minimum value that satisfies some constraints ( linear and nonlinear equalities; linear inequalities). So far, I have tried the following solvers:
  • fmincon (algorithms interior-point, active-set and sqp). The function converges for some initial values and deteriorates for other initial values that are only slightly different.
  • ga. Either the algorithm doesn't find a feasible point in the first iteration (slighty less frequent when using nonlinear feasible creation function) or when it does, the stall generations limit is exceeded without a solution beeing found.
My code for the objective function:
function val = objFun(x)
val = x(1)+x(2)+x(3)+x(4);
end
My code for the constraints:
function [c, ceq] = constraints(x)
%inequalities
c(1) = -x(1);
c(2) = -x(2);
c(3) = -x(3);
c(4) = -x(4);
c(5) = x(15)-0.3;
%linear equalities
ceq(1) = x(5)+x(6)+x(7)+x(8);
ceq(2) = -500+x(9)+x(10)+x(11)+x(12);
ceq(3) = -500*0.636-0.25*(x(4)-x(2));
ceq(4) = -0.25*(x(3)-x(1));
ceq(5) = -500*0.242-0.25*(x(8)-x(6))-a*(x(11)-x(9));
ceq(6) = x(1)+x(3)-x(2)-x(4);
ceq(7) = (x(9)/x(5))+((0.25-x(13))/(-x(14)));
ceq(8) = (x(10)/x(6))+((-x(13))/(-0.25-x(14)));
ceq(9) = (x(11)/x(7))+((-0.25-x(13))/(-x(14)));
ceq(10) = (x(12)/x(8))+((-x(13))/(0.25-x(14)));
%nonlinear equalities
ceq(11) = x(15)^2*x(1)^2-x(5)^2-x(9)^2;
ceq(12) = x(15)^2*x(2)^2-x(6)^2-x(10)^2;
ceq(13) = x(15)^2*x(3)^2-x(7)^2-x(11)^2;
ceq(14) = x(15)^2*x(4)^2-x(8)^2-x(12)^2;
end
My code for the optimization with fmincon:
options = optimoptions(@fmincon,'Display','iter','Algorithm','sqp');
x0 = [300 400 300 200 100 400 100 200 500 400 200 100 0.1 0.1 0.25]; %this initial value converges
% x0 = [300 400 300 200 110 400 100 200 500 400 200 100 0.1 0.1 0.25]; %this initial value deteriorates
[x,fval] = fmincon(@objFun,x0,[],[],[],[],[],[],@constraints,options)
My code for the optimization with ga:
options = gaoptimset('Display','iter','CreationFcn',@gacreationnonlinearfeasible);
[x,fval] = ga(@objFun,15,[],[],[],[],[],[],@constraints,options)
  2 Comments
Dhanu Naik
Dhanu Naik on 30 Jan 2018
How can we tell Constraint function,The number of decision Variables in case of Generic Programming. Here you have taken 15 which was known to you,if my number of decision variables varies,how can I send that extra information to constraint function.
Walter Roberson
Walter Roberson on 30 Jan 2018
You can take the length() of the input to the constraint function. If somehow you have a different number of decision variables, then use http://www.mathworks.com/help/matlab/math/parameterizing-functions.html

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 22 Dec 2015
Do not use nonlinear constraint functions to effect linear constraints and bounds. Your first five nonlinear inequality constraints should be represented as bounds: x(1) through x(4) have lower bounds of 0, and x(15) has an upper bound of 0.3.
Similarly, your first six nonlinear equality constraints should be written as linear equality constraints.
Don't bother trying to optimize a smooth function with smooth constraints using ga. The solver of choice for such problems is fmincon.
Do x(13) and x(14) have to be between -0.25 and 0.25? If so, give these as bounds.
I suggest that you examine your problem carefully to see if you can bound each component, and then include the tightest bounds you can in the problem.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  4 Comments
Lucas Giering
Lucas Giering on 23 Dec 2015
Yes, after writing my first comment i realized my mistake in that regard. Of course equalities 7-10 are indeed nonlinear.
I applied the changes you advised, but the behaviour is still the same: few initial values converge, others deteriorate to very high function values.
Alan Weiss
Alan Weiss on 23 Dec 2015
Maybe you can follow the suggestions in When the Solver Fails. In particular, I believe that you could easily come up with analytic gradients and Hessian for the 'interior-point' algorithm, either using Symbolic Math Toolbox as the easiest way, or calculate it by hand.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!