-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.py
executable file
·48 lines (35 loc) · 1.36 KB
/
main.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# This script contains a high level overview of the proposed hybrid algorithm
# The code is strictly mirroring the section 4.1 of the attached paper
import sys
import time
from src.utils import parser, gantt
from src.genetic import encoding, decoding, genetic, termination
from src import config
# Beginning
if len(sys.argv) != 2:
print("Usage: " + sys.argv[0] + " filename")
else:
# Parameters Setting
parameters = parser.parse(sys.argv[1])
t0 = time.time()
# Initialize the Population
population = encoding.initializePopulation(parameters)
gen = 1
# Evaluate the population
while not termination.shouldTerminate(population, gen):
# Genetic Operators
population = genetic.selection(population, parameters)
population = genetic.crossover(population, parameters)
population = genetic.mutation (population, parameters)
gen = gen + 1
sortedPop = sorted(population, key=lambda cpl: genetic.timeTaken(cpl, parameters))
t1 = time.time()
total_time = t1 - t0
print("Finished in {0:.2f}s".format(total_time))
# Termination Criteria Satisfied ?
gantt_data = decoding.translate_decoded_to_gantt(decoding.decode(parameters, sortedPop[0][0], sortedPop[0][1]))
if config.latex_export:
gantt.export_latex(gantt_data)
else:
gantt.draw_chart(gantt_data)