Skip to content

Commit 7ba209d

Browse files
committed
Add notebooks for priority queues and baulking functions
1 parent eeed875 commit 7ba209d

File tree

3 files changed

+694
-0
lines changed

3 files changed

+694
-0
lines changed

Baulking Functions - I.ipynb

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Baulking Functions - I"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"### This notebook will illustrate a simple deterministic example, designed to show the difference between baulking and queueing capacities"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {
21+
"collapsed": true
22+
},
23+
"outputs": [],
24+
"source": [
25+
"import ciw"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 2,
31+
"metadata": {
32+
"collapsed": true
33+
},
34+
"outputs": [],
35+
"source": [
36+
"def my_baulking_function(n):\n",
37+
" if n < 3:\n",
38+
" return 0.0\n",
39+
" return 1.0"
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 3,
45+
"metadata": {
46+
"collapsed": true
47+
},
48+
"outputs": [],
49+
"source": [
50+
"params_dict = {\n",
51+
" 'Arrival_distributions': [['Deterministic', 5.0], ['Deterministic', 23.0]],\n",
52+
" 'Service_distributions': [['Deterministic', 21.0], ['Deterministic', 1.5]],\n",
53+
" 'Transition_matrices': [[0.0, 0.0], [1.0, 0.0]],\n",
54+
" 'Number_of_servers': [1, 1],\n",
55+
" 'Baulking_functions': [my_baulking_function, None]\n",
56+
"}"
57+
]
58+
},
59+
{
60+
"cell_type": "markdown",
61+
"metadata": {},
62+
"source": [
63+
"### Now if we run this to time t=48, we will get the following chain of events:"
64+
]
65+
},
66+
{
67+
"cell_type": "markdown",
68+
"metadata": {},
69+
"source": [
70+
"| Time | Queue Node 1 | In Service Node 1 | Queue Node 2 | In Service Node 2 | Customer Finished a Service | Baulked Customers |\n",
71+
"|------|--------------|-------------------|--------------|-------------------|-----------------------------|-------------------|\n",
72+
"| 0 | | | | | | |\n",
73+
"| 5 | | 1 | | | | |\n",
74+
"| 10 | 2 | 1 | | | | |\n",
75+
"| 15 | 3, 2 | 1 | | | | |\n",
76+
"| 20 | 3, 2 | 1 | | | | 4 |\n",
77+
"| 23 | 3, 2 | 1 | | 5 | | 4 |\n",
78+
"| 24.5 | 5, 3, 2 | 1 | | | 5 | 4 |\n",
79+
"| 25 | 5, 3, 2 | 1 | | | 5 | 4, 6 |\n",
80+
"| 26 | 5, 3 | 2 | | | 5, 1 | 4, 6 |\n",
81+
"| 30 | 5, 3 | 2 | | | 5, 1 | 4, 6, 7 |\n",
82+
"| 35 | 5, 3 | 2 | | | 5, 1 | 4, 6, 7, 8 |\n",
83+
"| 40 | 5, 3 | 2 | | | 5, 1 | 4, 6, 7, 8, 9 |\n",
84+
"| 45 | 5, 3 | 2 | | | 5, 1 | 4, 6, 7, 8, 9, 10 |\n",
85+
"| 46 | 5, 3 | 2 | | 11 | 5, 1 | 4, 6, 7, 8, 9, 10 |\n",
86+
"| 47 | 5 | 3 | | 11 | 5, 1, 2 | 4, 6, 7, 8, 9, 10 |\n",
87+
"| 47.5 | 11, 5 | 3 | | | 5, 1, 2, 11 | 4, 6, 7, 8, 9, 10 |\n",
88+
"| 48 | | | | | | |"
89+
]
90+
},
91+
{
92+
"cell_type": "markdown",
93+
"metadata": {},
94+
"source": [
95+
"### We would therefore expect the following results:"
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": 4,
101+
"metadata": {
102+
"collapsed": true
103+
},
104+
"outputs": [],
105+
"source": [
106+
"expected_baulking_dictionary = {1:{0:[20.0, 25.0, 30.0, 35.0, 40.0, 45.0]}, 2:{0:[]}}\n",
107+
"expected_ids_of_completed_customers = set([5, 1, 2, 11])\n",
108+
"expected_waits_of_completed_customers = set([0.0, 0.0, 0.0, 16])\n",
109+
"expected_arrival_dates_of_completed_customers = set([5.0, 10.0, 23.0, 46.0])\n",
110+
"expected_service_start_dates_of_completed_customers = set([5.0, 23.0, 26.0, 46.0])\n",
111+
"expected_service_end_dates_of_completed_customers = set([24.5, 26.0, 47.0, 47.5])"
112+
]
113+
},
114+
{
115+
"cell_type": "markdown",
116+
"metadata": {},
117+
"source": [
118+
"### Let's check:"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 5,
124+
"metadata": {
125+
"collapsed": false
126+
},
127+
"outputs": [],
128+
"source": [
129+
"N = ciw.create_network(params_dict)\n",
130+
"Q = ciw.Simulation(N)"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 6,
136+
"metadata": {
137+
"collapsed": true
138+
},
139+
"outputs": [],
140+
"source": [
141+
"Q.simulate_until_max_time(48)\n",
142+
"recs = Q.get_all_records()"
143+
]
144+
},
145+
{
146+
"cell_type": "code",
147+
"execution_count": 7,
148+
"metadata": {
149+
"collapsed": false
150+
},
151+
"outputs": [
152+
{
153+
"data": {
154+
"text/plain": [
155+
"True"
156+
]
157+
},
158+
"execution_count": 7,
159+
"metadata": {},
160+
"output_type": "execute_result"
161+
}
162+
],
163+
"source": [
164+
"Q.baulked_dict == expected_baulking_dictionary"
165+
]
166+
},
167+
{
168+
"cell_type": "code",
169+
"execution_count": 8,
170+
"metadata": {
171+
"collapsed": false
172+
},
173+
"outputs": [
174+
{
175+
"data": {
176+
"text/plain": [
177+
"True"
178+
]
179+
},
180+
"execution_count": 8,
181+
"metadata": {},
182+
"output_type": "execute_result"
183+
}
184+
],
185+
"source": [
186+
"set([r.id_number for r in recs]) == expected_ids_of_completed_customers"
187+
]
188+
},
189+
{
190+
"cell_type": "code",
191+
"execution_count": 9,
192+
"metadata": {
193+
"collapsed": false
194+
},
195+
"outputs": [
196+
{
197+
"data": {
198+
"text/plain": [
199+
"True"
200+
]
201+
},
202+
"execution_count": 9,
203+
"metadata": {},
204+
"output_type": "execute_result"
205+
}
206+
],
207+
"source": [
208+
"set([r.waiting_time for r in recs]) == expected_waits_of_completed_customers"
209+
]
210+
},
211+
{
212+
"cell_type": "code",
213+
"execution_count": 10,
214+
"metadata": {
215+
"collapsed": false
216+
},
217+
"outputs": [
218+
{
219+
"data": {
220+
"text/plain": [
221+
"True"
222+
]
223+
},
224+
"execution_count": 10,
225+
"metadata": {},
226+
"output_type": "execute_result"
227+
}
228+
],
229+
"source": [
230+
"set([r.arrival_date for r in recs]) == expected_arrival_dates_of_completed_customers"
231+
]
232+
},
233+
{
234+
"cell_type": "code",
235+
"execution_count": 11,
236+
"metadata": {
237+
"collapsed": false
238+
},
239+
"outputs": [
240+
{
241+
"data": {
242+
"text/plain": [
243+
"True"
244+
]
245+
},
246+
"execution_count": 11,
247+
"metadata": {},
248+
"output_type": "execute_result"
249+
}
250+
],
251+
"source": [
252+
"set([r.service_start_date for r in recs]) == expected_service_start_dates_of_completed_customers"
253+
]
254+
},
255+
{
256+
"cell_type": "code",
257+
"execution_count": 12,
258+
"metadata": {
259+
"collapsed": false
260+
},
261+
"outputs": [
262+
{
263+
"data": {
264+
"text/plain": [
265+
"True"
266+
]
267+
},
268+
"execution_count": 12,
269+
"metadata": {},
270+
"output_type": "execute_result"
271+
}
272+
],
273+
"source": [
274+
"set([r.service_end_date for r in recs]) == expected_service_end_dates_of_completed_customers"
275+
]
276+
},
277+
{
278+
"cell_type": "code",
279+
"execution_count": null,
280+
"metadata": {
281+
"collapsed": true
282+
},
283+
"outputs": [],
284+
"source": []
285+
}
286+
],
287+
"metadata": {
288+
"kernelspec": {
289+
"display_name": "Python 3",
290+
"language": "python",
291+
"name": "python3"
292+
},
293+
"language_info": {
294+
"codemirror_mode": {
295+
"name": "ipython",
296+
"version": 3
297+
},
298+
"file_extension": ".py",
299+
"mimetype": "text/x-python",
300+
"name": "python",
301+
"nbconvert_exporter": "python",
302+
"pygments_lexer": "ipython3",
303+
"version": "3.5.1"
304+
}
305+
},
306+
"nbformat": 4,
307+
"nbformat_minor": 0
308+
}

0 commit comments

Comments
 (0)