-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_graphics.py
117 lines (90 loc) · 3.58 KB
/
run_graphics.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
__author__ = 'Artem Bishev'
import numpy as np
from test_gen import generate_windows, generate_jobs
from itertools import product
from scheduler import HybridSchedule
import matplotlib.pyplot as plt
import matplotlib
from scheduler_graphics import plot_windows
min_window_size, max_window_size = 10, 100
total_len = 500
min_job_duration, max_job_duration = 1, 40
partitions = {'A': 0.3,
'B': 0.3,
'C': 0.4}
load_factor = 0.75
hardnesses = np.linspace(1.0, 2.0, num=20)
n_runs = 100
quality_rate = []
quality_block = []
hardness_arr = []
for h in hardnesses:
print("h = {}".format(h))
for _ in range(n_runs):
windows = list(generate_windows(min_window_size, max_window_size,
partitions, total_len))
jobs = list(generate_jobs(windows, h, min_job_duration,
max_job_duration, load_factor))
hardness = sum(job.length / job.duration
for job in jobs) / len(jobs) # Aposteriori hardness
q_rate = []
q_block = []
scores = ['default', 'enhanced']
for score, window_score in product(scores, repeat=2):
recalc_jobs = 1.0 if score == 'enhanced' else 0.0
s = HybridSchedule(score, window_score, recalc_jobs)
s.build(jobs, min_window_size)
q_rate.append(s.rate())
q_block.append(1.0 if s.exists() else 0.0)
quality_block.append(q_block)
quality_rate.append(q_rate)
hardness_arr.append(hardness)
quality_rate = np.array(quality_rate)
quality_block = np.array(quality_block)
hardness_arr = np.array(hardness_arr)
hist, bins = np.histogram(hardness_arr, bins=20)
x = [0.5 * (bins[i + 1] + bins[i])
for i, _ in enumerate(hist[:-5])]
y = []
for i, count in enumerate(hist[:-5]):
mask = (bins[i] <= hardness_arr) & (hardness_arr < bins[i + 1])
y.append(np.mean(quality_rate[mask], axis=0))
y = np.array(y)
matplotlib.rc('font', family="Courier New")
for i in range(y.shape[1]):
plt.plot(x, y[:, i])
plt.xlabel("Жёсткость директивных интервалов")
plt.ylabel("Средняя доля размещённых работ")
plt.show()
windows = list(generate_windows(min_window_size, max_window_size,
partitions, 700))
jobs = list(generate_jobs(windows, 1.05, min_job_duration,
max_job_duration, 0.85))
plot_windows(windows, partitions=partitions, jobs=jobs)
s = HybridSchedule('enhanced', 'enhanced', recalc_jobs=1.0)
s.build(jobs, min_window_size)
plot_windows(s)
load_factors = np.linspace(0.25, 0.95, num=16)
hardness = 1.1
y1, y2 = [], []
for load in load_factors:
print("load = {}".format(load))
rate = 0
block = 0
for _ in range(50):
windows = list(generate_windows(min_window_size, max_window_size,
partitions, total_len))
jobs = list(generate_jobs(windows, hardness, min_job_duration,
max_job_duration, load))
s = HybridSchedule('enhanced', 'enhanced', recalc_jobs=1.0)
s.build(jobs, min_window_size)
rate += s.rate()
block += 1.0 if s.exists() else 0.0
y2.append(rate / 50)
y1.append(block / 50)
plt.plot(load_factors, y1, 'b', label="Доля построенных расписаний")
plt.plot(load_factors, y2, 'b--', label="Средняя доля размещённых работ")
plt.legend(loc='best')
plt.xlabel("Коэффициент загрузки процессора")
plt.show()