Please Help Optimization using PSO
4 次查看(过去 30 天)
显示 更早的评论
I have optimization problem using PSO "I have to write the code without using toolbox" .. I wrote the mainPSO code and the objective function but I don't know how to define the equality and inequality constraints
x1+x2+x3+x4+x5 =1000;
x1^2-4x2+5x3^3+x4^4-3.5x5^2 = 300
How to define these two constraints ???
0 个评论
采纳的回答
Walter Roberson
2021-1-5
%{
x1+x2+x3+x4+x5 =1000;
x1^2-4x2+5x3^3+x4^4-3.5x5^2 = 300
%}
Notice that x2 is the only variable that appears linearly in the second equation. So rewrite the first equation as
%{
x2 = 1000 - x1 - x3 - x4 - x5
%}
Now substitute that into the second equation
%{
x1^2-4*(1000 - x1 - x3 - x4 - x5)+5x3^3+x4^4-3.5x5^2 = 300
%}
This is a quadratic in x1 (or x5), so solve it for x1
syms x1 x2 x3 x4 x5
eqn = x1^2-4*(1000 - x1 - x3 - x4 - x5)+5*x3^3+x4^4-3.5*x5^2 == 300
X1 = solve(eqn, x1)
Now you run two different PSO runs, one substituting 1000 - x1 - x3 - x4 - x5 for x2 and the first of those X1 values for x1; the other run substituting 1000 - x1 - x3 - x4 - x5 for x2 and the second of those X1 values for x1. These runs will not require equality or inequality constraints (unless there are more constraints you did not tell us about.)
The runs you would do would be over 3 variables only, x3, x4, x5, with you having substituted for x1 and x2 in your objective function.
0 个评论
更多回答(1 个)
Ameer Hamza
2021-1-5
Check the code of this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/75101-non-linear-equality-and-inequality-constrained-pso. It might give you some ideas.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!