-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (60 loc) · 2.52 KB
/
main.py
File metadata and controls
79 lines (60 loc) · 2.52 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import pickle
from Data.Instance_Gen import *
from Source.cp_model import CPModel
from Source.lower_bound import CPModel_LB
from Source.cp_model_idea_tester import CPModel_Int
import Source.utils as ut
from os import walk, path
import pandas as pd
import random, math
from datetime import datetime
BASEDIR = path.dirname(path.realpath(__file__))
path2data = BASEDIR + "/Data/Instances"
_, _, filenames = next(walk(path2data), (None, None, []))
def data_update(Data):
for t in range(Data.n_periods):
if t >= Data.n_periods - math.ceil(Data.n_periods * 0.15):
data.I_in_min[t] = 0
return Data
def write_to_excel(Res):
out = pd.DataFrame(Res, columns=["Instance", "Model", "LB", "UB", "Solve time", "Why", "Solver"])
out.to_excel(BASEDIR + "/Data/Results/" + "output.xlsx")
def write_to_log(Res, prefex=""):
now_today = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
myfile = open(BASEDIR + f"/Data/Results/Log{prefex}.txt", "a+")
myfile.write(f"{now_today}\t")
myfile.write("\t".join([str(a) for a in Res if not isinstance(a, list)]) + "\r\n")
myfile.close()
def print_problem_info(data):
n_face= len(data.face)
n_pat = len(data.pattern)
n_O_pat = len([1 for pat in data.pattern.values() if pat.parent == -1])
n_drill = len(data.drill)
n_shovel = len(data.shovel)
print(f"{data.name} {n_face} {n_pat},{n_O_pat} {n_shovel} {n_drill}")
if __name__ == "__main__":
results = []
Gaps = {}
for instance in ["S_F60_P36_D13_S9_1.data"]: #, "S_F44_P24_D9_S6_3.data", "S_F44_P24_D9_S6_4.data"]: # [ "PL_011_3.data", "PL_010_2.data"]:
with open(path2data + "/" + instance, 'rb') as file:
data = pickle.load(file)
if not ("S_" in instance):
continue
data = data_update(data)
instance = instance.split(".")[0]
print_problem_info(data)
print(f"We are solving {instance}")
LB, UB, time, st1, st2 = CPModel(data, display=0, timelimit=200)
results.append([data.name, "Original", LB, UB, time, st1, st2])
write_to_log(results[-1])
LB, UB, time, st1, st2 = CPModel_Int(data, display=0, timelimit=200)
#LB, UB, time, st1, st2 = CPModel_LB(data, display=1, timelimit=100)
results.append([data.name, "Integer", LB, UB, time, st1, st2])
write_to_log(results[-1])
if UB:
Gaps[data.name] = (UB - LB) / UB * 100
for na in Gaps:
print(f"{na} : {Gaps[na]}")
print(results)
rite_to_excel(results)
#ut.Say_run_compeleted()