1

I want to make a simulation of a store with two types of customers: a normal customer and a VIP.

I don't want to serve these customers FIFO. Instead - no matter what the queue looks like - I want to serve a VIP with chance p and a normal customer with chance 1-p.

I know the basics of Simpy but I don't know how to implement different ways a cashier picks a customer that will be served next.

Ricardo
  • 335
  • 1
  • 4
  • 13

2 Answers2

0

The following code makes no use of Simpy but it might illustrate what you need. If either or both the VIPs and normal customers need not be kept in their arrival order then you could put them in a Python set, as I have done here for VIPs. If on the other hand they have to be served in FIFO order then you could use a Python queue, as I have done here for Normals. I've added a few elements to each container. (Obviously your code would be adding some kind of Simpy objects, rather than single characters.) If a uniformly distributed pseudorandom deviate falls below p then a Normal is selected (which is bass-ackwards to what you want, I think) and returned; otherwise, a VIP.

>>> VIPs = set (['1', '2', '3'])
>>> from queue import Queue
>>> Normals = Queue()
>>> Normals.put('a')
>>> Normals.put('b')
>>> Normals.put('c')
>>> p = 0.75
>>> def selectCustomer(VIPs, Normals, p):
...     from random import random
...     if random() < p:
...         return Normals.get()
...     else:
...         return VIPs.pop()
...     
>>> selectCustomer(VIPs, Normals, p)
'2'
>>> selectCustomer(VIPs, Normals, p)
'a'
>>> selectCustomer(VIPs, Normals, p)
'1'
>>> selectCustomer(VIPs, Normals, p)
'b'
Bill Bell
  • 21,021
  • 5
  • 43
  • 58
  • This might help. I intended to use simpy because it's a discrete event simulator. Since I am interested in waiting times, ... simpy seemed useful. – Ricardo Nov 20 '16 at 23:23
0

The easy way is to create two Simpy Stores, Regular and VIP:

import simpy
import random

# create 2 stores
env = simpy.Environment()
regularStore = simpy.Store(env)
vipStore = simpy.Store(env)

# populate (you can use any generate process here)
regularStore.put('customer')
vipStore.put('VIP')

def server(env, regularStore, vipStore, p):
    # create the choose process
    if random.random() <= p:
        pickCustomer = yield vipStore.get()
    else:
        pickCustomer = yield regularStore.get()

    print(pickCustomer)

env.process(server(env, regularStore, vipStore, 0.30))
env.run()