cf6bc4c844
runner 用 Docker 跑一条命令并交回结局和资源用量;tasks 读 task.json、准备运行目录、给出正式运行/校验器/轻量检查的运行定义,并从原始产物独立判分。任务目录从参考项目搬到 tasks/circle_packing/,新增 task.json;vocab 的 VERDICTS 删掉"判不了",ProcessResult 的 cancelled 改为"容器从外面被杀了"。 全新上下文审阅后的两处修复:计量 shell 以容器内 root 运行,命令经 setpriv 降权,结果写在容器自己的文件层、结束后 docker cp 取出,并加 no-new-privileges,候选无法伪造计量结果把超时记成正常退出;harness 开跑前删掉旧的 solution.json、metrics.json,旧产物不会被当成本次的值。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
3.1 KiB
Python
101 lines
3.1 KiB
Python
# EVOLVE-BLOCK-START
|
|
"""Constructor-based circle packing for n=26 circles"""
|
|
|
|
import numpy as np
|
|
|
|
|
|
def construct_packing():
|
|
"""
|
|
Construct a specific arrangement of 26 circles in a unit square
|
|
that attempts to maximize the sum of their radii.
|
|
|
|
Returns:
|
|
Tuple of (centers, radii, sum_of_radii)
|
|
centers: np.array of shape (26, 2) with (x, y) coordinates
|
|
radii: np.array of shape (26) with radius of each circle
|
|
sum_of_radii: Sum of all radii
|
|
"""
|
|
# Initialize arrays for 26 circles
|
|
n = 26
|
|
centers = np.zeros((n, 2))
|
|
|
|
# Place circles in a structured pattern
|
|
# This is a simple pattern - evolution will improve this
|
|
|
|
# First, place a large circle in the center
|
|
centers[0] = [0.5, 0.5]
|
|
|
|
# Place 8 circles around it in a ring
|
|
for i in range(8):
|
|
angle = 2 * np.pi * i / 8
|
|
centers[i + 1] = [0.5 + 0.3 * np.cos(angle), 0.5 + 0.3 * np.sin(angle)]
|
|
|
|
# Place 16 more circles in an outer ring
|
|
for i in range(16):
|
|
angle = 2 * np.pi * i / 16
|
|
centers[i + 9] = [0.5 + 0.7 * np.cos(angle), 0.5 + 0.7 * np.sin(angle)]
|
|
|
|
# Additional positioning adjustment to make sure all circles
|
|
# are inside the square and don't overlap
|
|
# Clip to ensure everything is inside the unit square
|
|
centers = np.clip(centers, 0.01, 0.99)
|
|
|
|
# Compute maximum valid radii for this configuration
|
|
radii = compute_max_radii(centers)
|
|
return centers, radii
|
|
|
|
|
|
def compute_max_radii(centers):
|
|
"""
|
|
Compute the maximum possible radii for each circle position
|
|
such that they don't overlap and stay within the unit square.
|
|
|
|
Args:
|
|
centers: np.array of shape (n, 2) with (x, y) coordinates
|
|
|
|
Returns:
|
|
np.array of shape (n) with radius of each circle
|
|
"""
|
|
n = centers.shape[0]
|
|
radii = np.ones(n)
|
|
|
|
# First, limit by distance to square borders
|
|
for i in range(n):
|
|
x, y = centers[i]
|
|
# Distance to borders
|
|
radii[i] = min(x, y, 1 - x, 1 - y)
|
|
|
|
for i in range(n):
|
|
for j in range(i + 1, n):
|
|
dist = np.sqrt(np.sum((centers[i] - centers[j]) ** 2))
|
|
|
|
# Then, limit by distance to other circles
|
|
# Each pair of circles with centers at distance d can have
|
|
# sum of radii at most d to avoid overlap
|
|
for i in range(n):
|
|
for j in range(i + 1, n):
|
|
dist = np.sqrt(np.sum((centers[i] - centers[j]) ** 2))
|
|
|
|
# If current radii would cause overlap
|
|
if radii[i] + radii[j] > dist:
|
|
# Scale both radii proportionally
|
|
scale = dist / (radii[i] + radii[j])
|
|
radii[i] *= scale
|
|
radii[j] *= scale
|
|
|
|
# Ensure no negative radii due to numerical issues
|
|
radii = np.maximum(radii, 0.0)
|
|
return radii
|
|
|
|
|
|
# EVOLVE-BLOCK-END
|
|
|
|
|
|
# This part remains fixed (not evolved)
|
|
def run_packing():
|
|
"""Run the circle packing constructor for n=26"""
|
|
centers, radii = construct_packing()
|
|
# Calculate the sum of radii
|
|
sum_radii = np.sum(radii)
|
|
return centers, radii, sum_radii
|