-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.py
97 lines (77 loc) · 2.65 KB
/
Input.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
from Memory import Memories
from Task import RTTask
import sys
from Processor import Processor
class GAConfig:
def __init__(self):
self.MAX_GEN = None
self.POPULATIONS = None
self.TRY_LIMIT = None
self.UTIL_LIMIT_RATIO = None
self.PENALTY_RATIO = None
self.MUTATION_PROB = None
self.K = None
self.MAX = self.MIN = None
def get_configuration(input_file="input_configuration.txt"):
try:
processor = None
memories = None
with open(input_file, "r", encoding='UTF-8') as f:
while True:
line = f.readline()
if not line:
break # EOF
line = line.split()
if len(line) == 0:
continue
if line[0] == '##':
if line[1] == 'Memory':
memories = get_memory(f)
elif line[1] == 'Processor':
processor = get_processor(f)
elif line[1] == 'GA':
ga_config = get_ga_config(f)
else:
raise Exception
return processor, memories, ga_config
except FileNotFoundError:
print("Cannot find {}".format(input_file))
sys.exit(0)
def get_processor(f):
processor = Processor(int(f.readline()))
while True:
line = f.readline().split()
if len(line) == 0:
break
processor.insert_processor_mode(*map(float, line))
return processor
def get_memory(f):
memories = Memories()
while True:
line = f.readline().split()
if len(line) == 0:
break
memories.insert_memory(int(line[1]), *map(float, line[2:]))
return memories
def get_ga_config(f):
ga_config = GAConfig()
ga_config.MAX_GEN = int(f.readline())
ga_config.POPULATIONS = int(f.readline())
ga_config.TRY_LIMIT = int(f.readline())
ga_config.UTIL_LIMIT_RATIO = float(f.readline())
ga_config.PENALTY_RATIO = int(f.readline())
ga_config.MUTATION_PROB = float(f.readline())
ga_config.K = int(f.readline())
ga_config.MAX, ga_config.MIN = tuple(map(int, f.readline().split()))
return ga_config
def get_rt_tasks(input_file="input_task.txt"):
try:
rt_tasks = []
with open(input_file, "r", encoding='UTF-8') as f:
for i in range(int(f.readline())):
line = f.readline().split()
rt_tasks.append(RTTask(*map(int, line[:3]), float(line[3])))
return rt_tasks
except FileNotFoundError:
print("Cannot find {}".format(input_file))
sys.exit(0)