File size: 938 Bytes
fe446ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import neat
import pickle
from .fyp1_simulation.newcar import run_simulation

# Paths
config_path = os.path.join(os.path.dirname(__file__), 'fyp1_simulation', 'config.txt')
genome_path = os.path.join(os.path.dirname(__file__), 'fyp1_simulation', 'best_neat_genome.pkl')

# Load NEAT config
config = neat.config.Config(
    neat.DefaultGenome,
    neat.DefaultReproduction,
    neat.DefaultSpeciesSet,
    neat.DefaultStagnation,
    config_path
)

# Load the best genome
if not os.path.exists(genome_path):
    raise FileNotFoundError(f"Best genome file not found at {genome_path}")

with open(genome_path, "rb") as f:
    best_genome = pickle.load(f)

# print("\n✅ Best genome loaded successfully!")
# print(f"Fitness: {best_genome.fitness}")

# Wrap the genome in the expected format: list of tuples (genome_id, genome)
test_genomes = [(0, best_genome)]

# Run the simulation for testing
run_simulation(test_genomes, config)