1+ """Multi-objective LLaMEA example on a synthetic TSP variant.
2+
3+ This script shows how to:
4+ 1. Evaluate generated code against two objectives (Distance and Fuel).
5+ 2. Return objective values using ``Fitness``.
6+ 3. Run LLaMEA with ``multi_objective=True`` and objective keys.
7+ 4. Read final non-dominated solutions from ``ParetoArchive``.
8+ """
9+
110import os
211import random
312from typing import Optional
@@ -26,6 +35,7 @@ def __repr__(self):
2635
2736
2837def generate_tsp_test (seed : Optional [int ] = None , size : int = 10 ):
38+ """Generate a depot and customer set for the synthetic TSP task."""
2939 if seed is not None :
3040 random .seed (seed )
3141 depot = Location (0 , 50 , 50 , 0 )
@@ -46,6 +56,12 @@ def generate_tsp_test(seed: Optional[int] = None, size: int = 10):
4656 referable_dict [customer .id ] = customer
4757
4858def evaluate (solution : Solution , explogger : Optional [ExperimentLogger ] = None ):
59+ """Evaluate generated solver code on a two-objective TSP benchmark.
60+
61+ The generated class must return a permutation of customer ids. The evaluator
62+ validates the route, computes total travel distance and load-dependent fuel
63+ usage, then stores a ``Fitness`` object with both objectives.
64+ """
4965 code = solution .code
5066
5167 global_ns , issues = prepare_namespace (
@@ -180,7 +196,8 @@ def __call__():
180196 return customer_ids
181197"""
182198
183- llamea_inst = LLaMEA (f = evaluate ,
199+ # Multi-objective mode returns a Pareto archive instead of a single winner.
200+ llamea_inst = LLaMEA (f = evaluate ,
184201 llm = llm ,
185202 multi_objective = True ,
186203 max_workers = 3 ,
@@ -192,10 +209,11 @@ def __call__():
192209 example_prompt = example_prompt ,
193210 experiment_name = "MOO-TSP" ,
194211 minimization = True ,
195- budget = 27
212+ budget = 27
196213 )
197214
198215 solutions = llamea_inst .run ()
216+ # Keep only the final non-dominated set for reporting/inspection.
199217 if isinstance (solutions , ParetoArchive ):
200218 solutions = solutions .get_best ()
201219
@@ -206,4 +224,4 @@ def __call__():
206224 print (solutions .description )
207225 print (solutions .code )
208226 print (solutions .fitness )
209- print ("------------------------------------------------------------------------------------------------------------------------" )
227+ print ("------------------------------------------------------------------------------------------------------------------------" )
0 commit comments