-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
132 lines (110 loc) · 4.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
__author__ = 'max'
import MachineBoss
import JobManager
import GreedyScheduler
import SortedGreedyScheduler
import RandomScheduler
import RandomSearch
import RandomSearchStatistics
import HillClimbingScheduling
import LeaveRoomSortedGreedy
import time
def main():
files = ["normal-3-1.txt","normal-6-2.txt","normal-100-30.txt","biNormal-100-300--30.txt", "biNormal-100-300--10.txt","pareto-1.txt","pareto-2.txt","pareto-3.txt","pareto-4.txt","pareto-1p1.txt"]
#files = ["pareto-1.txt","pareto-2.txt","pareto-3.txt","pareto-4.txt", "biNormal-100-300--30.txt", "biNormal-100-300--10.txt"]
#files = ["biNormal-100-300--30.txt", "biNormal-100-300--10.txt"]
machines = 5
kLookAhead = 5
mStep = [5,10,15,20,25,30]
kStep = [5,10,15,20,25,30]
writeIO = open('pareto-1p1-KStep.csv','w')
writeIO.write("M,K,Sorted Greedy,Random Search, Random Search with History \n")
for variable in kStep:
#simpleTest(writeIO,files[9],variable,kStep[1]) #m variates
simpleTest(writeIO,files[9],mStep[1],variable) #k variates
#randomRetries(files[3],machines,kLookAhead)
def randomRetries(inputFile,m,k):
bestM = 1
bestS = 100000000000
bestR = 1
for i in range(5):
for m in range(m,m+1):
startTime = time.time()
jobs = JobManager.JobManager(k,inputFile,m)
machines = MachineBoss.MachineBoss(m)
RandomSearch.RandomSearch(machines,jobs)
makeSpan = machines.maxMachine().makeSpan
OPT = max(jobs.MAXJOB, jobs.sumJobTime/float(m))
bestS,bestM = "",""
if makeSpan < bestS:
bestS = makeSpan
bestM = m
bestR = OPT
exTime = time.time() - startTime
#print "Max Machine Run time: "+ str(makeSpan) + " OPT for " + str(m) + " machines is " + str(ratio)
#print "ratio: " + str(makeSpan/ratio)
print "Random Search: \t\t " + str(bestS)+ "|| Ratio: " + str(bestS/OPT)+ " run time: " + str(exTime)
def simpleTest(writeFile,inputFile,m,k):
line = ""
bestM = 1
bestS = 100000000000
bestR = 0
for m in range(m,m+1):
startTime = time.time()
jobs = JobManager.JobManager(k,inputFile,m)
machines = MachineBoss.MachineBoss(m)
SortedGreedyScheduler.SortedGreedyScheduler(machines,jobs)
makeSpan = machines.maxMachine().makeSpan
OPT = max(jobs.MAXJOB, jobs.sumJobTime/float(m))
bestS,bestM = "",""
if makeSpan < bestS:
bestS = makeSpan
bestM = m
bestR = OPT
exTime = time.time() - startTime
line = line + str(m)+","+str(k)+","+str(bestS/OPT) + ","
print "SG"
bestM = 1
bestS = 100000000000
bestR = 1
for i in range(5):
for m in range(m,m+1):
startTime = time.time()
jobs = JobManager.JobManager(k,inputFile,m)
machines = MachineBoss.MachineBoss(m)
RandomSearch.RandomSearch(machines,jobs)
makeSpan = machines.maxMachine().makeSpan
OPT = max(jobs.MAXJOB, jobs.sumJobTime/float(m))
bestS,bestM = "",""
if makeSpan < bestS:
bestS = makeSpan
bestM = m
bestR = OPT
exTime = time.time() - startTime
#print "Max Machine Run time: "+ str(makeSpan) + " OPT for " + str(m) + " machines is " + str(ratio)
#print "ratio: " + str(makeSpan/ratio)
line = line + str(bestS/OPT) +","
print "RS"
bestM = 1
bestS = 100000000000
bestR = 1
for i in range(5):
for m in range(m,m+1):
startTime = time.time()
jobs = JobManager.JobManager(k,inputFile,m)
machines = MachineBoss.MachineBoss(m)
RandomSearchStatistics.RandomSearchStatistics(machines,jobs)
makeSpan = machines.maxMachine().makeSpan
OPT = max(jobs.MAXJOB, jobs.sumJobTime/float(m))
bestS,bestM = "",""
if makeSpan < bestS:
bestS = makeSpan
bestM = m
bestR = OPT
exTime = time.time() - startTime
#print "Max Machine Run time: "+ str(makeSpan) + " OPT for " + str(m) + " machines is " + str(ratio)
#print "ratio: " + str(makeSpan/ratio)
line = line+ str(bestS/OPT) + "\n"
writeFile.write(line)
print "RSH"
main()