-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
47 lines (33 loc) · 1.13 KB
/
Copy pathMain.py
File metadata and controls
47 lines (33 loc) · 1.13 KB
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
from code.Constructive import *
from code.Extract import *
from code.Genetic import *
from code.Instance import *
from code.Solution import *
from optparse import OptionParser
import os
import time
if __name__ == "__main__":
start = time.time()
parser = OptionParser()
parser.add_option("-r", "--file", dest="file", type = "string")
(opts, _) = parser.parse_args()
path = opts.file
if path is None:
# path = '../instance/001_struc_2_10_01'
# path = '../instance/002_struc_2_10_02'
path = '../instance/006_struc_2_100_01'
inst = Instance(Extract(os.path.join(path)))
pop_size = 10
init_pop: List[Solution] = np.ndarray(pop_size, dtype=Solution)
const_sol = Constructive(inst)
for i in range(pop_size):
sol = Solution(inst)
const_sol.build_naive(sol)
init_pop[i] = sol
sol = Solution(inst)
const_sol.build_greedy(sol)
init_pop[0] = sol
ga = Genetic(init_pop, inst)
ga.next_generation(5)
print(f"Genético: {ga.inc_sol.cmax} in {(time.time() - start):.2f}seg")
print("CMax Guloso: ", sol.cmax)