Alright, this python code is purposed to solve SMTWTP (Single Machine Total Weighted Tardiness Problem) using Genetic Algorithm.
You can take a look the GA implemented inside a file: genetic_algorithm.py
On this project, this is how the GA mechanism works:
- Generate Random Solutions
- Firstly, this program will take a SMTWTP problem as an input from an excel file:
data/case_1.xls
(usual SMTWTP problem table) - and will generate random solutions of the given problem
- the first solutions generated are 6 in total (why 6? because following the total of the projects)
- Calculate Fitness Function
- calculating the fitness function (total weighted tardiness) as per SMTWTP formula
- Selection Process
- the selection process will take two chromosomes as parents randomly and prepared for crossover
- after selecting the parents, the crossover is executed. After the crossover, this program will sort the 2 best candidate (chromosome) and will be the next gen candidate, this method is called as "Elitism"
- Crossover Process
- in this process the parent's gene will be swapped to each other
- the genes that swapped are the last two genes of the parents. Can see the example on the table below
Example Chromsome Chromosome A: A F D C (B E) Chromosome B: C A B F (E D) New Chromosome 1: A F D C E D New Chromosome 2: C A B F B E
- Mutation Process
- mutation process will take a look if there's a same gene in a chromosome
- if there's a same gene, one of it will be replaced to a new unique gene which hasn't in the chromosome
Example Chromsome New Chromosome 1: A F D C E D New Chromosome 1 (mutated): A F D C E B New Chromosome 2: C A B F B E New Chromosome 2 (mutated): C A B F D E
main.py
data/case_1.xls
genetic_algorithm.py
helper.py
- Just ignore the others
python main.py