A heuristic automatic design method based on large language model and evolutionary calculation
Patent Information
- Application Number
- CN202611433703.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-16
- Publication Date
- 2026-10-20
AI Technical Summary
[0013]为了克服现有技术的不足,本发明的目的在于提供一种基于大语言模型与进化计算的启发式自动设计方法,旨在解决现有技术中启发式设计与代码实现割裂、提示词策略单一、模型后端与问题定义难以复用、评估效率不足以及实验产物不完整的问题
通过将每个候选启发式表示为包含自然语言格式的算法思维描述数据和可执行代码的联合数据结构,并在统一的进化循环中对其进行选择、生成、评估和管理,实现了算法思维与代码实现的协同演化,避免了二者割裂的问题;通过预设至少包括用于改变算法逻辑结构的探索策略和用于调整算法参数的修改策略的提示词策略集合,能够同时进行全局探索和局部改良,有效维持种群多样性,降低早熟收敛风险;通过统一的问题定义框架和大语言模型接口模块,实现了问题定义与模型后端的可插拔,提高了系统的通用性和复用性;通过评估加速、并行计算、超时控制以及结果归档机制,降低了自动设计的计算成本,并确保了实验的可复现性和完整性。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a heuristic automatic design method based on large language models and evolutionary computation. Background Technology
[0002] Heuristic algorithms are a common approach for solving combinatorial optimization problems such as bin packing, path planning, scheduling, and hyperparameter search. These problems have large solution spaces and complex constraints, typically belonging to NP-hard problems, where exact algorithms struggle to provide high-quality solutions within acceptable timeframes. In engineering practice, heuristic design has long relied on trial and error by domain experts: it requires simultaneously providing the algorithmic idea, scoring function or local search rules, and executable code implementation. This process is costly, time-consuming, and difficult to reuse across multiple tasks.
[0003] In recent years, large language models have demonstrated the ability to generate algorithmic ideas and code based on natural language task descriptions; evolutionary computation excels at maintaining diversity and gradually improving fitness in candidate populations through selection, crossover, and mutation. Combining these two approaches can transform heuristic design from expert-written rules to automatic search within the code space, forming a new paradigm of Automatic Heuristic Design (AHD). This paradigm has shown potential in tasks such as online bin packing, the Traveling Salesman Problem (TSP), flow shop scheduling, and Bayesian optimization. Existing heuristic designs mainly include the following categories: (1) Manually designed heuristic: For problems such as packing, TSP, and vehicle routing, experts design rules such as nearest neighbor, cost saving, and guiding local search based on domain knowledge. This method is highly interpretable, but it relies on expert experience and is difficult to cover diverse instance distributions.
[0004] (2) Program search and function search methods: Methods represented by FunSearch use large language models to iteratively improve function implementations in a program database, which can discover programs that are superior to those designed manually in some mathematical and combinatoric problems. FunSearch pairs a pre-trained large language model with a systematic evaluator and evolves the initial low-scoring program into a high-scoring program through an evolutionary process. Its focus is on function-level iterative improvement. It usually lacks a unified problem access for various combinatorial optimization tasks, coordination of multiple prompt word strategies, and pluggable selection / population management operators.
[0005] (3) Evolutionary heuristic framework: Some studies use evolutionary computation for hyperheuristics or algorithm configuration, improving the quality of solutions by selecting combinations of existing operators. These methods usually search within a predefined set of operators, making it difficult to directly generate entirely new heuristic code.
[0006] (4) Generate code for general large language models. Direct prompts for large language models to write heuristic code at once lack population management, closed-loop evaluation of objective functions and diversity maintenance mechanisms. The generated results are unstable and difficult to continuously improve under limited computational budget.
[0007] The existing technology has the following main drawbacks: First, heuristic design is disconnected from code implementation: existing methods often only generate natural language ideas or search for code snippets, failing to update the algorithmic thinking description and executable code as a single entity within the evolutionary framework, resulting in inconsistencies between ideas and implementations and unreproducible evaluation results.
[0008] Second, the cue word strategy is too simplistic: using only initialization or single mutation cue words easily leads to rapid homogenization of the population. There is a lack of differentiation between exploratory mutation and modification mutation; the former encourages structural differences, while the latter encourages local improvements and parameter resetting.
[0009] Third, the large language model backend and problem definition are not plug-and-play compatible: In actual deployment, it is necessary to switch between remote OpenAI compatible interfaces, HuggingFace inference interfaces, and local large language model services, while simultaneously addressing different issues such as binning, TSP, scheduling, and Bayesian optimization. Existing prototypes typically hardcode model calls and problem evaluations in scripts, resulting in high expansion costs.
[0010] Fourth, there are shortcomings in evaluation efficiency and population management: heuristic evaluation often requires repeated calculation of the objective function for multiple instances, lacking an acceleration mechanism; population updates lack alternative strategies such as greedy retention and local search, which can easily lead to the loss of high-quality individuals or getting stuck in local optima.
[0011] Fifth, the experimental products are incomplete: the lack of population archives, optimal individual export, and automatic generation of summary reports is not conducive to the reproduction of experiments, ablation analysis, and secondary research.
[0012] Therefore, existing technologies still need to be improved and developed. Summary of the Invention
[0013] To overcome the shortcomings of existing technologies, the present invention aims to provide a heuristic automatic design method based on large language models and evolutionary computation, which addresses the problems of separation between heuristic design and code implementation, single prompt word strategy, difficulty in reusing model backend and problem definition, insufficient evaluation efficiency, and incomplete experimental results in existing technologies.
[0014] The first aspect of this invention provides a heuristic automatic design method based on a large language model and evolutionary computation, comprising the steps of: acquiring task description data and an evaluation function for a target optimization problem; initializing a current population, wherein each candidate individual in the current population, as well as subsequent parent individuals and offspring individuals, are represented as a joint data structure, the joint data structure containing algorithmic thought description data in natural language format and executable code; selecting parent individuals from the current population; assembling the algorithmic thought description data and executable code of the parent individuals into prompts based on a preset set of prompt strategy, and calling a large language model to generate an offspring joint data structure, wherein the prompt strategy set includes at least an exploration strategy for changing the algorithmic logic structure and a modification strategy for adjusting algorithm parameters, the exploration strategy including a first exploration strategy and a second exploration strategy, and the modification strategy including a first modification strategy and a second modification strategy; when the first exploration strategy is adopted, the prompts are assembled to guide the large language model to generate algorithms that tend to be consistent with all the algorithmic logic structures. A new algorithm is developed where each selected parent individual is unique. When the second exploration strategy is adopted, prompts are assembled to extract the common core algorithmic ideas of the selected parent individuals, and a new algorithm variant is generated based on these core ideas. When the first modification strategy is adopted, prompts are assembled to generate an improved version based on a single parent individual. When the second modification strategy is adopted, prompts are assembled to identify the adjustable parameters of the parent individuals and generate a new algorithm with reset parameter values. The offspring algorithmic thinking description data and offspring executable code are parsed from the offspring joint data structure to construct a complete offspring individual. Based on the obtained evaluation function, the offspring executable code is run and calculated on the instance data of the target optimization problem to obtain the objective function value of the offspring individual. Based on the objective function value of each offspring individual, the current population is updated, and it is determined whether the stopping condition is met. If not, the process returns to the step of selecting parent individuals from the current population and subsequent steps. If yes, the design result containing the final population and / or the optimal individual is output.
[0015] A second aspect of this invention provides a heuristic automatic design device based on a large language model and evolutionary computation, comprising: an acquisition module for acquiring task description data and an evaluation function for a target optimization problem; an initialization module for initializing a current population, wherein each candidate individual in the current population, as well as subsequent parent individuals and offspring individuals, are represented as a joint data structure, the joint data structure containing algorithmic thought description data in natural language format and executable code; a selection module for selecting parent individuals from the current population; and an assembly module for assembling the algorithmic thought description data and executable code of the parent individuals into prompts based on a preset set of prompt strategy, and calling a large language model to generate an offspring joint data structure, wherein the prompt strategy set includes at least an exploration strategy for changing the algorithmic logic structure and a modification strategy for adjusting algorithm parameters, the exploration strategy including a first exploration strategy and a second exploration strategy, and the modification strategy including a first modification strategy and a second modification strategy; when the first exploration strategy is adopted, the prompts are assembled to guide the large language model to generate a structure that tends towards a certain algorithmic logic structure. A novel algorithm, distinct from all selected parent individuals, is employed. When using the second exploration strategy, prompts are assembled to extract the common core algorithmic ideas of the selected parent individuals, and a new algorithm variant is generated based on these core ideas. When using the first modification strategy, prompts are assembled to generate an improved version based on a single parent individual. When using the second modification strategy, prompts are assembled to identify the adjustable parameters of the parent individuals and generate a new algorithm with reset parameter values. A parsing module is used to parse the offspring algorithmic thinking description data and offspring executable code from the offspring joint data structure to construct a complete offspring individual. A calculation module is used to run the offspring executable code on the instance data of the target optimization problem based on the obtained evaluation function, obtaining the objective function value of the offspring individual. An update module is used to update the current population based on the objective function values of each offspring individual and determine whether the stopping condition is met. If not, the process returns to the step of selecting parent individuals from the current population and subsequent steps; if yes, the design result containing the final population and / or the optimal individual is output.
[0016] A third aspect of the present invention provides an electronic device comprising: a memory and at least one processor, the memory storing computer-readable instructions, the memory and the at least one processor being interconnected via a circuit; the at least one processor invokes the computer-readable instructions in the memory to cause the electronic device to perform the steps of the heuristic automatic design method based on large language models and evolutionary computation as described above.
[0017] A fourth aspect of the present invention provides a computer-readable storage medium storing computer-readable instructions that, when executed on a computer, cause the computer to perform the steps of the heuristic automatic design method based on a large language model and evolutionary computation as described above.
[0018] Through the above technical solution, the present invention has the following beneficial effects: By representing each candidate heuristic as a joint data structure containing algorithmic thinking description data in natural language format and executable code, and selecting, generating, evaluating, and managing them in a unified evolutionary loop, the co-evolution of algorithmic thinking and code implementation is achieved, avoiding the problem of their separation. By pre-setting a set of prompting strategies, including at least exploration strategies for changing the algorithm's logical structure and modification strategies for adjusting algorithm parameters, global exploration and local improvement can be performed simultaneously, effectively maintaining population diversity and reducing the risk of premature convergence. Through a unified problem definition framework and a large language model interface module, the problem definition and model backend are pluggable, improving the system's versatility and reusability. Through evaluation acceleration, parallel computing, timeout control, and result archiving mechanisms, the computational cost of automated design is reduced, and the reproducibility and integrity of experiments are ensured. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0020] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 A flowchart of a heuristic automatic design method based on a large language model and evolutionary computation provided in an embodiment of the present invention.
[0022] Figure 2 This is a schematic diagram of the heuristic automatic design device based on large language models and evolutionary computation provided by the present invention.
[0023] Figure 3 This is a schematic diagram of the electronic device structure provided by the present invention. Detailed Implementation
[0024] This invention provides a heuristic automatic design method, apparatus, device, and storage medium based on large language models and evolutionary computation. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" or "having" and any variations thereof are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0025] The technical solution of this invention is mainly applied to the automatic design and generation of combinatorial optimization algorithms. It can automatically explore high-performance heuristic algorithm code for specific problems without relying on manual design by experts. This usually involves problems such as online packing, traveling salesman problem, and production scheduling.
[0026] The following are explanations of several key terms involved in this invention: A joint data structure refers to a data object internally used to represent a candidate heuristic. This object contains at least two core fields: a description of the algorithmic thinking (natural_language_description, or algorithm) and executable code (executable_code, or code). This data structure ensures that the algorithm's conception and implementation are always treated, evaluated, and updated as a whole during the evolution process.
[0027] Exploration strategy: A cue word assembly strategy whose core purpose is to encourage large language models to generate new algorithms that differ significantly from their parents in algorithmic logical structure, thereby expanding the search space and maintaining population diversity. Exploration strategies include specific forms such as primary exploration strategies and secondary exploration strategies.
[0028] Modification strategy: A prompt word assembly strategy whose core purpose is to encourage large language models to make local adjustments or refinements based on the parent algorithm, such as improving the implementation process or adjusting parameters, to achieve incremental performance optimization. Modification strategies include specific forms such as the first modification strategy and the second modification strategy.
[0029] Problem package: A pre-packaged data module that defines information related to a specific optimization problem. It typically includes at least a natural language description of the task, the function signature (name, parameters, and return type) of the expected heuristic function, an evaluation function interface, and instance data available for testing. By loading different problem packages, the system can reuse the core evolutionary process to handle different problems.
[0030] The unified large language model interface module is an internal abstraction layer that encapsulates the specific call details for different large language model services (such as remote APIs and locally deployed services), providing a unified call function to the outside world. The system automatically switches and adapts to the specific backend services called at the underlying level based on user-configured endpoint information.
[0031] Results directory: This refers to a folder created on the local file system to store all the outputs of a complete experiment. Its contents typically include state snapshots (serialized files) of each generation of the population, the code and description of the best individual, the execution log, and the final generated summary report.
[0032] Please see Figure 1 , Figure 1 A flowchart of a heuristic automatic design method based on a large language model and evolutionary computation provided by this invention is shown in the figure, which includes the following steps: S10. Obtain the task description data and evaluation function for the target optimization problem; S20. Initialize the current population, wherein each candidate individual in the current population, as well as subsequent parent individuals and offspring individuals, are represented as a joint data structure, which contains algorithmic thinking description data in natural language format and executable code; S30. Select parental individuals from the current population; S40. Based on a preset set of prompting word strategies, the algorithmic thinking description data and executable code of the parent individuals are assembled into prompting words, and a large language model is called to generate a joint data structure for offspring. The prompting word strategy set includes at least an exploration strategy for changing the algorithm's logical structure and a modification strategy for adjusting algorithm parameters. The exploration strategy includes a first exploration strategy and a second exploration strategy, and the modification strategy includes a first modification strategy and a second modification strategy. When the first exploration strategy is used, prompting words are assembled to guide the large language model to generate a new algorithm whose logical structure tends to be different from all selected parent individuals. When the second exploration strategy is used, prompting words are assembled to request the extraction of the common core algorithmic ideas of the selected parent individuals, and a new algorithm variant is generated based on the core algorithmic ideas. When the first modification strategy is used, prompting words are assembled to generate an improved version based on a single parent individual. When the second modification strategy is used, prompting words are assembled to identify the adjustable parameters of the parent individuals and generate a new algorithm with reset parameter values. S50. Parse the child algorithm thinking description data and child executable code from the child joint data structure to construct a complete child individual; S60. Based on the obtained evaluation function, the offspring executable code is run and calculated on the instance data of the target optimization problem to obtain the target function value of the offspring individual; S70. Based on the objective function value of each offspring individual, update the current population and determine whether the stopping condition is met. If not, return to step S30 and its subsequent steps; if yes, output the design result containing the final population and / or the optimal individual.
[0033] In this embodiment, the above steps work together to form a complete heuristic automatic evolutionary loop. Steps S10 and S20 prepare the input (problem definition) and initial search starting point (initial population) for the loop. Steps S30 to S60 are the core iterative generation stages of the loop: parents are selected from the population with current performance evaluation (objective function value) through a selection strategy; then, diverse prompt word strategies (S40) are used to assemble a guided input with executable code, driving the large language model to generate a joint data structure of offspring with new ideas and implementations; then, the data structure is precisely parsed to obtain complete offspring individuals; subsequently, their actual performance is quantified through objective function evaluation (S60). Step S70 updates the population based on the evaluation results, forming a survival of the fittest, and decides whether to continue the search. This method solves the key problem of the separation between thought and implementation, because the objects of evolution, evaluation, and selection are always individuals of a joint data structure containing thought description data and executable code, ensuring the consistency between the concept and the final execution effect. The combined use of multiple prompting strategies can effectively balance the exploration of new regions and the improvement of existing high-quality solutions, thus giving us a greater chance to discover high-performance heuristic algorithms within a limited number of evolutionary generations.
[0034] Taking a specific application scenario as an example, suppose the objective optimization problem is the online bin packing problem. The goal is to design a heuristic function that minimizes the number of bins into which items arrive in a given order. The signature of the heuristic function to be generated can be defined as: def select_bin(item size float,remaining capacities List[float], bin capacity : float) → int: where the input parameter includes: item size Indicates the size of items arriving in sequence; remaining capacities This indicates the remaining capacity of currently opened boxes; bincapacity This represents the fixed capacity of each box; the output parameter is an integer index; the return value is: if 0, it returns a value between len(remaining). capacities )-1 indicates that the current item will be placed in the existing box at the corresponding index; if len(remaining) is returned, then len(remaining) will be returned. capacities The expression `(a)` indicates that a new box has been opened. The evaluation function reads items sequentially, calls the heuristic function to select a box, updates the remaining capacity of each box, and finally uses the total number of boxes used as the objective value for that instance. The objective function value is obtained by averaging across multiple instances. This clearly defines the input, output, and return value of the heuristic function in the online bin packing problem, while also connecting it with the calculation process of the evaluation function.
[0035] Specifically, firstly, the system loads the online bin packing problem package through a unified problem definition framework, obtaining its task description (e.g., design an online bin packing algorithm to process items sequentially and minimize the number of bins used) and evaluation function interface (S10); next, the system initializes a current population containing 4 randomly generated individuals, each individual being a text describing the algorithm's logic and a piece of executable Python function code (S20); after entering the evolutionary loop, the system uses a probability ranking strategy to select 2 parent individuals from the current 4 individuals (S30); assuming that the first modification strategy is triggered in this iteration (m1), the system will select the single parent individual... The individual's thought description and code are assembled into specific prompt words, requiring the large language model to generate an improved version. The large language model returns text containing the new description and code (S40). The system uses regular expressions to extract the new algorithm description and complete function definition code segments, constructing offspring individuals (S50). Subsequently, in a multi-process parallel environment, the system uses just-in-time compilation technology to accelerate the process, calling the evaluation function to run a batch of standard test instances on the new offspring code, calculating the average number of boxes used as the objective function value (S60). Based on the objective function values of all offspring individuals, the system updates the current population using a greedy retention strategy, maintaining the population size at 4. If the preset 50-generation iteration stopping condition is not met, S30-S70 are repeated. Finally, the system outputs the entire population after 50 generations of evolution and the best-performing individual among them; the executable code of this individual is the automatically designed heuristic algorithm (S70).
[0036] In this embodiment, the aforementioned set of prompting strategies includes a first exploration strategy and a second exploration strategy, and a first modification strategy and a second modification strategy. The process of assembling prompting words based on the preset set of prompting strategies, specifically, involves: when using the first exploration strategy, assembling prompting words to guide the large language model to generate a new algorithm whose logical structure differs from all selected parent individuals; when using the second exploration strategy, assembling prompting words to extract the common core algorithmic ideas of the selected parent individuals and generating a new algorithm variant based on these core ideas; when using the first modification strategy, assembling prompting words to generate an improved version based on a single parent individual; and when using the second modification strategy, assembling prompting words to identify the adjustable parameters of the parent individual and generate a new algorithm with reset parameter values.
[0037] In this embodiment, the prompt word strategy set also includes an initialization strategy (i1). The initialization strategy (i1), without relying on the parent algorithm, requires the model to first describe the new algorithm in curly braces with a single sentence, and then implement the code according to the function signature given in the problem. The first exploration strategy (e1) focuses on differentiation, forcing the new algorithm to differ from all parent algorithms in its overall logical structure, directly pushing the search out of the local optimum region that the current population might be trapped in, thereby expanding the global exploration scope. The second exploration strategy (e2) focuses on variant exploration while maintaining the core ideas of the discovered effective algorithms. This helps to search for better specific implementations within an algorithm framework with certain performance guarantees, balancing the depth and stability of the exploration. The first modification strategy (m1) iteratively improves a single high-quality individual, which can be regarded as a targeted local search, helping to achieve performance improvement through creative fine-tuning of the model based on excellent candidate solutions. The second modification strategy (m2) focuses on parameter refinement. For many heuristic algorithms, the values of key parameters have a significant impact on their performance. This strategy identifies and resets these parameters, enabling fine-grained optimization of algorithm performance with relatively low structural modification costs. Furthermore, combining the above principles, the collaborative approach of these five strategies (initialization i1, exploration strategies e1 and e2, and modification strategies m1 and m2) allows for a systematic search of the code space across multiple dimensions during evolution, including initialization, global structure exploration, core idea variants, individual iterative improvements, and parameter tuning. This significantly reduces the risk of premature convergence and homogenization in the population and increases the probability of discovering novel and efficient heuristics. As a specific implementation, these five prompting strategies have different internal structures and collaborative relationships. They share a basic task description template but differ in their parent input and generation requirements.
[0038] In some optional implementations, the five prompt word strategies described above can be configured with different trigger probabilities. For example, the initialization strategy is only used initially, while the exploratory and modification mutation strategies are sampled and triggered in the main loop with certain probabilities (e.g., e1: 0.2, e2: 0.2, m1: 0.3, m2: 0.3). In other optional implementations, the population size can be set to smaller values such as 4, 5, or 10, and the number of iterations can be set to 50, 100, or more to accommodate different computational budgets. The number of parallel processes can be set to 4 or automatically adapted to the number of local CPU cores. During initialization, an initial population can be generated from scratch using a large language model, or an existing seed code (seed population) can be loaded as the starting point for evolution.
[0039] In some implementations, the step of parsing the child algorithm thought description data and child executable code from the child federated data structure specifically includes: using regular expressions to extract text located between specific identifiers from the child federated data structure as child algorithm thought description data; and using regular expressions to extract code segments containing function definitions from the child federated data structure as child executable code.
[0040] Specifically, this embodiment uses regular expressions for precise extraction, which can quickly and reliably extract structured algorithmic thinking description data and executable code from the potentially irregularly formatted text returned by the large language model, ensuring the accuracy of subsequent generation of offspring. In this embodiment, if parsing fails, a limited number of retries are performed to regenerate and parse the offspring's joint data structure. By setting a limited retry mechanism (e.g., a maximum of 3 times), when parsing fails (e.g., the model does not return in the required format), the large language model is automatically invoked again to generate a new response, avoiding the silent discarding of the entire offspring or the introduction of invalid code due to a single non-compliant generation, thus improving the robustness and resource utilization of the evolutionary process. Furthermore, based on the above principles, this method can ensure the automation and high success rate of the conversion process between the output of the large language model and the internally processable individuals, reducing the need for manual intervention. As a specific implementation method, the system presupposes that the thought description data is located within a pair of curly braces {} and extracts it using the regular expression pattern r'\{([^}]+)\}'; for executable code, it extracts it by recognizing function definition blocks that begin with the def keyword until the corresponding indentation ends or the end of the file is encountered.
[0041] In some implementations, for the selection of parent individuals from the current population mentioned above, a probabilistic ranking strategy or a tournament strategy is used. For updating the current population based on the objective function values of each offspring individual, a greedy retention strategy or a local search strategy is used to trim the current population size to a preset size. The probabilistic ranking strategy allocates selection probabilities based on the individual's ranking in the population according to the objective function value. The higher the ranking (the better the performance), the higher the probability of being selected. This ensures that the direction of evolutionary pressure is consistent with the direction of performance optimization, while avoiding premature convergence caused by excessively large differences in the absolute value of the objective function value in the roulette wheel strategy. The tournament strategy randomly selects a small number of individuals for comparison and selects the best as parents. This method allows for adjustable selection pressure and naturally supports parallelization. When updating the population using the greedy retention strategy, the system simply merges all the old and new individuals and sorts them according to the objective function value, retaining only the top pop_size (preset size) best individuals. This method is simple and efficient, ensuring that the population elites are preserved. Local search strategies, while preserving the elite, may further randomize or search within the code neighborhood of some individuals, attempting to discover better solutions and helping to escape local optima. Furthermore, combining the above principles, employing these configurable and pluggable selection and population management operators allows the system to flexibly adapt to the characteristics of different problems or the experimental needs of researchers (e.g., emphasizing exploration or convergence speed), improving the method's versatility and experimental feasibility.
[0042] In some implementations, the step of running the sub-executable code on instance data of the target optimization problem based on the acquired evaluation function specifically includes: accelerating the execution of the sub-executable code through just-in-time compilation decoration; evaluating multiple candidate sub-executable codes in a multi-process parallel manner; setting a timeout threshold for the execution process, and determining that the candidate sub-executable code fails the evaluation and does not participate in the elite selection if the timeout occurs.
[0043] Specifically, this embodiment accelerates code execution through just-in-time compilation decoration, significantly reducing the computation time spent repeatedly executing the same individual on the same batch of evaluation instances. This is crucial for evolutionary processes requiring extensive evaluation, directly reducing the overall computational cost of a single experiment. Employing a multi-process parallel approach to evaluate multiple candidate offspring executables fully utilizes the computing resources of modern multi-core CPUs, executing previously serial evaluation tasks concurrently, thereby drastically shortening the time required for each generation of evolution and improving system efficiency. Setting a timeout threshold and classifying timeout individuals as failures prevents the evaluation process from stalling due to defects such as infinite loops or extremely low efficiency in some offspring executables, ensuring smooth evolutionary cycles and avoiding invalid individuals occupying elite slots. Furthermore, based on the above principles, this approach effectively addresses the core challenge of high evaluation overhead in heuristic automatic design while ensuring the accuracy of evaluation results, making it possible to perform more rounds of evolutionary iterations within limited computing resources and time.
[0044] In some alternative implementations, the just-in-time (JIT) compiler decorator used for evaluation acceleration can be the `@jit` decorator from Python's Numba library (`nopython=True`) to pursue maximum performance. The timeout threshold can be set based on the problem's complexity and instance size, for example, 2 seconds or 5 seconds; the tournament strategy in the selected operator, its tournament size... size The value can be set to 2 or 3; the greedy retention strategy directly sorts the populations by objective function value after merging the old and new populations; while the local search strategy can be to randomly replace the syntax subtree or perturb the parameters of the elite individual codes.
[0045] In some implementations, obtaining the task description data and evaluation function of the target optimization problem specifically includes: loading a problem package corresponding to the target optimization problem through a unified problem definition framework, and obtaining the task description data and evaluation function of the target optimization problem. The problem package at least includes a natural language description of the task, a signature of the function to be generated, and an evaluation function interface.
[0046] In this embodiment, through a unified problem definition framework, the system can abstract specific combinatorial optimization problems into standardized problem packages for management. When a new problem needs to be addressed, developers only need to create a new problem package containing a natural language description, a signature of the function to be generated, and an evaluation function interface according to the framework conventions, without modifying the core main loop logic such as evolution generation, selection, and evaluation. This design decouples the problem definition from the core evolutionary engine, greatly improving the system's scalability and cross-task reusability. Furthermore, based on the above principles, this approach can be quickly applied to a wide range of combinatorial optimization problem domains. For example, switching from the bin packing problem to the traveling salesman problem only requires changing the problem package, significantly reducing the application threshold and development costs. As a specific implementation, the system pre-configures several standard problem packages, including online bin packing, greedy construction of the traveling salesman problem, flow shop scheduling, and Bayesian optimization hyperparameter search.
[0047] In this embodiment, the evaluation function is provided by the problem package, and its interface can be defined as: evaluate(heuristic) fn instance data ) → float. Where, heuristic fn For the callable function corresponding to the child executable code, instance data The objective is to optimize a dataset of instances. The evaluation function works as follows: for each instance in the dataset, the heuristic algorithm is called... fn The process involves generating candidate solutions for the given instance; calculating the objective value of each candidate solution based on the objective function of the optimization problem; and aggregating the objective values of all instances (e.g., by averaging, summing, or normalizing the weighted values) to obtain the objective function value for the offspring. The specific internal implementation of the evaluation function is related to the optimization problem, and the system calls it through a unified interface without modifying the core evolutionary process. For example, the evaluation function first iterates through the instance dataset, calling the offspring executable code for each instance to obtain the decision result; then it calculates the objective function value corresponding to the decision based on the problem definition; finally, it averages the objective function values of multiple instances to obtain the final objective function value for the offspring.
[0048] In some implementations, the steps for generating the progeny joint data structure by calling the large language model, as mentioned above, specifically include: switching between multiple backend services based on system configuration through a unified large language model interface module. These backend services include remote compatibility APIs, inference APIs, and local model services. During initialization, a probe request is sent to the backend services to verify interface availability. Through the unified large language model interface module, all requests to call the large language model within the system are forwarded through this module. Internally, this module automatically adapts and calls the corresponding remote API (such as the OpenAI API), inference API (such as the HuggingFace Inference API), or locally deployed large model service HTTP interface based on user-configured endpoints, keys, and other information. This design shields the differences between different model backends, enabling the same prompt word strategy and evolutionary process to run seamlessly on different large language model services, improving system flexibility and adaptability to hardware resources. Sending a probe request to verify the interface during initialization can detect network connectivity issues, key errors, or local service failures early, avoiding wasted computing resources and time due to continuous model call failures after the evolutionary cycle begins. Furthermore, based on the above principles, this approach enables plug-and-play functionality for large language model backends, allowing researchers to freely choose the most suitable model service based on cost, performance, or data security requirements.
[0049] In some implementations, after updating the current population as mentioned above, the method further includes: serializing the updated population state and storing it in the results directory; and generating an experimental summary report based on the data in the results directory after the design results are output when the stopping condition is met.
[0050] This embodiment serializes (e.g., saves as a JSON file) the joint data structure of each individual in the entire population after each generation of evolution and stores it in the results directory, preserving a complete and traceable snapshot of the state for each experiment. Based on this archived data, the automatically generated summary report after the experiment can summarize key experimental data, such as the change curve of the optimal objective function value for each generation, the performance distribution of the final population, and detailed information on the best individual. Furthermore, combined with the above principles, this method can greatly enhance the reproducibility and analyzability of the experiment. Researchers can resume the experiment from the archive of any generation at any time to conduct ablation studies or continue evolution, and it also provides direct and rich material for paper writing and results analysis.
[0051] In some implementations, the step of initializing the current population mentioned above further includes: upon receiving a command to continue the experiment, reading the stored population state file from the results directory to restore the current population and continue the evolutionary cycle. This feature allows users to resume the experiment from previously interrupted generations when computational resources are limited or when it is desired to extend the search process. The system fully restores the evolutionary context at that time by loading the previous population state from the stored serialized file, and then continues to execute subsequent steps such as selection and generation from that point. Furthermore, based on the above principles, this approach provides continuity of experimentation, making it possible to automatically design long-term, multi-stage algorithms, and improving the feasibility and flexibility of large-scale experiments.
[0052] In some implementations, before starting the aforementioned heuristic automatic design method based on large language models and evolutionary computation, the method further includes receiving a unified parameter configuration object. This parameter configuration object includes an evolutionary method identifier, large language model endpoint information, population size, number of iterations, and number of parallel processes. Users set all key experimental parameters at once using a unified parameter configuration object (such as a Python dictionary or configuration class). The evolutionary method identifier determines which main loop logic to use; the large language model endpoint information guides the unified interface module to connect to the correct service; the population size and number of iterations control the breadth and depth of the search; and the number of parallel processes is used to allocate evaluation acceleration resources. Furthermore, combining the above principles, this centralized configuration management method simplifies and standardizes system startup and experimental configuration, reduces user complexity, and facilitates batch experiments such as parameter scanning.
[0053] In some implementations, the target optimization problem is a combinatorial optimization problem, including, but not limited to, at least one of the online bin packing problem, traveling salesman problem, scheduling problem, or hyperparameter search problem. This feature clarifies the typical problem domain to which this method is applicable, namely, NP-hard (NP-hard, i.e., nondeterministic polynomial-time hard problem) or NP-complete problems that have large-scale solution spaces and are difficult to solve in polynomial time using exact algorithms. Furthermore, based on the above principles, this method automatically designs solutions for these problems, effectively exploring the broad design space of heuristic algorithms and potentially discovering high-performance algorithms that surpass manual design rules. Experiments show that this method has achieved results surpassing existing automatic programming methods (such as FunSearch) on the online bin packing problem.
[0054] The above describes a heuristic automatic design method based on large language models and evolutionary computation in an embodiment of the present invention. The following describes a heuristic automatic design device based on large language models and evolutionary computation in an embodiment of the present invention. Please refer to [link to relevant documentation]. Figure 2One embodiment of the heuristic automatic design device based on large language models and evolutionary computation in this invention includes: Module 10 is used to acquire task description data and evaluation functions for the target optimization problem; Initialization module 20 is used to initialize the current population, wherein each candidate individual in the current population, as well as subsequent parent individuals and offspring individuals, are represented as a joint data structure, which contains algorithmic thinking description data in natural language format and executable code; Selection module 30 is used to select parent individuals from the current population; Assembly module 40 is used to assemble the algorithmic thinking description data and executable code of the parent individuals into prompts based on a preset set of prompt strategy. It then calls a large language model to generate a joint data structure for offspring. The prompt strategy set includes at least an exploration strategy for changing the algorithm's logical structure and a modification strategy for adjusting algorithm parameters. The exploration strategy includes a first exploration strategy and a second exploration strategy, and the modification strategy includes a first modification strategy and a second modification strategy. When the first exploration strategy is used, prompts are assembled to guide the large language model to generate a new algorithm whose logical structure is different from all selected parent individuals. When the second exploration strategy is used, prompts are assembled to request the extraction of the common core algorithmic ideas of the selected parent individuals and to generate a new algorithm variant based on these core ideas. When the first modification strategy is used, prompts are assembled to generate an improved version based on a single parent individual. When the second modification strategy is used, prompts are assembled to identify the adjustable parameters of the parent individuals and generate a new algorithm with reset parameter values. The parsing module 50 is used to parse the child algorithm thinking description data and child executable code from the child joint data structure to construct a complete child individual; The calculation module 60 is used to perform calculations on the instance data of the target optimization problem based on the acquired evaluation function, and obtain the target function value of the individual child. The update module 70 is used to update the current population based on the objective function value of each offspring individual, and determine whether the stopping condition is met. If not, it returns to the step of selecting parent individuals from the current population and subsequent steps; if yes, it outputs the design result containing the final population and / or the optimal individual.
[0055] Based on the same ideas as the methods in the above embodiments, the device provided by the present invention can implement the methods in the above embodiments. For ease of explanation, the structural schematic diagram of the device embodiment only shows the parts related to the embodiments of the present invention. Those skilled in the art can understand that the illustrated structure does not constitute a limitation on the device, and may include more or fewer modules than illustrated, or combine certain modules, or have different module arrangements.
[0056] Figure 2 The heuristic automatic design device based on large language models and evolutionary computation in the embodiments of the present invention will be described in detail from the perspective of modular functional entities. The heuristic automatic design device based on large language models and evolutionary computation in the embodiments of the present invention will be described in detail from the perspective of hardware processing.
[0057] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. The electronic device 100 can vary significantly due to differences in configuration or performance. It may include one or more central processing units (CPUs) 111 (e.g., one or more processors) and a memory 121, and one or more storage media 130 (e.g., one or more mass storage devices) for storing application programs 133 or data 132. The memory 121 and storage media 130 may be temporary or persistent storage. The program stored in the storage media 130 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the electronic device 100. Furthermore, the processor 111 may be configured to communicate with the storage media 130 and execute the series of instruction operations in the storage media 130 on the electronic device 100.
[0058] Electronic device 100 may also include one or more power supplies 141, one or more wired or wireless network interfaces 151, one or more input / output interfaces 161, and / or one or more operating systems 131, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 3 The device structure shown does not constitute a limitation on the electronic device 100, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0059] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform steps of a heuristic automatic design method based on a large language model and evolutionary computation.
[0060] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system, device, or unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0061] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0062] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A heuristic automatic design method based on large language models and evolutionary computation, characterized in that, Including the following steps: Obtain the task description data and evaluation function for the target optimization problem; Initialize the current population, where each candidate individual in the current population, as well as subsequent parent individuals and offspring individuals, are represented as a joint data structure, which contains algorithmic thinking description data in natural language format and executable code; Select parental individuals from the current population; Based on a preset set of prompting strategies, the algorithmic thinking description data and executable code of the parent individuals are assembled into prompting words. A large language model is then invoked to generate a joint data structure for offspring. The prompting strategy set includes at least an exploration strategy for changing the algorithm's logical structure and a modification strategy for adjusting algorithm parameters. The exploration strategy includes a first exploration strategy and a second exploration strategy, and the modification strategy includes a first modification strategy and a second modification strategy. When the first exploration strategy is used, prompting words are assembled to guide the large language model to generate a new algorithm whose logical structure is different from all selected parent individuals. When the second exploration strategy is used, prompting words are assembled to request the extraction of the common core algorithmic ideas of the selected parent individuals, and a new algorithm variant is generated based on these core ideas. When the first modification strategy is used, prompting words are assembled to generate an improved version based on a single parent individual. When the second modification strategy is used, prompting words are assembled to identify the adjustable parameters of the parent individuals and generate a new algorithm with reset parameter values. The algorithmic thinking description data and executable code of the offspring are parsed from the offspring joint data structure to construct a complete offspring individual; Based on the obtained evaluation function, the offspring executable code is run and calculated on the instance data of the target optimization problem to obtain the target function value of the offspring individual; Based on the objective function value of each offspring individual, the current population is updated, and it is determined whether the stopping condition is met. If not, the process returns to the step of selecting parent individuals from the current population and subsequent steps; if yes, the design result containing the final population and / or the optimal individual is output.
2. The heuristic automatic design method based on large language models and evolutionary computation as described in claim 1, characterized in that, The step of parsing the child algorithmic thinking description data and the child executable code from the child joint data structure specifically includes: Use regular expressions to extract text located between specific identifiers from the child generation union data structure as child generation algorithm thinking description data. Use regular expressions to extract code segments containing function definitions from the child federated data structure as child executable code.
3. The heuristic automatic design method based on large language models and evolutionary computation as described in claim 1, characterized in that, The step of running the child executable code on the instance data of the target optimization problem based on the acquired evaluation function specifically includes: Accelerate the execution of the child executable code through just-in-time compilation decoration; Multiple candidate child executable codes are evaluated in a multi-process parallel manner; A timeout threshold is set for the execution process. If the timeout occurs, the candidate's offspring executable code is deemed to have failed the evaluation and will not participate in the elite selection.
4. The heuristic automatic design method based on large language models and evolutionary computation as described in claim 1, characterized in that, The process of obtaining the task description data and evaluation function of the target optimization problem specifically includes: loading the problem package corresponding to the target optimization problem through a unified problem definition framework, and obtaining the task description data and evaluation function of the target optimization problem. The problem package at least includes a natural language description of the task, the signature of the function to be generated, and the evaluation function interface.
5. The heuristic automatic design method based on large language models and evolutionary computation according to claim 4, characterized in that, The objective optimization problem is a combinatorial optimization problem, including at least one of the following: online packing problem, traveling salesman problem, scheduling problem, or hyperparameter search problem.
6. The heuristic automatic design method based on large language models and evolutionary computation according to claim 1, characterized in that, After updating the current population, the method further includes: Serialize the updated population state and store it in the results directory; After the design results are output when the stopping conditions are met, an experimental summary report is generated based on the data in the results directory.
7. A heuristic automatic design device based on large language models and evolutionary computation, characterized in that, include: The acquisition module is used to acquire task description data and evaluation functions for the target optimization problem; An initialization module is used to initialize the current population, wherein each candidate individual in the current population, as well as subsequent parent individuals and offspring individuals, are represented as a joint data structure, which contains algorithmic thinking description data in natural language format and executable code; The selection module is used to select parent individuals from the current population; An assembly module is used to assemble the algorithmic thinking description data and executable code of the parent individuals into prompts based on a preset set of prompt strategy. It then calls a large language model to generate a joint data structure for offspring. The prompt strategy set includes at least an exploration strategy for changing the algorithm's logical structure and a modification strategy for adjusting algorithm parameters. The exploration strategy includes a first exploration strategy and a second exploration strategy, and the modification strategy includes a first modification strategy and a second modification strategy. When the first exploration strategy is used, the prompts are assembled to guide the large language model to generate a new algorithm whose logical structure is different from all selected parent individuals. When the second exploration strategy is used, the prompts are assembled to request the extraction of the common core algorithmic ideas of the selected parent individuals and to generate a new algorithm variant based on these core ideas. When the first modification strategy is used, the prompts are assembled to generate an improved version based on a single parent individual. When the second modification strategy is used, the prompts are assembled to identify the adjustable parameters of the parent individuals and generate a new algorithm with reset parameter values. The parsing module is used to parse the child algorithm thinking description data and child executable code from the child joint data structure in order to construct a complete child individual; The calculation module is used to perform calculations on the instance data of the target optimization problem based on the acquired evaluation function, and obtain the target function value of the individual child. The update module is used to update the current population based on the objective function value of each offspring individual, and determine whether the stopping condition is met. If not, it returns to the step of selecting parent individuals from the current population and subsequent steps; if yes, it outputs the design result containing the final population and / or the optimal individual.
8. An electronic device, characterized in that, It includes a memory and at least one processor, wherein the memory stores computer-readable instructions; The at least one processor invokes the computer-readable instructions in the memory to perform the steps of the heuristic automatic design method based on large language models and evolutionary computation as described in any one of claims 1-6.
9. A computer-readable storage medium storing computer-readable instructions thereon, characterized in that, When the computer-readable instructions are executed by the processor, they implement the steps of the heuristic automatic design method based on large language models and evolutionary computation as described in any one of claims 1-6.