Divide plane into squares and then local search.

This commit is contained in:
2020-01-20 18:51:47 -05:00
parent 2bd5774c13
commit 03291a57bc
8 changed files with 78 additions and 39 deletions

View File

@@ -6,7 +6,7 @@ class Map(object):
# and neighbor regions. We can actually cluster in O(n) when we know how
# high and wide the clusters are. Once we have that working we go from
# there
CLUSTER_SIZE = 5 # How many points we want per cluster.
CLUSTERS_X = 4 # How many points we want per cluster.
def __init__(self):
pass
@@ -29,10 +29,12 @@ class Map(object):
self.y_max = y_max
def calc_cluster_dim(self, points):
clusters = len(points) // self.CLUSTER_SIZE
# clusters = len(points) // self.CLUSTER_SIZE
# Calculate number of clusters to have a square
self.clusters_x = math.ceil(math.sqrt(clusters))
self.clusters_y = self.clusters_x
# self.clusters_x = math.ceil(math.sqrt(clusters))
# self.clusters_y = self.clusters_x
self.clusters_x = self.CLUSTERS_X
self.clusters_y = self.CLUSTERS_X
self.clusters_total = self.clusters_x ** 2
self.cluster_x_dim = (self.x_max - self.x_min) / self.clusters_x
self.cluster_y_dim = (self.y_max - self.y_min) / self.clusters_y