forked from mcychan/GASchedule.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleApp.py
50 lines (40 loc) · 1.36 KB
/
ConsoleApp.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
49
50
import codecs
import pathlib
import os
import sys
import tempfile
import time
import traceback
from model.Configuration import Configuration
# from algorithm.GeneticAlgorithm import GeneticAlgorithm
# from algorithm.APNsgaIII import APNsgaIII
from algorithm.Cso import Cso
# from algorithm.Ngra import Ngra
# from algorithm.Amga2 import Amga2
from HtmlOutput import HtmlOutput
def main(file_name):
start_time = int(round(time.time() * 1000))
configuration = Configuration()
target_file = str(pathlib.Path().absolute()) + file_name
configuration.parseFile(target_file)
alg = Cso(configuration)
# alg = Hgasso(configuration)
print("GaSchedule Version 1.2.4 . Making a Class Schedule Using", alg, ".\n")
print("Copyright (C) 2022 - 2023 Miller Cy Chan.\n")
alg.run()
html_result = HtmlOutput.getResult(alg.result)
temp_file_path = tempfile.gettempdir() + file_name.replace(".json", ".htm")
writer = codecs.open(temp_file_path, "w", "utf-8")
writer.write(html_result)
writer.close()
seconds = (int(round(time.time() * 1000)) - start_time) / 1000.0
print("\nCompleted in {} secs.\n".format(seconds))
os.startfile(temp_file_path)
if __name__ == "__main__":
file_name = "/GaSchedule.json"
if len(sys.argv) > 1:
file_name = sys.argv[1]
try:
main(file_name)
except:
traceback.print_exc()