Paket SimPy: Jenis resource

Simulasi Peristiwa Diskret dengan Python

Dr Diogo Costa

Adjunct Professor, University of Saskatchewan, Canada & CEO of ImpactBLUE-Scientific

Jenis resource yang tersedia

  • SimPy menyediakan tiga jenis resource:

  • resource

  • container
  • store
Simulasi Peristiwa Diskret dengan Python

Jenis resource yang tersedia

simpy.Resource()

  • Berbagi resource antar proses
  • Contoh: meja di restoran

simpy.Container()

  • Resource untuk berbagi materi homogen antar proses
  • Kuantitas bisa diskret (mis. apel) atau kontinu (mis. air)
  • Contoh: reservoir air

simpy.Store()

  • Menyimpan jumlah objek yang mungkin tak terbatas
  • Contoh: supermarket
Simulasi Peristiwa Diskret dengan Python

Metode: simpy.Resource()

Membuat resource

resource_1 = simpy.Resource(env, capacity=8)
  • Dipakai saat kapasitas resource terbatas (mis. capacity=8)
  • Membatasi jumlah proses yang mengakses resource secara bersamaan
  • Proses harus meminta hak pakai resource
    • Jika semua resource dipakai, permintaan diantrekan
  • Saat proses melepas resource, permintaan tertunda dipicu

Meminta resource

# Buka permintaan resource
with resource_1.request() as request:

# Lakukan permintaan resource yield request
# Setelah resource tersedia yield env.timeout(event_duration)
Simulasi Peristiwa Diskret dengan Python

Resource: prioritas dan preemption

  • Variasi dari resource sebelumnya

    resource_1 = simpy.PreemptiveResource(
    env, capacity=1)
    
  • Beberapa proses dapat memiliki prioritas lebih tinggi

  • Contoh: teknisi perbaikan

    • Prioritas 1: memperbaiki mesin rusak
    • Prioritas 2 atau lebih rendah: pemeliharaan mesin
  • Penggunaan mirip dengan simpy.Resource()

  • Meminta resource dengan prioritas tertinggi

    with resource_1.request(priority=1) as 
    request:
    
    yield request
    yield env.timeout(process_duration)
    
  • Meminta resource dengan prioritas lebih rendah

    with resource_1.request(priority=2) as 
    request:
    
    yield request
    yield env.timeout(process_duration)
    
Simulasi Peristiwa Diskret dengan Python

Metode: simpy.Container()

  • Berguna untuk memodelkan produksi/konsumsi bahan homogen yang tidak dibedakan

  • Dapat berupa kontinu (seperti air) atau diskret (seperti apel)

Contoh: Cadangan bensin di SPBU.

  • Mobil mengurangi cadangan, truk pengisi menambahnya
  • Membuat container
    tank_1 = simpy.Container(
    env, tank_size, init=tank_size)
    
  • Tambah dan kurangi dari container/tangki

    yield tank_1.put(add_quantity)
    yield tank_1.get(remove_quantity)
    
  • Dapatkan jumlah saat ini di tangki

    tank_1.level
    
  • Dapatkan kapasitas total tangki

    tank_1.capacity
    
Simulasi Peristiwa Diskret dengan Python

Metode: simpy.Store()

  • Membuat store

    store_1 = simpy.Store(
    env, capacity=2)
    
  • Mirip dengan simpy.Container() tetapi dapat menyimpan objek berbeda

  • Berbeda dengan "jumlah" yang cukup abstrak pada container

  • Tambah dan ambil dari penyimpanan
yield store_1.put("item_1")
yield store_1.get()
  • Dapatkan daftar item yang tersedia

    store_1.items
    
  • Dapatkan kapasitas store

    store_1.capacity
    
Simulasi Peristiwa Diskret dengan Python

Bagaimana resource SimPy membantu keputusan bisnis?

Contoh

  • Supermarket dengan 1 kasir
  • Pemilik ingin tahu apakah layak menambah kasir
  • Apakah lebih banyak kasir mengurangi waktu tunggu?

Kondisi saat ini: 1 kasir

  • simpy.Resource(env, capacity=1)
...
waktu: 23,7 mnt | Customer 30 > Selesai

Skenario disimulasikan: n kasir

  • simpy.Resource(env, capacity=2)
...
waktu: 13,2 mnt | Customer 30 > Selesai
  • simpy.Resource(env, capacity=3)
...
waktu: 8,6 mnt | Customer 30 > Selesai
  • simpy.Resource(env, capacity=4)
...
waktu: 8,6 mnt | Customer 30 > Selesai
Simulasi Peristiwa Diskret dengan Python

Ayo berlatih!

Simulasi Peristiwa Diskret dengan Python

Preparing Video For Download...