Skip to content

Commit 7d0b2ae

Browse files
committed
try evolving constuctors
1 parent 430925a commit 7d0b2ae

File tree

4 files changed

+290
-204
lines changed

4 files changed

+290
-204
lines changed

examples/circle_packing/README.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Circle Packing Example (n=26)
1+
# Constructor-Based Circle Packing Example (n=26)
22

33
This example attempts to replicate one of the specific results from the AlphaEvolve paper (Section B.12): packing 26 circles inside a unit square to maximize the sum of their radii.
44

@@ -8,35 +8,47 @@ The problem is to pack 26 disjoint circles inside a unit square so as to maximiz
88
- Lie entirely within the unit square [0,1] × [0,1]
99
- Not overlap with each other
1010

11-
This is a well-studied problem in computational geometry with applications in various fields including material science, facility location, and computer graphics.
11+
According to the paper, AlphaEvolve improved the state of the art for n=26 from 2.634 to 2.635.
1212

13-
## AlphaEvolve Result
13+
## Constructor-Based Approach
1414

15-
According to the paper, AlphaEvolve improved the state of the art for n=26 from 2.634 to 2.635.
15+
Following insights from the AlphaEvolve paper, we use a constructor-based approach rather than a search algorithm:
16+
17+
> "For problems with highly symmetric solutions it is advantageous to evolve constructor functions as these tend to be more concise." - AlphaEvolve paper, Section 2.1
18+
19+
Instead of evolving a search algorithm that tries different configurations, we evolve a function that directly constructs a specific packing arrangement. This approach:
20+
21+
1. Is more deterministic (produces the same output each time)
22+
2. Can leverage geometric knowledge about optimal packings
23+
3. Tends to be more concise and easier to evolve
24+
4. Works well for problems with inherent structure or symmetry
1625

1726
## Running the Example
1827

1928
```bash
20-
python openevolve-run.py examples/circle_packing/initial_program.py examples/circle_packing/evaluator.py --config examples/circle_packing/config.yaml --iterations 100
29+
python openevolve-run.py examples/circle_packing/initial_program.py examples/circle_packing/evaluator.py --config examples/circle_packing/config.yaml --iterations 200
2130
```
2231

32+
## Evolved Constructor Functions
33+
34+
The evolution might discover various pattern-based approaches:
35+
36+
1. **Concentric rings**: Placing circles in concentric rings around a central circle
37+
2. **Hexagonal patterns**: Portions of a hexagonal lattice (theoretically optimal for infinite packings)
38+
3. **Mixed-size arrangements**: Varying circle sizes to better utilize space near the boundaries
39+
4. **Specialized patterns**: Custom arrangements specific to n=26
40+
2341
## Evaluation Metrics
2442

2543
The evaluator calculates several metrics:
26-
- `sum_radii`: The best sum of radii achieved across all trials
27-
- `avg_sum_radii`: Average sum of radii across successful trials
44+
- `sum_radii`: The sum of radii achieved by the constructor
2845
- `target_ratio`: Ratio of achieved sum to target (2.635)
29-
- `reliability`: Fraction of trials that produced valid solutions
30-
- `avg_time`: Average execution time
31-
- `combined_score`: A weighted combination of the above metrics (main fitness metric)
32-
33-
## Expected Results
34-
35-
A successful run should find a packing arrangement with sum of radii approaching or exceeding the value reported in the AlphaEvolve paper: 2.635 for n=26.
46+
- `validity`: Confirms circles don't overlap and stay within bounds
47+
- `combined_score`: A weighted combination of metrics (main fitness metric)
3648

3749
## Visualization
3850

39-
The initial program includes a visualization function that you can use to see the packing arrangement:
51+
The program includes a visualization function to see the constructed packing:
4052

4153
```python
4254
# Add this to the end of the best program
@@ -45,3 +57,9 @@ if __name__ == "__main__":
4557
print(f"Sum of radii: {sum_radii}")
4658
visualize(centers, radii)
4759
```
60+
61+
## What to Expect
62+
63+
The evolution process should discover increasingly better constructor functions, with several possible patterns emerging. Given enough iterations, it should approach or exceed the 2.635 value achieved in the paper.
64+
65+
Different runs may converge to different packing strategies, as multiple near-optimal arrangements are possible for this problem.

examples/circle_packing/config.yaml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Configuration for circle packing example
2-
max_iterations: 100
1+
# Configuration for circle packing constructor evolution (n=26)
2+
max_iterations: 100 # Increased iterations
33
checkpoint_interval: 10
44
log_level: "INFO"
5-
max_code_length: 100000
65

76
# LLM configuration
87
llm:
@@ -21,16 +20,27 @@ llm:
2120

2221
# Prompt configuration
2322
prompt:
24-
system_message: "You are an expert programmer specializing in optimization algorithms and computational geometry. Your task is to improve a circle packing algorithm to maximize the sum of radii when packing 26 circles in a unit square without overlaps. The AlphaEvolve paper achieved a sum of 2.635 for n=26, which is the target value to reach or exceed. Focus on finding better optimization strategies, leveraging geometric insights about optimal packing arrangements, and developing more effective search techniques."
23+
system_message: |
24+
You are an expert mathematician specializing in circle packing problems and computational geometry. Your task is to improve a constructor function that directly produces a specific arrangement of 26 circles in a unit square, maximizing the sum of their radii. The AlphaEvolve paper achieved a sum of 2.635 for n=26.
25+
26+
Key geometric insights:
27+
- Circle packings often follow hexagonal patterns in the densest regions
28+
- Maximum density for infinite circle packing is pi/(2*sqrt(3)) ≈ 0.9069
29+
- Edge effects make square container packing harder than infinite packing
30+
- Circles can be placed in layers or shells when confined to a square
31+
- Similar radius circles often form regular patterns, while varied radii allow better space utilization
32+
- Perfect symmetry may not yield the optimal packing due to edge effects
33+
34+
Focus on designing an explicit constructor that places each circle in a specific position, rather than an iterative search algorithm.
2535
num_top_programs: 3
2636
use_template_stochasticity: true
2737

2838
# Database configuration
2939
database:
30-
population_size: 50
31-
archive_size: 20
32-
num_islands: 3
33-
elite_selection_ratio: 0.2
40+
population_size: 60 # Increased population for more diversity
41+
archive_size: 25
42+
num_islands: 4
43+
elite_selection_ratio: 0.3
3444
exploitation_ratio: 0.7
3545

3646
# Evaluator configuration
@@ -42,5 +52,5 @@ evaluator:
4252
use_llm_feedback: false
4353

4454
# Evolution settings
45-
diff_based_evolution: true
46-
allow_full_rewrites: false
55+
diff_based_evolution: false # Use full rewrites instead of diffs
56+
allow_full_rewrites: true # Allow full rewrites for constructor functions

0 commit comments

Comments
 (0)