Skip to content

Commit

Permalink
add main code
Browse files Browse the repository at this point in the history
Took 28 minutes
  • Loading branch information
Nikronic committed Oct 12, 2019
1 parent 6ea9e4d commit 20d9916
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ga.py
Original file line number Diff line number Diff line change
@@ -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


2 changes: 2 additions & 0 deletions utils/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ def __getitem__(self, index: int) -> Chromosome:
:return: A `Chromosome` class from `Population`.
"""
return self.chromosomes[index]

# TODO add describe method

0 comments on commit 20d9916

Please sign in to comment.