How to formulate annulus bounds constraints in ga ?

Hello, I am struggling in formulating the lb and ub in my ga code, I need ga to generate locations within an annulus area between a smaller rectangle of 49-by-63 and a larger rectangle of 77-by-91. thanks !!!

 Accepted Answer

You need to use a nonlinear constraint for this. Something like
function [c,ceq] = myannulus(x)
ceq = [];
c(1) = (-(x(1) - a)*(b - x(1)));
c(2) = (-(x(2) - c)*(d - x(2)));
to constraint x to a < x(1) < b and c < x(2) < d. Of course, you would use your particular numbers for a, b, c, and d.
Alan Weiss
MATLAB mathematical toolbox documentation

1 Comment

Sorry, I wrote too fast. If you want x(1) to be in
a < x(1) < b OR f < x(1) < g then your nonlinear constraint c(1) would be
c(1) = (-(x(1) - a)*(b - x(1))*(x(1) - f)*(g - x(1)));
Similarly for c(2) and x(2).
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

More Answers (1)

Thanks Alan, :) , so I should leave lb and ub empty [] [] and include these constraints with the other nonlinear constraints ! I will try that

1 Comment

Now I'm not so sure, sorry again. Is this annulus a round annulus, I mean a section of two circles, radius between a and b? If so, then I think the correct nonlinear inequality constraint is this:
function [c,ceq] = myannulus(x)
ceq = [];
r = norm(x);
c = (-(r - a)*(b - r));
If, instead, this is a rectangular annulus, meaning the area between two rectangles where one rectangle is contained in the other, then I think that my previous answers are not correct. Instead, perhaps this is correct. The outer rectangle is from [xmin,ymin] to [xmax,ymax], and the inner rectangle is from [xmin2,ymin2] to [xmax2,ymax2], where
xmin < xmin2 < xmax2 < xmax
ymin < ymin2 < ymax2 < ymax
Use xmin, ymin and xmax,ymax as the bounds on the components of x. I mean, include them in the bounds. Then include also a nonlinear constraint function:
function [c,ceq] = myannulus2(x)
ceq = [];
cc(1) = (x(1) - xmin2)*(xmax2 - x(1));
cc(2) = (x(2) - ymin2)*(ymax2 - x(2));
c = max(cc(1),0)*max(cc(2),0);
Sorry for the confusion, I wasn't thinking clearly today.
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!