-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataParser.py
More file actions
59 lines (53 loc) · 2.05 KB
/
DataParser.py
File metadata and controls
59 lines (53 loc) · 2.05 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
###
# Parser data structure info:
# CAPACITY = maximum resource capacity
# N_TASKS = number of tasks
# d = list of durations of each task
# rr = list of resource requirements of each task
# suc = list of successors of each task ( list of lists )
###
class TaskDataParser:
def __init__(self, filename):
self.filename = filename
self.CAPACITY = 0
self.N_TASKS = 0
self.d = []
self.rr = []
self.suc = []
def read_data_from_file(self):
with open(self.filename, "r") as file:
lines = file.readlines()
for line in lines:
parts = line.split()
if parts[0] == "CAPACITY":
self.CAPACITY = int(parts[2].split(";")[0].strip())
elif parts[0] == "N_TASKS":
self.N_TASKS = int(parts[2].split(";")[0].strip())
elif parts[0] == "d":
self.d = [int(x.replace(',', "")) for x in parts[3:parts.index('];')]]
elif parts[0] == "rr":
self.rr = [int(x.replace(',', "")) for x in parts[3:parts.index('];')]]
else:
parts = [x for x in parts if x.replace(',', "").isdigit()]
successors = [int(x.replace(',', "")) for x in parts]
self.suc.append(successors)
def print_data(self):
print("Capacity:", self.CAPACITY)
print("Number of Tasks:", self.N_TASKS)
print("Durations:", self.d)
print("Resource Requirements:", self.rr)
print("Succession Structure:")
for i, successors in enumerate(self.suc):
print(f"Task {i + 1} -> {successors}")
def get_task_info(self, task_number):
if 1 <= task_number <= len(self.d):
duration = self.d[task_number - 1]
resource_requirement = self.rr[task_number - 1]
return duration, resource_requirement
else:
return None
def get_successors(self, task_number):
if 1 <= task_number <= len(self.d):
return self.suc[task_number - 1]
else:
return None