-
Notifications
You must be signed in to change notification settings - Fork 0
/
tester.py
57 lines (43 loc) · 1.67 KB
/
tester.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
#! /user/bin/python
import os, os.path
from solver import solve
from classes.Testdata import Testdata
def test(data):
folder = data['options']['testset']
if not os.path.isdir(folder):
folder = '../datasets/delays/{0}/'.format(data['options']['testset'])
testdata = Testdata(data['pos'])
for delayset in os.listdir(folder):
testdata.addTest(folder + '/' + delayset)
return testdata
def testFromFile(data, inputfile):
f = open(inputfile, 'r')
delays = map(float, list(f))
f.close()
delayedProblem = data['pos'].clone()
for (index, act) in enumerate(delayedProblem.activities):
act.time *= delays[index]
toSolve = {'options':{'solver':"noResources"},'instance':delayedProblem}
delayedSolution = solve(toSolve)
(numDelays, totalDelay) = getTaskDelays(data['solution'], delayedSolution)
horizon = float(data['instance'].getHorizon())
delayedMakespan = delayedSolution.getMakespan()
originalMakespan = data['solution'].getMakespan()
result = {}
result['numDelays'] = numDelays
result['totalDelay'] = totalDelay
result['delayedPortion'] = float(numDelays) / float(len(data['instance'].activities))
result['normTaskDelay'] = float(totalDelay) / horizon
result['mksInc'] = delayedMakespan - originalMakespan
result['relMksInc'] = float(delayedMakespan - originalMakespan) / float(originalMakespan)
result['normMksInc'] = float(delayedMakespan - originalMakespan) / horizon
return result
def getTaskDelays(originalSolution, delayedSolution):
numDelays = 0
totalDelay = 0
for (i, orig) in enumerate(originalSolution.startTimes):
delayed = delayedSolution.startTimes[i]
if delayed > orig:
numDelays += 1
totalDelay += delayed - orig
return (numDelays, totalDelay)