Simpy时间事件没有正确排序

时间:2018-04-04 09:29:53

标签: python sorting networking simulation simpy

我正在尝试使用simpy库模拟网络队列,当我设置到达率和服务时间为1秒(随机生成的exponetial dist,均值为1)时,它工作正常。但是,当我将到达率设置为比服务率快9倍(即到达=每秒9pkts,服务率=每秒1 pkt)时,简单的过程不能正确打印(按时顺序)

示例:

packet0 1219 arriving at 0.000000    
packet1 3568 arriving at 0.150441
packet2 3194 arriving at 0.300072
packet3 783 arriving at 0.303343
packet4 1308 arriving at 0.622341
packet5 150 arriving at 0.879188
packet6 353 arriving at 0.949535
packet7 1066 arriving at 1.036728
packet8 305 arriving at 1.038195
**packet0 1219 depart at 1.585690**
**packet1 3568 depart at 3.644606**
**packet9 3101 arriving at 1.074615**
packet10 217 arriving at 1.235867
packet11 186 arriving at 1.413119
packet12 169 arriving at 1.519886
packet2 3194 depart at 4.864265
packet13 2563 arriving at 1.520083

请注意,在** **之间,流程不会在时间轴内打印。有什么解决方法吗?感谢。

编辑以包含代码:

NEW_CUSTOMERS = 100  # Total number of customers
INTERVAL_CUSTOMERS = 0.111111  # Generate new customers roughly every x         seconds
SIZE = 1250

def source(env, number, interval, port):
    """Source generates customers randomly"""
    for i in range(number):
        size =  int(random.expovariate(0.0008))
        packet = Packet(env, '%d' % i, size, port, time_in_port=1)
        env.process(packet)
        t = random.expovariate(1 / interval)
        yield env.timeout(t)

def Packet(env, id, size, port, time_in_port):
    arrive = env.now
    yield Queue.buffer.put(size)
    print('packet%s %s arriving at %lf' % (id, size, arrive))

    with port.request() as req:
        yield req

        tip = random.expovariate(1/time_in_port)
        yield env.timeout(tip)
        amount = size
        yield Queue.buffer.get(amount)
        print('packet%s %s depart at %lf' % (id, size, env.now))

class queue:
    def __init__(self, env):
        self.buffer = simpy.Container(env, init = 0, capacity=12500)

random.seed(RANDOM_SEED)
env = simpy.Environment()
Queue = queue(env)

# Start processes and run
port = simpy.Resource(env, capacity=1)
env.process(source(env, NEW_CUSTOMERS, INTERVAL_CUSTOMERS, port))
env.run()

0 个答案:

没有答案