π§ Hindsight Insight Pool Β· π Foresight Evolutionary Navigator Β· π Closed-Loop Evolution
Welcome! This repository provides the code implementation for the paper HiFo-Prompt: Prompting with Hindsight and Foresight for LLM-based Automatic Heuristic Design.
- Jan. 2026: ππ HiFo-Prompt: Prompting with Hindsight and Foresight for LLM-based Automatic Heuristic Design has been accepted at ICLR 2026 as a Poster!
HiFo-Prompt (Hindsight-Foresight Prompt) is a novel framework for Automatic Heuristic Design (AHD) that synergizes Large Language Models (LLMs) with Evolutionary Computation (EC).
Existing LLM-based methods often suffer from short-term memory (forgetting successful tricks) and lack of direction (randomly searching without a strategy). HiFo-Prompt solves this by introducing two key mechanisms:
-
π§ Hindsight (The Insight Pool): A self-evolving knowledge base that distills and stores "design principles" from high-performing heuristics, preventing the system from reinventing the wheel.
-
π Foresight (The Evolutionary Navigator): A meta-controller that monitors population dynamics (stagnation, diversity) and actively switches search regimes (Explore, Exploit, or Balance) via specific Design Directives.
| Component | Function | Why it matters |
|---|---|---|
| Insight Pool | Extracts & Reuses Knowledge | Instead of discarding parents, we extract why they worked. The prompts are augmented with proven "Insights". |
| Evolutionary Navigator | Adaptive Control | Detects if the search is stuck (stagnation) or too narrow (low diversity) and dynamically adjusts the prompt strategy. |
| Decoupled Evaluation | Efficient Pipeline | Decouples "Thought" from "Code", allowing for faster iteration and lower token consumption compared to standard methods. |
We recommend using Conda to manage the environment.
# 1. Create environment
conda create -n hifo python=3.10
conda activate hifo
# 2. Clone repository
git clone https://github.com/Challenger-XJTU/HiFo-Prompt.git
cd HiFo
# 3. Install dependencies
cd hifo
pip install .Note: You must have an LLM API key (e.g., OpenAI, DeepSeek, Qwen) or a local LLM server running.
from hifo import hifo
from hifo.utils.getParas import Paras
# 1. Initialize Parameters
paras = Paras()
# 2. Configure HiFo
paras.set_paras(
method = "hifo",
problem = "tsp_construct", # Problem: 'tsp_construct', 'bp_online'
llm_api_endpoint = "api.deepseek.com", # Your API Endpoint
llm_api_key = "sk-xxxxxxxx", # Your API Key
llm_model = "deepseek-chat", # Model Name
ec_pop_size = 8, # Population size
ec_n_pop = 8, # Number of generations
exp_n_proc = 4, # Parallel threads for evaluation
exp_debug_mode = False # Set True to see prompt construction details
)
# 3. Initialize & Run
evolution = hifo.EVOL(paras)
evolution.run()We provide ready-to-run scripts for standard combinatorial optimization problems.
Constructive heuristic design for TSP.
cd examples/tsp_construct
python runHiFo.pyDesigning scoring functions for online packing.
cd examples/bp_online
python runHiFo.pycd examples/user_XXX
python runHiFo.pyHiFo-Prompt supports both remote APIs and local LLM deployment.
Supported protocols: OpenAI-compatible APIs (DeepSeek, Moonshot, ChatGPT, etc.).
Modify runHiFo.py:
llm_api_endpoint = "api.openai.com"
llm_api_key = "your_key"
llm_model = "gpt-4o"- Start your local server (e.g., using vLLM):
python -m vllm.entrypoints.openai.api_server --model Qwen/Qwen2.5-7B-Instruct --port 8000- Configure HiFo:
llm_use_local = True
llm_local_url = "http://localhost:8000/v1/chat/completions"HiFo-Prompt/
βββ hifo/
β βββ src/hifo/
β β βββ methods/
β β β βββ hifo/
β β β βββ hifo.py # Main HiFo Algorithm
β β β βββ hifo_evolution.py # Evolution Operators (i1, e1, m1, etc.)
β β β βββ insight_pool.py # π§ Hindsight Module
β β β βββ evolutionary_navigator.py # π Foresight Module (Regime Control)
β β βββ llm/ # LLM Interfaces
β β βββ problems/ # Problem Definitions
β β βββ utils/ # Parameter parsing & helpers
β βββ setup.py
βββ examples/ # Problem-specific runners (TSP, BPP, etc.)
βββ docs/ # Documentation & Tutorials
| Parameter | Description | Default |
|---|---|---|
method |
Algorithm method (hifo, ael) |
hifo |
problem |
Problem type | tsp_construct |
ec_pop_size |
Population size per generation | 8 |
ec_n_pop |
Number of generations | 8 |
exp_n_proc |
Number of parallel processes | 4 |
eva_timeout |
Evaluation timeout (seconds) | 300 |
exp_debug_mode |
Enable debug output | False |
We are actively maintaining HiFo-Prompt and thrilled to hear from the community!
- Need Help? If you run into any bugs or have feature requests, please check the Issues page or submit a new one.
- Collaboration: We are open to discussions on AHD and LLMs. Feel free to reach out via email or pull requests. Let's push the boundaries of automated algorithm design together! π€
Support Us: If HiFo-Prompt aids your research or if you like our approach, please Star β or Fork π΄ this repository. Your support drives our updates!
@inproceedings{chen2026hifo,
title = {HiFo-Prompt: Prompting with Hindsight and Foresight for LLM-based Automatic Heuristic Design},
author = {Chen, Chentong and Zhong, Mengyuan and Fan, Ye and Shi, Jialong and Sun, Jianyong},
booktitle = {International Conference on Learning Representations},
year = {2026},
url = {https://openreview.net/forum?id=imSLzfZ6av}
}
Our work builds upon EoH and ReEvo, and we thank the authors for their inspiring work. We also acknowledge LLM4AD and FM4CO for their valuable learning resources on LLM-based AHD.

