-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
51 lines (42 loc) · 1.9 KB
/
utils.py
File metadata and controls
51 lines (42 loc) · 1.9 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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
def make_random_task(num_jobs = 5, max_time = 5):
deadlines = np.array(np.random.rand(num_jobs)* (max_time - 1) + 1).astype(int)
profits = np.array(np.random.rand(num_jobs)* 50).astype(int)
times = np.array(np.random.rand(num_jobs) * (max_time - 1) * 0.6 + 1).astype(int)
return times, deadlines, profits
def visualize(results, save = None):
schedule = pd.DataFrame(results)
JOBS = sorted(list(schedule['Job'].unique()))
MACHINES = sorted(list(schedule['Machine'].unique()))
makespan = schedule['Finish'].max()
bar_style = {'alpha':1.0, 'lw':25, 'solid_capstyle':'butt'}
text_style = {'color':'white', 'weight':'bold', 'ha':'center', 'va':'center'}
colors = mpl.cm.Dark2.colors
schedule.sort_values(by=['Job', 'Start'])
schedule.set_index(['Job', 'Machine'], inplace=True)
fig, ax = plt.subplots(2,1, figsize=(12, 5+(len(JOBS)+len(MACHINES))/4))
for jdx, j in enumerate(JOBS, 1):
for mdx, m in enumerate(MACHINES, 1):
if (j,m) in schedule.index:
xs = schedule.loc[(j,m), 'Start']
xf = schedule.loc[(j,m), 'Finish']
ax[0].plot([xs, xf], [jdx]*2, c=colors[mdx%7], **bar_style)
ax[0].text((xs + xf)/2, jdx, m, **text_style)
ax[1].plot([xs, xf], [mdx]*2, c=colors[jdx%7], **bar_style)
ax[1].text((xs + xf)/2, mdx, j, **text_style)
ax[0].set_title('Job Schedule')
ax[0].set_ylabel('Job')
ax[1].set_title('Machine Schedule')
ax[1].set_ylabel('Machine')
for idx, s in enumerate([JOBS, MACHINES]):
ax[idx].set_ylim(0.5, len(s) + 0.5)
ax[idx].set_yticks(range(1, 1 + len(s)))
ax[idx].set_yticklabels(s)
ax[idx].set_xlabel('Time')
ax[idx].grid(True)
fig.tight_layout()
if save != None:
fig.savefig(save)