forked from zcaicaros/L2D
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdispatching_rules.py
84 lines (72 loc) · 3.26 KB
/
dispatching_rules.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
from itertools import compress
import numpy as np
from Params import configs
from JSSP_Env import SJSSP
from plot import plot_schedule
def shortest_processing_time(candidates, mask, dur):
# perform masking
inverted_mask = [not elem for elem in mask]
masked_candidates = np.array(list(compress(candidates, inverted_mask)))
durations = np.take(dur, masked_candidates)
shortest_op = np.argmin(durations)
action = masked_candidates[shortest_op]
return action
def largest_processing_time(candidates, mask, dur):
# perform masking
inverted_mask = [not elem for elem in mask]
masked_candidates = np.array(list(compress(candidates, inverted_mask)))
durations = np.take(dur, masked_candidates)
longest_op = np.argmax(durations)
action = masked_candidates[longest_op]
return action
def most_work_remaining(candidates, mask, env):
# only collect information for unscheduled operations
unfinished_mark = np.zeros_like(env.finished_mark)
where_0 = np.where(env.finished_mark == 0)
unfinished_mark[where_0] = 1
unfinished_duration_matrix = env.dur * unfinished_mark
# sum up remaining processing time
job_tpt = np.sum(unfinished_duration_matrix, axis=1)
# perform masking for jobs and candidates
inverted_mask = [not elem for elem in mask]
masked_candidates = np.array(list(compress(candidates, inverted_mask)))
job_idx = np.arange(env.number_of_jobs)
masked_jobs = np.array(list(compress(job_idx, inverted_mask)))
# remove illegal jobs from the tpt array
mwr_candidates = job_tpt[masked_jobs]
# take job index with highest mwr
longest_op = np.argmax(mwr_candidates)
# action = operation in masked_candidates at the job index
action = masked_candidates[longest_op]
return action
def most_operations_remaining(candidates, mask, env):
unfinished_mark = np.zeros_like(env.temp1)
where_0 = np.where(env.temp1 == 0)
unfinished_mark[where_0] = 1
ops_remaining = np.sum(unfinished_mark, axis=1)
# perform masking for jobs and candidates
inverted_mask = [not elem for elem in mask]
masked_candidates = np.array(list(compress(candidates, inverted_mask)))
job_idx = np.arange(env.number_of_jobs)
masked_jobs = np.array(list(compress(job_idx, inverted_mask)))
mor_candidates = ops_remaining[masked_jobs]
max_ops = np.where((mor_candidates == np.max(mor_candidates)))[0]
most_ops_remaining = np.random.choice(max_ops)
# most_ops_remaining = np.argmax(mor_candidates)
action = masked_candidates[most_ops_remaining]
return action
def random_selection(candidates, mask):
inverted_mask = [not elem for elem in mask]
masked_candidates = np.array(list(compress(candidates, inverted_mask)))
action = np.random.choice(masked_candidates)
return action
def earliest_due_date(candidates, mask, env, due_dates):
inverted_mask = [not elem for elem in mask]
masked_candidates = np.array(list(compress(candidates, inverted_mask)))
job_idx = np.arange(env.number_of_jobs)
masked_jobs = np.array(list(compress(job_idx, inverted_mask)))
# remove illegal jobs from the due date array
due_dates_candidates = due_dates[masked_jobs]
earliest_op = np.argmin(due_dates_candidates)
action = masked_candidates[earliest_op]
return action