-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainGenerators.py
67 lines (56 loc) · 2.22 KB
/
mainGenerators.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
import os
import sys
from data_generators.generator import *
from paramsMainGenerators import *
def usage():
print("Usage:")
print('python3 mainGenerators.py "generator" "numInstances"')
print("The generator can be:")
print("0 -> Random")
print("1 -> Feasible 1")
print("2 -> Feasible 2")
if __name__ == '__main__':
if len(sys.argv) < 3:
print("Not enough parameters")
usage()
exit(1)
if len(sys.argv) > 3:
print("Too much parameters")
usage()
exit(1)
generator = sys.argv[1]
if generator not in ['0', '1', '2']:
print("Invalid parameter for generator", generator)
exit(1)
numInstances = sys.argv[2]
try:
numInstances = int(numInstances)
except ValueError:
print("Invalid value for numInstances", numInstances)
exit(1)
folder = "data_generators/autoGeneratedData/"
if not os.path.exists(folder):
os.makedirs(folder)
for i in range(numInstances):
# using random generator
if generator == '0':
name = "random_" + str(i+1) + ".dat"
params = generateRandom(distrDemand, distrMinHours, distrMaxHours,
distrMaxConsec, distrMaxPresence, hoursDay)
writeParams(params, "RANDOM", folder + name, -1)
# using generateFeasible1
elif generator == '1':
name = "feasible1_" + str(i+1) + ".dat"
(params, nurses) = generateFeasible1(distrDemand, distrMaxHours, distrMaxConsec, distrMaxPresence, hoursDay)
# stops the program if a generated instance is not OK
assert isFeasibleGeneratorOk(nurses, params)
cost = sum(sum(nurse) > 0 for nurse in nurses)
writeParams(params, "FEASIBLE", folder + name, cost)
# using generateFeasible2
elif generator == '2':
name = "feasible2_" + str(i+1) + ".dat"
(params, nurses) = generateFeasible2(distrNNurses, hoursDay)
# stops the program if a generated instance is not OK
assert isFeasibleGeneratorOk(nurses, params)
cost = sum(sum(nurse) > 0 for nurse in nurses)
writeParams(params, "FEASIBLE", folder + name, cost)