PSO does not satisfy the nonlcon inequality constraint and gives solutions less than LB
2 views (last 30 days)
Show older comments
Hello everyone,
I uses this pso code: https://www.mathworks.com/matlabcentral/fileexchange/25986-constrained-particle-swarm-optimization?s_tid=srchtitle
when running the pso with:
[best_solution, fval] = pso(objFcn,nVars,[],[],A_eq,B_eq,LB(ttt,:),UB(ttt,:),nonlcon,options_pso)
returns me solutions does not satisfy the nonlcon and some solutions have values lower than than the LB ?
here is the nonlcon function:
function [cneq, ceq] = myNonLinearConstraint(force_pop)
global ttt
% compression and shear vectors directions
[a1, b1, c1, a2, b2, c2, a, b, c, d, e, f] = shear_comp_ratio_coef;
% GH reaction forces
R_gh_x = force_pop(55);
R_gh_y = force_pop(56);
R_gh_z = force_pop(57);
% shear forces
F_shear_1 = a1(ttt)*R_gh_x+b1(ttt)*R_gh_y+c1(ttt)*R_gh_z;
F_shear_2 = a2(ttt)*R_gh_x+b2(ttt)*R_gh_y+c2(ttt)*R_gh_z;
% angle between F_shear_1 (as x-dir) and F_shear_2 (as y-dir)
theta = atan2d(F_shear_2,F_shear_1);
if theta<0
theta = theta+360;
end
% emprical shear_comp_ratio
shear_comp_ratio_emprical = [0.51, 0.33, 0.29, 0.4, 0.56, 0.43, 0.3, 0.35, 0.51];
angle = 0:45:360;
% get the shear_comp_ratio_at the current angle theta using linear interpolation
shear_comp_ratio_at_theta = interp1(angle,shear_comp_ratio_emprical,theta);
% total shear force
F_shear = (a(ttt)*R_gh_x+b(ttt)*R_gh_y+c(ttt)*R_gh_z);
% compression force
F_comp = (d(ttt)*R_gh_x+e(ttt)*R_gh_y+f(ttt)*R_gh_z);
% cneq: not equality constraint
cneq = abs(F_shear/F_comp)-shear_comp_ratio_at_theta;
% ceq: equality constraint not exist
ceq = [];
thanks in advance
9 Comments
Walter Roberson
on 4 Jun 2023
You did not post your full code and you did not attach your data, so we cannot test this for you.
Answers (1)
Steven Lord
on 2 Jun 2023
Have you considered using the particleswarm function in Global Optimization Toolbox, either as your main solver or to help you diagnose why the solver in the File Exchange submission doesn't give you the answers you expect?
8 Comments
See Also
Categories
Find more on Particle Swarm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!