<pre><code>#@title Visualization function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
defplot_circles(circles: np.ndarray):
"""Plots the circles."""
_, ax = plt.subplots(1, figsize=(7, 7))
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_aspect('equal') # Make axes scaled equally.
Draw unit square boundary.
rect = patches.Rectangle((0, 0), 1, 1, linewidth=1, edgecolor='black', facecolor='none')
ax.add_patch(rect)
Draw the circles.
for circle in circles:
circ = patches.Circle((circle[0], circle[1]), circle[2], edgecolor='blue', facecolor='skyblue', alpha=0.5)
ax.add_patch(circ)
plt.title(f'A collection of {len(circles)} disjoint circles packed inside a unit square to maximize the sum of radii')
plt.show()</code></pre>
谷歌还提供了画图代码,代码如下:
<pre><code>#@title Visualization function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
defplot_circles(circles: np.ndarray):
"""Plots the circles."""
_, ax = plt.subplots(1, figsize=(7, 7))
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_aspect('equal') # Make axes scaled equally.
# Draw unit square boundary.
rect = patches.Rectangle((0, 0), 1, 1, linewidth=1, edgecolor='black', facecolor='none')
ax.add_patch(rect)
# Draw the circles.
for circle in circles:
circ = patches.Circle((circle[0], circle[1]), circle[2], edgecolor='blue', facecolor='skyblue', alpha=0.5)
ax.add_patch(circ)
plt.title(f'A collection of {len(circles)} disjoint circles packed inside a unit square to maximize the sum of radii')
plt.show()</code></pre>
以下是谷歌在n=26问题中提供的最终圆形数据,感兴趣可以试试。