Nested-Refinement Metamorphosis: Reflective Evolution for Efficient Optimization of Networking Problems (2025)

Abstract: Large Language Models (LLMs) excel in network algorithm design but suffer from inefficient iterative coding and high computational costs. Drawing inspiration from butterfly metamorphosis—where structured developmental phases (Phase I: larval nutrient accumulation → Phase II: pupal transformation) enable adaptive evolution—we propose Nested-Refinement Metamorphosis (NeRM). Building on this principle, we introduce Metamorphosis on Prompts (MoP) to iteratively refine task descriptions (e.g. latency / bandwidth constraints) and Metamorphosis on Algorithms (MoA) to generate more effective solutions (e.g. appropriate network processing architecture). Their nested refinement ensures task-algorithm alignment, systematically improving both task descriptions and algorithmic solutions for more efficient algorithm design. To further enhance efficiency, we incorporate predictor-assisted code evaluation, mimicking natural selection by filtering out weak candidates early and reducing computational costs. Experimental results on TSP (routing), MKP (resource allocation), and CVRP (service-network coordination) demonstrate that NeRM consistently outperforms state-of-the-art approaches in both performance and efficiency.

## introduction large language models (llms) @xcite @xcite for algorithm design have gained significant attention across various domains. these models have proven effective in tasks such as automated code generation @xcite @xcite , program synthesis @xcite @xcite , and algorithm optimization @xcite @xcite . these applications demonstrate the ability of llms to automate and optimize traditional processes, improving development workflows and enabling innovative solutions across fields. currently, llm-based automatic algorithm design @xcite @xcite primarily focuses on code evolution, where models iteratively generate and refine code through search-based strategies. these approaches require generating a large pool of candidate solutions and individually evaluating each one to identify high-quality algorithms. however, without a mechanism to refine task descriptions, evolved code often lacks alignment with problem requirements, leading to inefficient search that produces redundant or suboptimal solutions @xcite . moreover, the necessity of evaluating every candidate imposes significant computational costs, making the process impractical for large-scale problems. these challenges highlight the need for a more structured framework that integrates both prompt refinement and algorithm evolution, enabling more targeted exploration while reducing evaluation overhead. inspired by biological metamorphosis foot_0 , we take the butterfly lifecycle as an analogy (figure 1a ), which unfolds of three key phases: phase i: meta-morphosis from larva to pupa, where the larva undergoes growth and nutrient accumulation in preparation for transformation into a pupa; phase ii: metamorphosis from pupa to butterfly, a structural transition where the butterfly adapts to its environment and emerges as a fully developed adult; and phase iii, where the butterfly's adaptation shapes the evolutionary trajectory of the next generation of larvae. we identify the challenges of algorithm design as nested-refinement metamorphosis (figure 1b ), which mirrors the butterfly's transformation by iteratively refining both prompts and algorithms to enhance their effectiveness and efficiency. specifically, we propose a novel framework named nested-refinement metamorphosis: reflection and evolution of prompts and code for efficient algorithm design (nerm), a novel framework that enables the generation of effective algorithms with high efficiency. nerm introduces a nested metamorphosis process that combines metamorphosis on prompts (mop) and metamorphosis on algorithms (moa). mop iteratively refines task descriptions to improve guidance for solution generation, while moa leverages these refined prompts to evolve algorithms through reflectiondriven adaptation @xcite and evolutionary optimization @xcite , ensuring better task alignment. the interaction between mop and moa forms a self-improving feedback loop, continuously enhancing algorithm performance. to further improve efficiency, nerm incorporates a predictor-assisted evaluation mechanism, which mimics natural selection by filtering out weak candidates early. this prioritization of promising solutions reduces computational overhead while maintaining solution quality. our contributions can be summarized as follows: ## methodology this work introduces nerm, comprising two components: nested refinement metamorphosis and predictor-assisted code evaluation. nested refinement metamorphosis integrates metamorphosis on prompts (mop), which simulates phase i of : evolution llm : reflector llm : reflection metamorphosis on prompts (mop) reflection historical knowledge initial population evolution crossover mutation metamorphosis on algorithms (moa) initial population reflection historical knowledge evolution crossover mutation update predictor : prompts & codes : historical prompts & codes : crossover prompts & codes worse better metamorphosis on prompts (mop) metamorphosis on algorithms (moa) … update performance indicator predictor predictor predictor-assisted code evaluation llm code/data embedding classifier label ℒ figure 2: overview of nerm, which integrates nested-refinement metamorphosis and predictor-assisted code evaluation. the nested-refinement metamorphosis consists of the nests between metamorphosis on prompts (mop) and metamorphosis on code (moa) to generate algorithms effectively. additionally, nerm incorporates predictorassisted code evaluation to efficiently filter high-quality solutions, reducing computational overhead. biological metamorphosis by refining task descriptions, and metamorphosis on algorithms (moa), which mimics phase ii by optimizing algorithms. their nested interaction simulates phase iii, driving continuous co-evolution for more effective solutions. predictor-assisted code evaluation filters out low-quality algorithms early, reducing computational costs while maintaining solution quality. an overview of nerm is shown in figure 2. 3.1 nested-refinement metamorphosis nested-refinement metamorphosis overcomes the limitations of existing methods that iteratively generate code without refining task descriptions to better guide the search process, leading to inefficient exploration and high computational costs. inspired by biological evolution, which mimics the phases of biological development, we propose (i) metamorphosis on prompts (mop), which corresponds to the growth and accumulation phase, where the task description is iteratively refined to guide exploration more effectively; and (ii) metamorphosis on algorithms (moa), which mirrors the transformation phase, where the generated code undergoes iterative refinement, continuously adapting to task requirements and enhancing its quality. mop and moa. both mop and moa begin with a diverse initial population, where mop combines manually crafted prompts to integrate human ex-pertise with llm-generated prompts for diversity, while moa generates an initial heuristic population guided by mop prompts and an llm-based generator. in the reflection phase, a reflector llm extracts insights from past refinements, synthesizing key takeaways, and suggesting improvements to ensure continuous evolution based on previous performance. during the evolution phase, mop and moa apply crossover and mutation to generate new candidates: mop combines and modifies prompts, while moa generates new heuristics through llmdriven refinements. finally, in the update phase, both processes evaluate the candidates generated in a development set, using a code predictor to retain high-quality prompts and algorithms while filtering out weaker ones. the details of the mop and moa design are described in ## conclusion in this work, we introduced nested-refinement metamorphosis (nerm), a framework that iteratively refines prompts and evolves heuristic algorithms through reflection and optimization. inspired by biological metamorphosis, nerm integrates metamorphosis on prompts (mop) to refine task descriptions and metamorphosis on algorithms (moa) to enhance solutions. the nested refinement between mop and moa balances exploration and optimization, enabling adaptive algorithm design. to improve efficiency, we added a predictor-assisted evaluation mechanism, filtering out low-quality heuristics early and reducing computational overhead. experiments on tsp, mkp, and cvrp show that nerm outperforms state-ofthe-art prompt-based and evolution-based methods in both quality and efficiency. in future work, we plan to expand nerm to broader domains, enhance predictor models for better assessment, and improve scalability for large-scale algorithm design.