NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import simpy
import random

RANDOM_SEED = 9780

INTERARRIVAL_MEAN = 15.6 # The durations between two consecutive calls are observed to be exponentially distributed with a mean of 15,6 minutes.
INTERARRIVAL_RATE = 1 / INTERARRIVAL_MEAN

# The time it takes to collect and record the details of a caller is assumed to be distributed according to the
# Gaussian (i.e. Normal) distribution with a mean of 4,2
# and a standard deviation of 1,5 minutes.
OPERATOR_SERVICE_MEAN = 4.2 # minutes
OPERATOR_SERVICE_VAR = 1.5 # minutes

EXPERT_SERVICE_MEAN = 9.3 # The service time of the expert is Exponentially distributed with a mean of 9,3 minutes.
EXPERT_SERVICE_RATE = 1 / EXPERT_SERVICE_MEAN

EXPERT_SHIFT_DURATION = 480 # minutes
AVG_BREAKS_PER_SHIFT = 8
EXPERT_BREAK_DURATION = 5 # minutes
TOTAL_CUSTOMER_NUM = 1000

random.seed(RANDOM_SEED)

operator_work_time = 0
expert_work_time = 0
customer_number = 0

service_times = [] #Duration of the conversation between the customer and the operator (Service time)
queue_w_times = [] #Time spent by a customer while it waits for the operator (Queue waiting time Wq)



class Customer(object):
def __init__(self, name, env, operator, expert):
global customer_number
customer_number += 1
self.name = name
self.env = env
self.arrival_to_system_t = self.env.now
self.arrival_to_expert_t = -1
self.wait_duration = 0
self.action = env.process(self.call(operator, expert))


def call(self, operator, expert):
print('[%g]t: %s initiated a call' % (self.env.now, self.name))

with operator.request() as req:
yield req
print('[%g]t: %s is assigned to an operator' % (self.env.now, self.name))

self.wait_duration += (self.env.now - self.arrival_to_system_t)

yield self.env.process(self.ask_question())
print('[%g]t: %s is done at operator' % (self.env.now, self.name))

self.arrival_to_expert_t = self.env.now
with expert.request() as req:
yield req
print('[%g]t: %s is assigned to the expert' % (self.env.now, self.name))

self.wait_duration += (self.env.now - self.arrival_to_expert_t)

yield self.env.process(self.get_service())
print('[%g]t: %s is done at expert' % (self.env.now, self.name))


def ask_question(self):
duration = random.normalvariate(OPERATOR_SERVICE_MEAN, OPERATOR_SERVICE_VAR)
yield self.env.timeout(duration)
global operator_work_time
operator_work_time += duration

def get_service(self):
duration = random.expovariate(EXPERT_SERVICE_RATE)
yield self.env.timeout(duration)
global expert_work_time
expert_work_time += duration


def customer_generator(env, operator, expert):
for i in range(TOTAL_CUSTOMER_NUM):
yield env.timeout(random.expovariate(INTERARRIVAL_RATE))
customer = Customer('Cust %s' % (i+1), env, operator, expert)

def break_generator(env):
while True:
global customer_number
if customer_number == TOTAL_CUSTOMER_NUM:
break
duration = random.expovariate(AVG_BREAKS_PER_SHIFT/EXPERT_SHIFT_DURATION)
print('[%g]t: Expert decided to take a break after about %g minutes' % (env.now, duration))
yield env.timeout(duration)
with expert.request() as req:
yield req
print('[%g]t: Expert takes a break now' % env.now, env.now)
yield env.timeout(EXPERT_BREAK_DURATION)
print('[%g]t: Expert returns from break' % env.now)


env = simpy.Environment()
operator = simpy.Resource(env, capacity = 1)
expert = simpy.Resource(env, capacity = 1)
env.process(break_generator(env))
env.process(customer_generator(env, operator, expert))
env.run()

print(queue_w_times)
print(service_times)
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.