Tối ưu hóa sản xuất: Score & Rank
Hãy sử dụng cùng mô hình sự kiện rời rạc của nhà máy đồng hồ treo tường và thiết lập một quy trình tối ưu hóa kiểu "Score & Rank". Để bạn tiện theo dõi, quy trình sản xuất được tóm tắt lại trong bảng dưới đây. Thông tin đã được lưu trong một list các dictionary tên là processes, mỗi quy trình là một dictionary. Các khóa (key) của dictionary này tương ứng với tiêu đề các cột trong bảng.

Phương thức plot_results() dùng để tạo các biểu đồ trong bài tập này đã được nạp sẵn và hiển thị bên dưới.
def plot_results(objective_func):
# Score
fig, axes = plt.subplots(1, len(processes), sharey=True, figsize=(10, 8))
for p in range(len(processes)):
sns.scatterplot(ax=axes[p], x=process_duration_all[:, p], y=objective_func, c=objective_func, cmap="turbo_r")
axes[p].set_title(processes[p]["Name"], rotation = 20, horizontalalignment='left')
axes[p].set_xlabel("Duration [min]", rotation = -10)
axes[p].grid()
axes[0].set_ylabel("Objective function score")
plt.show()
# Rank
index_sort = np.argsort(objective_func)
fig, axes = plt.subplots(1, len(processes), sharey=True, figsize=(10, 8))
for p in range(len(processes)):
sns.lineplot(ax=axes[p], x=np.linspace(0, NUM_SIMULATIONS, NUM_SIMULATIONS),
y=process_duration_all[index_sort, p], color="orchid")
axes[p].set_title(processes[p]["Name"], rotation = 20, horizontalalignment='left')
axes[p].set_xlabel("Score-ranked scenarios", rotation = -10)
axes[p].grid()
axes[0].set_ylabel("Duration [min]")
plt.show()
Vòng lặp lấy mẫu Monte Carlo sẽ tạo ra một loạt quỹ đạo quy trình khả dĩ và chấm điểm chúng, như minh họa trong hình.

Bài tập này là một phần của khóa học
Mô phỏng Sự kiện Rời rạc bằng Python
Hướng dẫn bài tập
- Cộng phần đóng góp điểm của từng quy trình, biết rằng thời lượng của các quy trình được lưu tại
process_duration_all[s, p]và trọng số tương ứng tạiproc_p["score_weight_0_10"]. - Thiết lập vòng lặp for để chạy
NUM_SIMULATIONSlượt Monte Carlo vớislà biến giả. - Chạy bộ máy Monte Carlo được đóng gói trong hàm
run_monte_carlo()(hàm này sẽ tạo cả biểu đồ "score" và "rank")
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
def objective_function_calc():
objective_func = np.ones(NUM_SIMULATIONS)
for s in range(NUM_SIMULATIONS):
for p in range(len(processes)):
proc_p = processes[p]
# Add the score contribution of each process
objective_func[s] += ____
plot_results(objective_func)
def run_monte_carlo():
# Set the for-loop to run NUM_SIMULATIONS Monte-Carlo runs
____
env = simpy.Environment()
env.process(manufractoring_process(env, s))
env.run()
objective_function_calc()
# Run the Monte Carlo function
____