Defining inequality constraint A*x <= b for genetic algorithm
46 views (last 30 days)
Show older comments
Dear MATLAB Community,
I am trying to constrain the design variables in a genetic algorithm (GA). My goal is to select the xxx and yyy positions of knots (see first image step 1). After selecting these points using GA, I fit a curve to create an area (see first image step 2).
However, many knot distributions lead to self-intersecting (see second image) curves, which introduce noise and reduce computational efficiency. I already implemented this into constrraint function for checking the intersection. However, since this calls the constraint function and evaluation of the constraint function takes sometime it is not efficient.
I was wondering if i can somehow consttraint the variables with the linear inequalities A*x ≤ b so that GA will exclude those candidates before calling objective/constraint functions.
Could someone provide guidance on how to better implement these constraints so that the GA avoids invalid, self-intersecting knot distributions?
Thank you for your help!


4 Comments
Answers (3)
Matt J
about 20 hours ago
Edited: Matt J
10 minutes ago
You should be able to vectorize the computations in your self-intersection checker (within your nonlinear constraint function). They are mainly cross-product calculations aren't they? Assuming you have done so, then you can run ga with the UseVectorized option setting so that it will get the computational benefits of this.
0 Comments
Walter Roberson
about 16 hours ago
Edited: Walter Roberson
about 16 hours ago
In order to have a hope of doing it through linear inequalities, you would have to first have a row that tested whether the first segment intersected the third segment, then whether the second segment intersected the fourth segment, and so on marching across the N'th segment intersecting the (N+2) segment. After that you would have to march across the N'th segment intersecting the (N+3) segment, then marching across the N'th segment intersecting the (N+4) segment, and so on, until eventually you hit the first segment intersecting the last segment.
Now, can you use a linear inequality to express N'th segment intersect (N+2) segment? No. The equations at https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line_segment show that the calculations are non-linear. They are individually not especially complicated, but they are non-linear. x values must be multiplied by y values, which is not possible in linear inequalities.
So it cannot be done using linear inequalities.
John D'Errico
about 15 hours ago
Edited: John D'Errico
about 15 hours ago
As I said in my comment, you cannot set up a linear system of inequalities to constrain that curved path from self intersections. (@Walter Roberson points this out too.) The higher order nature of the curves will prevent a linear system from being viable. Is there anything you can do? Perhaps.
Approximate the curve as a set of line segments, so a piecewise linear curve, connect-the-dots. Given the end points of each line segment, a test for two line segments crossing can then be written as a 2x2 linear system of parametric equations. That is, if two points determine a line segment, then the set of points on that line segment can be written as
P(t) = p1*(1-t) + p2*t
where t must lie between 0 and 1, and p1 and p2 are vectors of length 2. Now if you have a second line segment defined by different end points, this gives you a pair of linear equations in 2 unknowns, s and t. If the solution has both s, and t in the interval [0,1], then the line segments must intersect.
Do this for EVERY pair of line segments. Well, segment k in a piecewise linear curve will never intersect with segments k-1, k or k+1. It will get messy, and big. And again, you need to constrain the solutions so they don't lie in the unit square for each pair of parameters defining those lines. However, it will catch SOME of those intersection cases. The problem is, approximating a path by a piecewise linear set of segments will miss some intersections. And it will occasionally predict an intersection where none exists.
Typically, when I see such an approximation, the result is a necessary, but not sufficient kind of thing. In this case, the linear system will be neither necessary nor sufficient to avoid self-intersection. Honestly, I don't even like my own idea here, even if you could manage to make it work partially. I don't think the effort involved will be worth the gain, as you will still need to perform a better test on all such planar curves.
See Also
Categories
Find more on Genetic Algorithm 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!