技能 simpy
🔬

simpy

安全 ⚙️ 外部命令🌐 網路存取📁 檔案系統存取

使用 SimPy 建立離散事件模擬

也可從以下取得: davila7

SimPy 讓你用流程、佇列與共享資源來建模複雜系統。在實作前先模擬製造產線、服務作業、網路流量與物流,以最佳化效能。

支援: Claude Codex Code(CC)
🥈 77 白銀
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「simpy」。 Create a SimPy simulation of customers arriving at a bank with 2 tellers. Customers arrive every 3-5 minutes and service takes 5-8 minutes. Run for 8 hours and show average wait time.

預期結果:

  • Simulation Results: 8-hour bank operation
  • Total customers served: 147
  • Average wait time: 4.2 minutes
  • Maximum wait time: 18.7 minutes
  • Teller utilization: 87%
  • Queue length peaked at 12 customers around hour 6

正在使用「simpy」。 Build a SimPy model of a 3-stage manufacturing line where parts go through cutting (10 min), assembly (15 min), and inspection (5 min). Each stage has 1 machine. Analyze throughput.

預期結果:

  • Manufacturing Line Analysis Results:
  • Parts completed: 23 over 8-hour shift
  • Stage utilization: Cutting 96%, Assembly 72%, Inspection 36%
  • Bottleneck identified: Cutting station
  • Average cycle time per part: 32 minutes
  • Suggestion: Add second cutting machine to increase throughput by 35%

正在使用「simpy」。 Model a cloud data center with 10 servers handling 3 types of jobs.

預期結果:

  • Resource Allocation Results:
  • Short jobs: 450 completed, avg wait 0.3 min, utilization 45%
  • Medium jobs: 180 completed, avg wait 2.1 min, utilization 78%
  • Long jobs: 45 completed, avg wait 8.4 min, utilization 92%
  • Optimal allocation: 3 servers short, 4 medium, 3 long jobs
  • Current over-provisioning: 2 servers

安全審計

安全
v4 • 1/17/2026

Static analysis flagged 260 potential security issues, but evaluation confirms all are false positives. The 'external_commands' findings are markdown backticks used for code formatting, not shell execution. The 'weak cryptographic algorithm' flags refer to random.seed() for simulation reproducibility. No actual security risks exist in this legitimate SimPy discrete-event simulation skill.

9
已掃描檔案
3,202
分析行數
3
發現項
4
審計總數
審計者: claude 查看審計歷史 →

品質評分

68
架構
100
可維護性
87
內容
20
社群
100
安全
91
規範符合性

你能建構什麼

最佳化製造產線

建模生產流程以找出瓶頸、平衡產能並縮短週期時間。

模擬網路流量

在不同負載條件下分析封包路由、頻寬分配與延遲。

設計排隊系統

模擬銀行、醫院或零售業的顧客流量,以決定最佳人力配置。

試試這些提示

基本排隊模擬
Create a SimPy simulation of customers arriving at a bank with 2 tellers. Customers arrive every 3-5 minutes and service takes 5-8 minutes. Run for 8 hours and show average wait time.
製造產線
Build a SimPy model of a 3-stage manufacturing line where parts go through cutting (10 min), assembly (15 min), and inspection (5 min). Each stage has 1 machine. Analyze throughput.
網路封包模擬
Simulate packets arriving at a router with 100 Mbps bandwidth. Packets are 1-5 KB and arrive at 50 packets per second. Show queue length and packet loss under peak load.
資源最佳化
Model a cloud data center with 10 servers handling 3 types of jobs: short (1-5 min), medium (10-20 min), long (30-60 min). Jobs arrive randomly. Find optimal server allocation per job type.

最佳實務

  • 在請求資源時一律使用 context manager(with 陳述式)以確保正確清理並避免死結
  • 在比較不同模擬情境時設定 random.seed() 以確保結果可重現
  • 在模擬過程中持續監控並蒐集資料,而不是只在結束時,才能捕捉暫態行為

避免

  • 在流程函式中忘記 yield 陳述式會使流程瞬間執行完畢,沒有正確的時間推進
  • 重複使用已觸發的事件會造成模擬錯誤或非預期行為
  • 使用 time.sleep() 這類阻塞式 Python 操作而非 env.timeout() 會破壞模擬的時間模型

常見問題

Environment 與 RealtimeEnvironment 有什麼差異?
Environment 會以最快速度執行模擬,而 RealtimeEnvironment 會將模擬時間與真實時間同步,適用於即時或硬體迴路應用。
我該如何為模擬選擇合適的資源類型?
基本容量限制用 Resource、優先序排隊用 PriorityResource、燃料或水等大量物料用 Container、物件儲存且可 FIFO 或過濾用 Store。
我可以在 SimPy 中中斷正在執行的流程嗎?
可以,使用 process.interrupt() 強制恢復暫停的流程。這在建模搶占、逾時或外部取消事件時很有用。
如何在模擬期間蒐集自訂統計資料?
使用提供的腳本中的 ResourceMonitor 類別,或透過修補資源方法並在模擬執行期間追蹤事件來建立自訂監控器。
建模需要同步的並行流程的最佳方式是什麼?
用 env.process() 啟動多個流程,並搭配 yield 與 & 運算子等待所有流程完成,或用 | 等待任一流程完成。
如何匯出模擬結果以供外部分析?
使用 ResourceMonitor 中的 export_csv() 方法儲存蒐集到的資料,或使用模擬過程中追蹤的資料字典撰寫自訂匯出函式。