Finish Discrete Optimization.

This commit is contained in:
2020-01-21 22:53:31 -05:00
parent cd3d564113
commit fb2953bc6f
7 changed files with 208 additions and 53 deletions

View File

@@ -6,10 +6,9 @@ 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
CLUSTERS_X = 4 # How many points we want per cluster.
def __init__(self):
pass
def __init__(self, n_clusters):
self.CLUSTERS_X = n_clusters
def calc_corners(self, points):
x_min, x_max = float("inf"), float("-inf")
@@ -95,26 +94,30 @@ class Map(object):
self.add_neighbors_to_points(points)
return points
def plot(self, points):
def plot_grid(self, plt):
if plt is None:
return
for x_i in range(self.clusters_x + 1):
x_1 = self.x_min + x_i * self.cluster_x_dim
x_2 = x_1
y_1 = self.y_min
y_2 = self.y_max
plt.plot([x_1, x_2], [y_1, y_2], 'y:', linewidth=0.1)
for y_i in range(self.clusters_y + 1):
x_1 = self.x_min
x_2 = self.x_max
y_1 = self.y_min + y_i * self.cluster_y_dim
y_2 = y_1
plt.plot([x_1, x_2], [y_1, y_2], 'y:', linewidth=0.1)
def plot(self, points, plt):
if plt is None:
return
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
return
def plot_grid():
for x_i in range(self.clusters_x + 1):
x_1 = self.x_min + x_i * self.cluster_x_dim
x_2 = x_1
y_1 = self.y_min
y_2 = self.y_max
plt.plot([x_1, x_2], [y_1, y_2], 'b:')
for y_i in range(self.clusters_y + 1):
x_1 = self.x_min
x_2 = self.x_max
y_1 = self.y_min + y_i * self.cluster_y_dim
y_2 = y_1
plt.plot([x_1, x_2], [y_1, y_2], 'b:')
def plot_arrows():
for i in range(len_points):
p1 = points[i - 1]
@@ -140,6 +143,6 @@ class Map(object):
len_points = len(points)
plot_points()
plot_grid()
self.plot_grid(plt)
plot_arrows()
plt.show()