예제 #1
0
    def test_QueueServer_accounting(self):

        nSe = np.random.randint(1, 10)
        mu = self.lam / (self.rho * nSe)

        def arr(t):
            return t + np.random.exponential(1 / self.lam)

        def ser(t):
            return t + np.random.exponential(1 / mu)

        q = qt.QueueServer(num_servers=nSe, arrival_f=arr, service_f=ser)
        q.set_active()
        num_events = 15000

        ans = np.zeros((num_events, 3), bool)

        for k in range(num_events):
            nt = len(q._departures) + len(q.queue) + len(q._arrivals) - 2
            nS = len(q._departures) + len(q.queue) - 1
            ans[k, 0] = nt == q._num_total
            ans[k, 1] = nS == q.num_system
            ans[k, 2] = len(q._departures) - 1 <= q.num_servers
            q.simulate(n=1)

        self.assertTrue(ans.all())
예제 #2
0
    def test_QueueServer_set_num_servers_errors(self):
        q = qt.QueueServer(num_servers=3)

        with self.assertRaises(TypeError):
            q.set_num_servers(3.0)

        with self.assertRaises(ValueError):
            q.set_num_servers(0)
예제 #3
0
    def test_QueueServer_set_inactive(self):

        q = qt.QueueServer()
        q.set_active()

        a = q.active
        q.set_inactive()

        self.assertTrue(a)
        self.assertTrue(not q.active)
예제 #4
0
    def test_QueueServer_copy(self):

        q1 = qt.QueueServer(seed=15)
        q1.set_active()
        q1.simulate(t=100)

        q2 = q1.copy()
        t = q1.time
        q2.simulate(t=20)

        self.assertTrue(t < q2.time)
예제 #5
0
def observed_new_arrival():

    rate = lambda t: 2 + 16 * np.sin(np.pi * t / 8)**2
    arr = lambda t: qt.poisson_random_measure(t, rate, 18)
    ser = lambda t: t + np.random.gamma(4, 0.1)
    q = qt.QueueServer(5, arrival_f=arr, service_f=ser, seed=54)
    q.set_active()

    nA0, nD0 = q.num_arrivals[1], q.num_departures
    q.simulate(nA=1000)
    result = q.num_departures - nD0, q.num_arrivals[1] - nA0,
    print(result)
예제 #6
0
    def test_QueueServer_active_cap(self):
        def r(t):
            return 2 + np.sin(t)

        arr = functools.partial(qt.poisson_random_measure, rate=r, rate_max=3)

        q = qt.QueueServer(active_cap=1000, arrival_f=arr, seed=12)
        q.set_active()
        q.simulate(n=3000)

        self.assertEqual(q.num_departures, 1000)
        self.assertEqual(q.num_arrivals, [1000, 1000])
예제 #7
0
def time_simulation():

    rate = lambda t: 2 + 16 * np.sin(np.pi * t / 8)**2
    arr = lambda t: qt.poisson_random_measure(t, rate, 18)
    ser = lambda t: t + np.random.gamma(4, 0.1)
    q = qt.QueueServer(5, arrival_f=arr, service_f=ser, seed=54)
    q.set_active()

    num_events = q.num_arrivals[0] + q.num_departures
    t0 = q.time
    q.simulate(t=175)
    round(float(q.time - t0), 1)
    result = q.num_arrivals[1] + q.num_departures - num_events
    print(result)
예제 #8
0
    def test_QueueServer_set_num_servers(self):

        nSe = np.random.randint(1, 10)
        q = qt.QueueServer(num_servers=nSe)

        Se1 = q.num_servers
        q.set_num_servers(2 * nSe)

        Se2 = q.num_servers
        q.set_num_servers(np.infty)

        self.assertEqual(Se1, nSe)
        self.assertEqual(Se2, 2 * nSe)
        self.assertTrue(q.num_servers is np.inf)
예제 #9
0
def event_simulation():

    rate = lambda t: 2 + 16 * np.sin(np.pi * t / 8)**2
    arr = lambda t: qt.poisson_random_measure(t, rate, 18)
    ser = lambda t: t + np.random.gamma(4, 0.1)
    q = qt.QueueServer(5, arrival_f=arr, service_f=ser, seed=54)
    q.set_active()

    q.collect_data = True
    q.simulate(100)
    data = q.fetch_data()
    print(data)

    num_events = q.num_arrivals[0] + q.num_departures
    print("the number of job arrival: ", q.num_arrivals[0])
    print("the number of job departure: ", q.num_departures)
    print("the total number of jobs ", num_events)
예제 #10
0
    def test_QueueServer_simulation(self):

        nSe = np.random.randint(1, 10)
        mu = self.lam / (self.rho * nSe)

        def arr(t):
            return t + np.random.exponential(1 / self.lam)

        def ser(t):
            return t + np.random.exponential(1 / mu)

        q = qt.QueueServer(num_servers=nSe, arrival_f=arr, service_f=ser)
        q.set_active()
        num_events = 5000

        ans = np.zeros(4, bool)

        k = np.random.randint(num_events * 0.75, num_events * 1.25)
        nA0 = q._oArrivals
        nD0 = q.num_departures
        q.simulate(n=k)
        ans[0] = q.num_departures + q._oArrivals - nA0 - nD0 == k

        k = np.random.randint(num_events * 0.75, num_events * 1.25)
        nA0 = q._oArrivals
        q.simulate(nA=k)
        ans[1] = q._oArrivals - nA0 == k

        k = np.random.randint(num_events * 0.75, num_events * 1.25)
        nD0 = q.num_departures
        q.simulate(nD=k)
        ans[2] = q.num_departures - nD0 == k

        t = 100 * np.random.uniform(0.5, 1)
        t0 = q.current_time
        q.simulate(t=t)
        ans[3] = q.current_time - t0 >= t

        self.assertTrue(ans.all())
예제 #11
0
"""
The following code constructs an Mt/GI/5 QueueServer with mean utilization rate ρ=0.8.
The arrivals are modeled as a Poisson random measure with rate function r(t)=2+16sin2(πt/8) 
and a service distribution that is gamma with shape and scale parameters 4 and 0.1 respectively. 
To create such a queue run:
"""

def rate(t): 
    return 2 + 16 * np.sin(np.pi * t / 8)**2
def arr(t): 
    return qt.poisson_random_measure(t, rate, 18)
def ser(t): 
    return t + np.random.gamma(4, 0.1)


q = qt.QueueServer(5, arrival_f=arr, service_f=ser)
# q.set_num_servers(10)                                   # set servers in the queue
q.set_active()
q.collect_data = True
q.simulate(n=100)
data = q.fetch_data()
print(data)

"""
A comma seperated string of the column headers. Returns 'arrival,service,departure,num_queued,num_total,q_id'
1st: The arrival time of an agent.
2nd: The service start time of an agent.
3rd: The departure time of an agent.
4th: The length of the queue upon the agents arrival.
5th: The total number of Agents in the QueueServer.
6th: The QueueServer's edge index.
예제 #12
0
    def test_QueueServer_init_errors(self):
        with self.assertRaises(TypeError):
            qt.QueueServer(num_servers=3.0)

        with self.assertRaises(ValueError):
            qt.QueueServer(num_servers=0)
예제 #13
0
 def test_QueueServer_deactivate(self):
     q = qt.QueueServer(num_servers=3, deactive_t=10)
     q.set_active()
     self.assertTrue(q.active)
     q.simulate(t=10)
     self.assertFalse(q.active)