This example demonstrates how to use the LoongFlow framework to solve a complex computational geometry optimization problem known as the Heilbronn Triangle Problem. The goal is to evolve a Python algorithm that finds a specific configuration of points within an equilateral triangle.
The objective is to place
For the detailed mathematical definition and problem context, please refer to the official repository: AlphaEvolve Results Repository
In this specific configuration (
-
initial_program.py: The starting seed code. It contains a basic function signaturerun_search_pointand a heuristic implementation (using Halton sequences and adaptive hybrid optimization) that needs to be evolved. -
eval_program.py: The evaluation logic. It executes the generated code in a secure/isolated manner, verifies geometric constraints (points inside the triangle, non-collinear), and calculates the score based on the target area ($0.0365$ ). -
task_config.yaml: The main configuration file defining the LLM prompt, evolution parameters (iterations, target score), and the agent components (Planner, Executor, Summarizer).
To start the evolution process, you need to use the math_agent_agent.py entry point. Ensure your PYTHONPATH includes the project root so that python can find the agents and evolux modules.
Ensure you are in the root directory of your local project (the directory containing agents/ and evolux/).
Run the following command to kick off the evolution. This command loads the base configuration and injects the initial code and evaluation logic from the respective files.
python agents/math_agent/math_agent_agent.py \
--config agents/math_agent/examples/heilbronn_problem_for_triangles/task_config.yaml \
--initial-file agents/math_agent/examples/heilbronn_problem_for_triangles/initial_program.py \
--eval-file agents/math_agent/examples/heilbronn_problem_for_triangles/eval_program.py \
--log-level INFOArguments Explanation:
--config: Path to the YAML configuration file (task_config.yaml).--initial-file: Path to the Python file containing the seed code (initial_program.py). The content of this file will be injected intoevolve.initial_code.--eval-file: Path to the Python file containing the evaluation logic (eval_program.py). The content will be injected intoevolve.evaluator.evaluate_code.--log-level: Sets the logging verbosity (e.g., INFO, DEBUG).
The task_config.yaml is pre-configured with the following strategies:
-
Planner:
evolve_planner(Handles the strategic direction of code modification). -
Executor:
evolve_executor_fuse(A powerful executor that fuses multiple thought processes/candidates). -
Summarizer:
evolve_summary(Summarizes the results of the execution for the next iteration). -
Target: The evolution aims to surpass the SOTA benchmark for
$n=11$ .
The system iterates through generations of code, attempting to maximize the minimum triangle area. Below are the results of the generated point configurations.
The best solution found by LoongFlow.
Result Metrics:
- Minimum Triangle Area: 0.0365210671221724 (Surpassing the SOTA of 0.036)
- TimeoutError: The
eval_program.pyenforces a strict timeout (default 3600s in config). If the generated code enters an infinite loop or takes too long to converge, it will be terminated and marked as a failure. - ModuleNotFoundError: Ensure your
PYTHONPATHis set correctly. You may need to runexport PYTHONPATH=$PYTHONPATH:.in the project root before running the command.