This is the implementation for the experiments used for PAIR paper results section -We facilitated the design and implementation for this code to make all experiments easily repeatable and transparent
Utilizing LLMs in Evolutionary Algorithms as Evolutionary Optimizers and to imitate human-based selection (PAIR-Driven Selection)
Our main tests and experiments are on the Travelling Salesman Problem using TSPLIB95 and PyConcorde Libraries to generate problems and find their optimal solutions.
All problems are on a 2-D Euclidean plane.
- Create an environment variable to store your Gemini API's key, you can get a key from Google AI Studio
GEMINI_API_KEY=your_keyYou can also change it directly in the Gemini model's Class
def configure(self, systemPrompt: str, temperature: float):
code.....
# Initialize Gemini Client
genai.configure(api_key= "your_API_Key")
self.client = genai.GenerativeModel(
model_name=self.modelName,
generation_config=self.generationConfig,
system_instruction=systemPrompt
)-
You would need to have created TSP problem files and found their optimal solutions using PyConcorde.
We did not implement this part as the library didn't work locally, so we did that part on google colab instead and used the files directly. -
Move to your LLMsGA directory in the terminal:
cd LLMsGA- Run the main.py
Python .In the following steps, you would be provided with options to choose from
5. Enter the name of the problem you want to solve
Enter the name of the problem: *Problem_Name*
- Enter the problem's TSP file path
Enter the path to the problem file: */file_path/problem.tsp*- Enter the problem's optimal solution you found through PyConcorde
Enter the optimal solution for the problem: *Optimal_Solution*- Choose which solver to use (which methodology you want to solve with)
Select the solver to use:
1. TinderMatching
Enter the number of your choice: *Solver_Number*- Select the Large Language Model you want to use (only Gemini is implemented so far)
Select the model to use:
1. gemini-2.0-flash-thinking-exp-1219
2. gemini-2.0-flash-exp
Enter the number of your choice: *Model_Number*- Select which Population Initializer you want to use (only Random and Simulated Annealing Initializers are implemented so far)
Select the population initializer to use:
1. simulated-annealing
2. random
Enter the number of your choice: *Population_Initializer_Number*The Experiment should run now, you can find the run's results in /data folder. If any errors happened with the LLM during the run, the code will retry several times and if fails again will ask if you want to try again or terminate.
To generate graphs for the experiments data, run the Visualizations Manager:
- Move to your LLMsGA directory in the terminal:
cd LLMsGA- Run the Visualizations Manager:
python src/VisualizationsManager.pyTo visualize the behavior of Genetic Algorithms in solving TSP, follow these steps:
- Ensure you have the parsed JSON data from the experiments. You can generate this using the
parser.pyscript:
python TSP-Visualizer/parser.py- Open the
index.htmlfile using a web server to start the TSP Visualizer frontend.
