From 20d991638afb38a428630934c101b0e1966ac400 Mon Sep 17 00:00:00 2001 From: "M. Doosti Lakhani" Date: Sun, 13 Oct 2019 00:09:52 +0330 Subject: [PATCH] add main code Took 28 minutes --- ga.py | 25 +++++++++++++++++++++++++ utils/population.py | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 ga.py diff --git a/ga.py b/ga.py new file mode 100644 index 0000000..f2c8585 --- /dev/null +++ b/ga.py @@ -0,0 +1,25 @@ +from utils.chromosome import Chromosome +from utils.depot import Depot +from utils.customer import Customer +import utils.io as IO +import utils.functional as F + +# Hyper-parameters +POPULATION_SIZE = 10 +ITERATION = 100 + +# Initialization +depots, customers = IO.single_data_loader('data/input/p01', 'data/result/p01.res') +sample = F.generate_chromosome_sample(depots, customers) +population = F.generate_initial_population(sample, POPULATION_SIZE) +for ch in population: + ch.fitness_value([1, 1]) + +# Iteration +for i in range(ITERATION): + new_population = F.generate_new_population(population) + for ch in new_population: + ch.fitness_value() + # describe population + + diff --git a/utils/population.py b/utils/population.py index fd4defb..0409cf2 100644 --- a/utils/population.py +++ b/utils/population.py @@ -111,3 +111,5 @@ def __getitem__(self, index: int) -> Chromosome: :return: A `Chromosome` class from `Population`. """ return self.chromosomes[index] + + # TODO add describe method