Unverified Commit d77735cf authored by Bennett Piater's avatar Bennett Piater
Browse files

add working parser to build the graph

parent 673a597b
digraph dependencies {
0 -> 7
1 -> 8
2 -> 9
3 -> 10
4 -> 11
5 -> 12
6 -> 13
{7, 8, 9, 10, 11, 12, 13} -> 14
14 -> {15, 16, 17, 18, 19, 20, 21}
15 -> 22
16 -> 23
17 -> 24
18 -> 25
19 -> 26
20 -> 27
21 -> 28
{22, 23, 24, 25, 26, 27, 28} -> 29
}
#!/usr/bin/env python3
# use http://www.mypy-lang.org/ for static type checking
from taskgraph import Task
from typing import List
def parse_machine_prices(fname: str) -> List[float]:
with open(fname, "r") as f:
f.readline() # ignore header
lines = f.readlines()
# ignore machine type
return [float(line.split(',')[1]) for line in lines]
def parse_durations_on_machines(fname: str) -> List[List[float]]:
result = []
with open(fname, "r") as f:
f.readline() # ignore header
lines = f.readlines()
for line in lines:
line_list = line.split(',')
line_list.pop(0) # ignore task id
result.append([float(i) for i in line_list])
return result
def parse_traffic_relation(fname: str) -> List[List[int]]:
result = []
with open(fname, 'r') as f:
f.readline() # ignore header
lines = f.readlines()
for line in lines:
line_list = line.split(',')
line_list.pop(0) # ignore task id
result.append([int(i) if not i in ["", "\n"] else 0 for i in line_list])
return result
def parse_tasks() -> List[Task]:
durations = parse_durations_on_machines("task_time_instance.csv")
traffic = parse_traffic_relation("traffic_relation.csv")
# transpose traffic to get predecessors
trafficT: List[List[int]] = list(map(list, zip(*traffic)))
tasks = []
for node, parents in enumerate(trafficT):
durationList = durations[node]
predecessors = [(p, b) for p, b in enumerate(parents) if b > 0]
tasks.append(Task(node, durationList, predecessors))
return tasks
if __name__ == "__main__":
print(parse_tasks())
from typing import List, Tuple
Node = int
class Task(object):
"""Docstring for Task. """
def __init__(self, node: Node, durationOnMachines: List[float], predecessorsAndBandwidth: List[Tuple[Node, int]]):
self.node = node
self.durationOnMachines = durationOnMachines
self.predecessors = predecessorsAndBandwidth
self.inDegree: int = len(predecessorsAndBandwidth)
self.scheduledOn = None
self.startTime = None
self.endTime = None
def __repr__(self):
return "{}: {}".format(self.node, self.predecessors)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment