簡體   English   中英

model如何多次到達分配?

[英]How do you model multiple arrival distributions?

Python:

我正在模擬一個具有兩種來電類型的呼叫中心:銷售電話和服務電話。

這些調用具有不同的、獨立的分布,它們進入同一個系統。

我有 function,包含:

iat_sales = random.expovariate(1/3) 
yield env.timeout(iat_sales)

我想合並:

iat_service = random.triangular(0,0,6) 
yield env.timeout(iat_service)

我怎樣才能同時產生每個事件?


這是我想出的解決方案:

def arrival_list():
    
    sales_time = 0           #sim time of sales arrival
    service_time = 0           #sim time of service arrival
    sales_list=[]           #list of sequential sales arrivals [arrival time,'sales']
    service_list=[]         #list of sequential sales arrivals [arrival time,'service']
    arrivals = []      #ordered list of arrivals (sales and service merged) [arrival time,arrival type,iat]
    
    while sales_time < sim_end:
        iat_sales = random.expovariate(sales_rate)                    
        
        sales_time += iat_sales
        
        sales=[sales_time,'sales']
        sales_list.append(sales)
        
    while service_time < sim_end:
        iat_service = random.triangular(0,6,0)        #### 
        
        service_time += iat_service

        service=[service_time,'service']
        service_list.append(service)
        
    arrivals = sales_list + service_list
    arrivals.sort()
    arrivals[0].append(arrivals[0][0])
    
    for i in range(len(arrivals)-1):
        arrivals[i+1].append(arrivals[i+1][0]-arrivals[i][0])
    
    return arrivals

作為參考,一個簡單的實現可以像這樣完成,其中模擬以 1 秒的間隔無限期運行,如果它們的隨機值超過某些閾值,則認為調用到達:

import random
import time

def generate_calls():
    return random.expovariate(1/3), random.triangular(10, 20, 5)

def simulation(count, sales_acceptance, services_acceptance):
    # run the simulation indefinitely
    while True:
        print('Time: {}'.format(count))
        sales_call, services_call = generate_calls()
        
        # calls arrive if the values exceed some thresholds
        if sales_call > sales_acceptance:
            print('Sales call arrived!')
        if services_call > services_acceptance:
            print('Services call arrived!')
        time.sleep(1)
        count += 1

simulation(1, 2, 13)

您可以擁有三個獨立的並行進程。 1- 一個撥打銷售電話的流程。 2- 一個調用服務的過程。 3- 一個處理呼叫的過程。

import simpy 
import random

sim_end = 1000;

def generateSalesCall(env, call_pipe):
    while env.now < sim_end:
        # put call in the pipe
        yield call_pipe.put("sales");
        interval = random.expovariate(1/3);
        yield env.timeout(interval);

def generateServiceCall(env, call_pipe):
    while env.now < sim_end:
        # put call in the pipe
        yield call_pipe.put("service");
        interval = random.triangular(0,6,0);
        yield env.timeout(interval);

def handleCalls(env, call_pipe):
    while(True):
        call = yield call_pipe.get();
        if call == "sales":
              print(env.now, "sales call");
        elif call == "service":
              print(env.now, "service call");

env = simpy.Environment();
call_pipe = simpy.Store(env);
env.process(generateSalesCall(env, call_pipe));
env.process(generateServiceCall(env, call_pipe));
env.process(handleCalls(env, call_pipe));
env.run();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM