forked from ANRGUSC/saga
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
99 lines (73 loc) · 3.6 KB
/
Copy pathmain.py
File metadata and controls
99 lines (73 loc) · 3.6 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
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
98
99
import logging
import pathlib
from typing import Dict, List
import networkx as nx
from matplotlib import pyplot as plt
from saga.scheduler import Task
from saga.schedulers import CpopScheduler, HeftScheduler
from saga.utils.draw import draw_gantt, draw_network, draw_task_graph
logging.basicConfig(level=logging.DEBUG)
thisdir = pathlib.Path(__file__).parent.absolute()
def get_makespan(schedule: Dict[str, List[Task]]) -> float:
"""Get makespan of a schedule.
Args:
schedule (Dict[str, List[Task]]): Schedule to get makespan of.
Returns:
float: Makespan of schedule.
"""
return max([0 if not tasks else tasks[-1].end for tasks in schedule.values()])
def main():
"""Main function."""
savepath = thisdir / 'figures'
savepath.mkdir(exist_ok=True)
# simple diamon task graph
task_graph = nx.DiGraph()
task_graph.add_nodes_from([1, 2, 3, 4, 5], weight=3)
task_graph.add_edges_from([(1, 2), (1, 3), (1, 4)], weight=2)
task_graph.add_edges_from([(2, 5), (3, 5), (4, 5)], weight=3)
axis = draw_task_graph(task_graph, use_latex=False)
axis.get_figure().savefig(savepath / 'task_graph.pdf')
plt.close(axis.get_figure())
# simple 3-node network (complete graph)
network = nx.Graph()
network.add_nodes_from([1, 2, 3], weight=1)
network.add_edges_from([(1, 2), (1, 3), (2, 3)], weight=1)
network.add_edges_from([(1, 1), (2, 2), (3, 3)], weight=1e9)
network.nodes[3]['weight'] = 1 + 1e-9
axis = draw_network(network, draw_colors=False, use_latex=False)
axis.get_figure().savefig(savepath / 'network.pdf')
plt.close(axis.get_figure())
schedule_heft = HeftScheduler().schedule(network, task_graph)
heft_makespan = get_makespan(schedule_heft)
schedule_cpop = CpopScheduler().schedule(network, task_graph)
cpop_makespan = get_makespan(schedule_cpop)
# modify network
network.edges[(1, 3)]['weight'] = 1/2
network.edges[(2, 3)]['weight'] = 1/2
axis = draw_network(network, draw_colors=False, use_latex=False)
axis.get_figure().savefig(savepath / 'modified_network.pdf')
plt.close(axis.get_figure())
schedule_heft_modified = HeftScheduler().schedule(network, task_graph)
heft_makespan_modified_network = get_makespan(schedule_heft_modified)
schedule_cpop_modified = CpopScheduler().schedule(network, task_graph)
cpop_makespan_modified_network = get_makespan(schedule_cpop_modified)
print(f'HEFT makespan: {heft_makespan:.2f}')
print(f'CPOP makespan: {cpop_makespan:.2f}')
print(f'HEFT makespan (modified network): {heft_makespan_modified_network:.2f}')
print(f'CPOP makespan (modified network): {cpop_makespan_modified_network:.2f}')
# Draw schedules
max_makespan = max(heft_makespan, cpop_makespan, heft_makespan_modified_network, cpop_makespan_modified_network)
## HEFT
axis = draw_gantt(schedule_heft, use_latex=False, xmax=max_makespan)
axis.get_figure().savefig(savepath / 'heft_schedule.pdf')
## CPOP
axis = draw_gantt(schedule_cpop, use_latex=False, xmax=max_makespan)
axis.get_figure().savefig(savepath / 'cpop_schedule.pdf')
## HEFT (modified network)
axis = draw_gantt(schedule_heft_modified, use_latex=False, xmax=max_makespan)
axis.get_figure().savefig(savepath / 'heft_schedule_modified_network.pdf')
## CPOP (modified network)
axis = draw_gantt(schedule_cpop_modified, use_latex=False, xmax=max_makespan)
axis.get_figure().savefig(savepath / 'cpop_schedule_modified_network.pdf')
if __name__ == '__main__':
main()