如何用最近邻随机点划分空间?遗传算法交叉方法技术问询
Great question—since you're only optimizing 2-3 variables, working in planar or spherical space makes this problem way more tractable than high-dimensional GA scenarios. Let's break down your two core challenges with practical, actionable solutions:
1. Ensuring Equal Parental Contribution When Grouping Points
The key here is to design grouping strategies where every parent individual is included in the same number of triangle/quadrilateral groups, so each contributes equally to the next generation's offspring. Here are two reliable approaches:
Round-Robin Rotational Grouping (For Fixed Group Sizes)
This works best when you can adjust your population size to be compatible with your group size (3 for triangles, 4 for quadrilaterals), or when you want controlled overlap:
- First, shuffle your population randomly to avoid bias from initial ordering.
- If your population size
Mis divisible by group sizek: Split the shuffled list into consecutive groups ofkpoints. Each parent appears in exactly one group, so every individual contributes to exactly one offspring (the centroid of their group). - If
Misn't divisible byk: Use cyclic rotation to create overlapping groups. For example, withk=3andM=7:- Start with group
[p0, p1, p2] - Shift right by one to get
[p1, p2, p3] - Repeat until you loop back to
[p6, p0, p1]
This createsMtotal groups, and each parent appears in exactlykgroups (3 in this case), ensuring equal contribution across all individuals.
- Start with group
Weighted Random Pooling (For Flexible Group Sizes)
If you need more flexibility with arbitrary population and group sizes:
- Decide on a target number of offspring
G, then calculate how many times each parent should be included in groups:t = (G * k) / M(round to the nearest integer if needed, or adjustGto maketan integer). - Initialize a counter for each parent set to
t(this tracks how many more groups they can join). - Repeatedly select
kparents with remaining counter > 0 at random, form a group, generate the centroid offspring, and decrement each selected parent's counter by 1. - Stop when all counters reach 0. This guarantees every parent contributes exactly
ttimes to the offspring pool.
2. Spatial Subdivision Using Nearest Neighbors
Leveraging nearest neighbors helps you create meaningful, space-filling groups that respect the distribution of your population. Here are tailored methods for your 2D/3D use cases:
k-Nearest Neighbor (k-NN) Grouping
This is simple, intuitive, and ensures groups are locally cohesive:
- For each parent point
pi:- Find its top
k-1nearest neighbors (use Euclidean distance for planes, great-circle distance for spheres). - Form a group with
piand thesek-1neighbors (3 total for triangles, 4 for quadrilaterals). - Generate the centroid of this group as an offspring.
- Find its top
- To avoid redundant groups (e.g.,
pi's group being identical topj's group), you can either:- Keep only unique groups (check for identical sets of points), or
- Allow duplicates—they'll produce identical centroids, which won't harm diversity unless overdone.
- Bonus: Add randomness by selecting
k-1neighbors from the topmnearest neighbors (instead of the absolute topk-1). This introduces more variability and helps avoid getting stuck in local optima.
Delaunay Triangulation (For 2D Planar Spaces)
If you want optimal, non-overlapping spatial subdivision:
- Run a Delaunay triangulation on your planar point set. This algorithm creates triangles such that no point lies inside the circumcircle of any triangle, resulting in well-shaped, space-filling groups.
- Extract each triangle's centroid as an offspring.
- To fix unequal parental contribution:
- Count how many triangles each parent appears in.
- For parents in too many triangles, randomly discard some of their associated groups.
- For parents in too few, add extra groups using their nearest neighbors until all parents have the same count.
Spherical Delaunay Triangulation (For 3D Spherical Spaces)
For 3-variable problems mapped to a sphere (e.g., unit sphere constraints):
- Use a spherical Delaunay triangulation, which extends the planar Delaunay logic to the surface of a sphere.
- Calculate the spherical centroid of each triangle (average the 3 vertex vectors, then normalize to the sphere's surface) as an offspring.
- Follow the same equal-contribution adjustment steps as the planar Delaunay method to ensure every parent contributes equally.
内容的提问来源于stack exchange,提问作者Dónal Flanagan

