Evaluate the program by running it once and checking the sum of radii Args: program_path: Path to the program file Returns: Dictionary of metrics
(program_path)
| 184 | |
| 185 | |
| 186 | def evaluate(program_path): |
| 187 | """ |
| 188 | Evaluate the program by running it once and checking the sum of radii |
| 189 | |
| 190 | Args: |
| 191 | program_path: Path to the program file |
| 192 | |
| 193 | Returns: |
| 194 | Dictionary of metrics |
| 195 | """ |
| 196 | # Target value from the paper |
| 197 | TARGET_VALUE = 2.635 # AlphaEvolve result for n=26 |
| 198 | |
| 199 | try: |
| 200 | # For constructor-based approaches, a single evaluation is sufficient |
| 201 | # since the result is deterministic |
| 202 | start_time = time.time() |
| 203 | |
| 204 | # Use subprocess to run with timeout |
| 205 | centers, radii, reported_sum = run_with_timeout( |
| 206 | program_path, timeout_seconds=600 # Single timeout |
| 207 | ) |
| 208 | |
| 209 | end_time = time.time() |
| 210 | eval_time = end_time - start_time |
| 211 | |
| 212 | # Ensure centers and radii are numpy arrays |
| 213 | if not isinstance(centers, np.ndarray): |
| 214 | centers = np.array(centers) |
| 215 | if not isinstance(radii, np.ndarray): |
| 216 | radii = np.array(radii) |
| 217 | |
| 218 | # Check for NaN values before validation |
| 219 | if np.isnan(centers).any() or np.isnan(radii).any(): |
| 220 | print("NaN values detected in solution") |
| 221 | return { |
| 222 | "sum_radii": 0.0, |
| 223 | "target_ratio": 0.0, |
| 224 | "validity": 0.0, |
| 225 | "eval_time": float(time.time() - start_time), |
| 226 | "combined_score": 0.0, |
| 227 | } |
| 228 | |
| 229 | # Validate solution |
| 230 | valid = validate_packing(centers, radii) |
| 231 | |
| 232 | # Check shape and size |
| 233 | shape_valid = centers.shape == (26, 2) and radii.shape == (26,) |
| 234 | if not shape_valid: |
| 235 | print( |
| 236 | f"Invalid shapes: centers={centers.shape}, radii={radii.shape}, expected (26, 2) and (26,)" |
| 237 | ) |
| 238 | valid = False |
| 239 | |
| 240 | # Calculate sum |
| 241 | sum_radii = np.sum(radii) if valid else 0.0 |
| 242 | |
| 243 | # Make sure reported_sum matches the calculated sum |
no test coverage detected