Optimization - non-linear eqn. genetic algorithm

Hello,
I want to solve the system of non-linear equations:
0.8*x(1)+0.2*x(2)<0.2
0.45*x(3)+0.55*x(4)<0.2
0.45*x(3)+0.55*x(4)<0.8*x(1)+0.2*x(2)
x(2)<x(3)
x(4)<x(1)
I tried with genetic algorithm. However, a few times fourth condition (x(2)<x(3)) is getting violated. Can anyone help me please.
Thanks in advance
format short
fun=@(x)-(x(1)+x(2)+x(3)+x(4));
nonlcon=@nonlinearconstr;
lb=[0.01 0.01 0.01 0.01];
ub=[0.99 0.99 0.99 0.99];
Aeq = []; % No other constraints
beq = [];
A = [];
b = [];
x0=lb;
options = optimoptions('ga','ConstraintTolerance',1e-6,'PopulationSize',150,'PlotFcn', @gaplotbestf);
x = ga(fun,4,A,b,Aeq,beq,lb,ub,nonlcon,options);
disp(x);
function [c,ceq] = nonlinearconstr(x)
c(1)=0.8*x(1)+0.2*x(2)-0.2;
c(2)=0.45*x(3)+0.55*x(4)-0.2;
c(3)=-0.45*x(3)-0.55*x(4)+0.8*x(1)+0.2*x(2);
c(4)=x(2)-x(3);
c(5)=x(4)-x(1);
ceq = [];
end

Answers (1)

Your problem is linear - thus use linprog instead of ga:
f = -[ 1 1 1 1];
A = [0.8 0.2 0 0;0 0 0.45 0.55;-0.8 -0.2 -0.45 -0.55;0 1 -1 0;-1 0 0 1];
b = [0.2 0.2 0 0 0].';
lb=[0.01 0.01 0.01 0.01];
ub=[0.99 0.99 0.99 0.99];
sol = linprog(f,A,b,[],[],lb,ub)
Optimal solution found.
sol = 4×1
0.1419 0.4322 0.4322 0.0100
By the way:
Your constraint
c(3)=-0.45*x(3)-0.55*x(4)+0.8*x(1)+0.2*x(2);
is wrong. Must read
c(3)=-0.45*x(3)-0.55*x(4)-0.8*x(1)-0.2*x(2);

2 Comments

Hello Torsten,
Thanks for your comments. We have the same issue here, x(2)=x(3), However I x(2)<x(3).
Strict inequality (<, >) cannot be imposed in optimization problems.
The reason is that in general, no solution would exist.
Consider e.g. the problem
min: x
under the constraint
x > 0
and try to find the solution.

Sign in to comment.

Asked:

on 10 Nov 2022

Edited:

on 10 Nov 2022

Community Treasure Hunt

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

Start Hunting!