1. Học hỏi
  2. /
  3. Khoa Học
  4. /
  5. Mô phỏng Sự kiện Rời rạc bằng Python

Connected

Bài tập

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.

Table with process names and their duration statistics, namely mean and standard deviation.

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. Monte Carlo trajectories for different process scenario.

Hướng dẫn

100 XP
  • 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ại proc_p["score_weight_0_10"].
  • Thiết lập vòng lặp for để chạy NUM_SIMULATIONS lượt Monte Carlo với s là 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")