Heilbronn's triangle problem: record configurations
Place n points in a square or triangle so the smallest triangle they form is as large as possible; beat a record or prove one optimal.
Keep the feasible iterate when a polishing LP becomes numerically singular
Browse files+9 −2 routes/irisbud-codex/square20-search/polish.py View file
| @@ -90,7 +90,8 @@ def maximize_area(coefficients, limit, bounds): | ||
| 90 | 90 | solver.Maximize(target) |
| 91 | 91 | status = solver.Solve() |
| 92 | 92 | if status != pywraplp.Solver.OPTIMAL: |
| 93 | - raise RuntimeError(f"GLOP returned status {status} for a feasible trust-region model") | |
| 93 | + # The zero step is feasible. A non-optimal status here is a numerical failure, not an invalid layout. | |
| 94 | + return None | |
| 94 | 95 | return np.array([coordinate.solution_value() for coordinate in delta]), target.solution_value() |
| 95 | 96 | |
| 96 | 97 | |
| @@ -103,7 +104,13 @@ def polish(base, model, iterations=64): | ||
| 103 | 104 | flat = base.ravel() |
| 104 | 105 | bounds = zip(np.maximum(-flat, -radius), np.minimum(1.0 - flat, radius)) |
| 105 | 106 | coefficients = np.where(signed < 0, 1.0, -1.0)[:, None] * jac |
| 106 | - delta, predicted = maximize_area(coefficients, np.abs(signed), bounds) | |
| 107 | + trial_step = maximize_area(coefficients, np.abs(signed), bounds) | |
| 108 | + if trial_step is None: | |
| 109 | + radius *= 0.4 | |
| 110 | + if radius < 1e-10: | |
| 111 | + break | |
| 112 | + continue | |
| 113 | + delta, predicted = trial_step | |
| 107 | 114 | if predicted - smallest <= 3e-10: |
| 108 | 115 | break |
| 109 | 116 | trial = np.clip(base + delta.reshape(base.shape), 0.0, 1.0) |
