Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 546
1
2
% Default to the notebook output style
3
4
5
6
7
% Inherit from the specified cell style.
8
9
10
11
12
13
\documentclass[11pt]{article}
14
15
16
17
\usepackage[T1]{fontenc}
18
% Nicer default font (+ math font) than Computer Modern for most use cases
19
\usepackage{mathpazo}
20
21
% Basic figure setup, for now with no caption control since it's done
22
% automatically by Pandoc (which extracts ![](path) syntax from Markdown).
23
\usepackage{graphicx}
24
% We will generate all images so they have a width \maxwidth. This means
25
% that they will get their normal width if they fit onto the page, but
26
% are scaled down if they would overflow the margins.
27
\makeatletter
28
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
29
\else\Gin@nat@width\fi}
30
\makeatother
31
\let\Oldincludegraphics\includegraphics
32
% Set max figure width to be 80% of text width, for now hardcoded.
33
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=.8\maxwidth]{#1}}
34
% Ensure that by default, figures have no caption (until we provide a
35
% proper Figure object with a Caption API and a way to capture that
36
% in the conversion process - todo).
37
\usepackage{caption}
38
\DeclareCaptionLabelFormat{nolabel}{}
39
\captionsetup{labelformat=nolabel}
40
41
\usepackage{adjustbox} % Used to constrain images to a maximum size
42
\usepackage{xcolor} % Allow colors to be defined
43
\usepackage{enumerate} % Needed for markdown enumerations to work
44
\usepackage{geometry} % Used to adjust the document margins
45
\usepackage{amsmath} % Equations
46
\usepackage{amssymb} % Equations
47
\usepackage{textcomp} % defines textquotesingle
48
% Hack from http://tex.stackexchange.com/a/47451/13684:
49
\AtBeginDocument{%
50
\def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code
51
}
52
\usepackage{upquote} % Upright quotes for verbatim code
53
\usepackage{eurosym} % defines \euro
54
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
55
\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
56
\usepackage{fancyvrb} % verbatim replacement that allows latex
57
\usepackage{grffile} % extends the file name processing of package graphics
58
% to support a larger range
59
% The hyperref package gives us a pdf with properly built
60
% internal navigation ('pdf bookmarks' for the table of contents,
61
% internal cross-reference links, web links for URLs, etc.)
62
\usepackage{hyperref}
63
\usepackage{longtable} % longtable support required by pandoc >1.10
64
\usepackage{booktabs} % table support for pandoc > 1.12.2
65
\usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment)
66
\usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout)
67
% normalem makes italics be italics, not underlines
68
\usepackage{mathrsfs}
69
70
71
72
73
% Colors for the hyperref package
74
\definecolor{urlcolor}{rgb}{0,.145,.698}
75
\definecolor{linkcolor}{rgb}{.71,0.21,0.01}
76
\definecolor{citecolor}{rgb}{.12,.54,.11}
77
78
% ANSI colors
79
\definecolor{ansi-black}{HTML}{3E424D}
80
\definecolor{ansi-black-intense}{HTML}{282C36}
81
\definecolor{ansi-red}{HTML}{E75C58}
82
\definecolor{ansi-red-intense}{HTML}{B22B31}
83
\definecolor{ansi-green}{HTML}{00A250}
84
\definecolor{ansi-green-intense}{HTML}{007427}
85
\definecolor{ansi-yellow}{HTML}{DDB62B}
86
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
87
\definecolor{ansi-blue}{HTML}{208FFB}
88
\definecolor{ansi-blue-intense}{HTML}{0065CA}
89
\definecolor{ansi-magenta}{HTML}{D160C4}
90
\definecolor{ansi-magenta-intense}{HTML}{A03196}
91
\definecolor{ansi-cyan}{HTML}{60C6C8}
92
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
93
\definecolor{ansi-white}{HTML}{C5C1B4}
94
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
95
\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF}
96
\definecolor{ansi-default-inverse-bg}{HTML}{000000}
97
98
% commands and environments needed by pandoc snippets
99
% extracted from the output of `pandoc -s`
100
\providecommand{\tightlist}{%
101
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
102
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
103
% Add ',fontsize=\small' for more characters per line
104
\newenvironment{Shaded}{}{}
105
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
106
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
107
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
108
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
109
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
110
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
111
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
112
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
113
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
114
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
115
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
116
\newcommand{\RegionMarkerTok}[1]{{#1}}
117
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
118
\newcommand{\NormalTok}[1]{{#1}}
119
120
% Additional commands for more recent versions of Pandoc
121
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
122
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
123
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
124
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
125
\newcommand{\ImportTok}[1]{{#1}}
126
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
127
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
128
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
129
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
130
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
131
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
132
\newcommand{\BuiltInTok}[1]{{#1}}
133
\newcommand{\ExtensionTok}[1]{{#1}}
134
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
135
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
136
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
137
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
138
139
140
% Define a nice break command that doesn't care if a line doesn't already
141
% exist.
142
\def\br{\hspace*{\fill} \\* }
143
% Math Jax compatibility definitions
144
\def\gt{>}
145
\def\lt{<}
146
\let\Oldtex\TeX
147
\let\Oldlatex\LaTeX
148
\renewcommand{\TeX}{\textrm{\Oldtex}}
149
\renewcommand{\LaTeX}{\textrm{\Oldlatex}}
150
% Document parameters
151
% Document title
152
\title{ModSim Project 1}
153
154
155
156
157
158
159
% Pygments definitions
160
161
\makeatletter
162
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax%
163
\let\PY@ul=\relax \let\PY@tc=\relax%
164
\let\PY@bc=\relax \let\PY@ff=\relax}
165
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
166
\def\PY@toks#1+{\ifx\relax#1\empty\else%
167
\PY@tok{#1}\expandafter\PY@toks\fi}
168
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{%
169
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
170
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}
171
172
\expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
173
\expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
174
\expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
175
\expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
176
\expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
177
\expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
178
\expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
179
\expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
180
\expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
181
\expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
182
\expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
183
\expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
184
\expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
185
\expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
186
\expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
187
\expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
188
\expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
189
\expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
190
\expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
191
\expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
192
\expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
193
\expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
194
\expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
195
\expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
196
\expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
197
\expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
198
\expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
199
\expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
200
\expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
201
\expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
202
\expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
203
\expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
204
\expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
205
\expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit}
206
\expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf}
207
\expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
208
\expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
209
\expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
210
\expandafter\def\csname PY@tok@err\endcsname{\def\PY@bc##1{\setlength{\fboxsep}{0pt}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}
211
\expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
212
\expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
213
\expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
214
\expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
215
\expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
216
\expandafter\def\csname PY@tok@fm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
217
\expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
218
\expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
219
\expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
220
\expandafter\def\csname PY@tok@vm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
221
\expandafter\def\csname PY@tok@sa\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
222
\expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
223
\expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
224
\expandafter\def\csname PY@tok@dl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
225
\expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
226
\expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
227
\expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
228
\expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
229
\expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
230
\expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
231
\expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
232
\expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
233
\expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
234
\expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
235
\expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
236
\expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
237
\expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
238
\expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
239
240
\def\PYZbs{\char`\\}
241
\def\PYZus{\char`\_}
242
\def\PYZob{\char`\{}
243
\def\PYZcb{\char`\}}
244
\def\PYZca{\char`\^}
245
\def\PYZam{\char`\&}
246
\def\PYZlt{\char`\<}
247
\def\PYZgt{\char`\>}
248
\def\PYZsh{\char`\#}
249
\def\PYZpc{\char`\%}
250
\def\PYZdl{\char`\$}
251
\def\PYZhy{\char`\-}
252
\def\PYZsq{\char`\'}
253
\def\PYZdq{\char`\"}
254
\def\PYZti{\char`\~}
255
% for compatibility with earlier versions
256
\def\PYZat{@}
257
\def\PYZlb{[}
258
\def\PYZrb{]}
259
\makeatother
260
261
262
% Exact colors from NB
263
\definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
264
\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
265
266
267
268
269
% Prevent overflowing lines due to hard-to-break entities
270
\sloppy
271
% Setup hyperref package
272
\hypersetup{
273
breaklinks=true, % so long urls are correctly broken across lines
274
colorlinks=true,
275
urlcolor=urlcolor,
276
linkcolor=linkcolor,
277
citecolor=citecolor,
278
}
279
% Slightly bigger margins than the latex defaults
280
281
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
282
283
284
285
\begin{document}
286
287
288
\maketitle
289
290
291
292
293
Modeling Flight Delays
294
295
The Question
296
297
What is the best way to increase the number of flights without delays?
298
We will model airplane traffic between several airports and test two
299
different modeling strategies to avoid flight delays and maintain flight
300
turnaround efficiency.
301
302
\begin{Verbatim}[commandchars=\\\{\}]
303
{\color{incolor}In [{\color{incolor}1}]:} \PY{c+c1}{\PYZsh{} Configure Jupyter so figures appear in the notebook}
304
\PY{o}{\PYZpc{}}\PY{k}{matplotlib} inline
305
306
\PY{c+c1}{\PYZsh{} Configure Jupyter to display the assigned value after an assignment}
307
\PY{o}{\PYZpc{}}\PY{k}{config} InteractiveShell.ast\PYZus{}node\PYZus{}interactivity=\PYZsq{}last\PYZus{}expr\PYZus{}or\PYZus{}assign\PYZsq{}
308
309
\PY{c+c1}{\PYZsh{} import functions from the modsim library}
310
\PY{k+kn}{from} \PY{n+nn}{modsim} \PY{k}{import} \PY{o}{*}
311
312
\PY{c+c1}{\PYZsh{} set the random number generator}
313
\PY{n}{np}\PY{o}{.}\PY{n}{random}\PY{o}{.}\PY{n}{seed}\PY{p}{(}\PY{l+m+mi}{7}\PY{p}{)}
314
\PY{k+kn}{import} \PY{n+nn}{random}
315
316
\PY{k+kn}{import} \PY{n+nn}{pandas} \PY{k}{as} \PY{n+nn}{pd}
317
\PY{k+kn}{import} \PY{n+nn}{datetime}
318
\PY{k+kn}{from} \PY{n+nn}{dateutil}\PY{n+nn}{.}\PY{n+nn}{parser} \PY{k}{import} \PY{n}{parse}
319
\PY{k+kn}{import} \PY{n+nn}{math}
320
\PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np}
321
\end{Verbatim}
322
323
Below is data collected in 2008 which details flights and delays. This
324
data was narrowed to include only Delta (DL) and United (UA) flights
325
between airports LAX, JFK, ATL, IAD, SEA. By using only flights between
326
specific airports, we reduce the likelihood that the data is influenced
327
primarily by the airport or the airline.
328
329
\begin{Verbatim}[commandchars=\\\{\}]
330
{\color{incolor}In [{\color{incolor}2}]:} \PY{n}{trips} \PY{o}{=} \PY{n}{pd}\PY{o}{.}\PY{n}{read\PYZus{}csv}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{2008.csv}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
331
\end{Verbatim}
332
333
\begin{Verbatim}[commandchars=\\\{\}]
334
{\color{outcolor}Out[{\color{outcolor}2}]:} Year Month DayofMonth DayOfWeek DepTime ArrTime UniqueCarrier \textbackslash{}
335
0 2008 1 1 2 613.0 1407.0 UA
336
1 2008 1 2 3 615.0 1435.0 UA
337
2 2008 1 3 4 607.0 1454.0 UA
338
3 2008 1 4 5 618.0 1523.0 UA
339
4 2008 1 5 6 615.0 1416.0 UA
340
{\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots}
341
10152 2008 2 29 5 2128.0 2311.0 DL
342
10153 2008 2 29 5 1858.0 2041.0 DL
343
10154 2008 2 29 5 1455.0 1646.0 DL
344
10155 2008 2 29 5 824.0 1002.0 DL
345
10156 2008 2 29 5 957.0 1147.0 DL
346
347
ActualElapsedTime AirTime ArrDelay {\ldots} Origin Dest Distance \textbackslash{}
348
0 294.0 278.0 -24.0 {\ldots} LAX JFK 2475
349
1 320.0 298.0 4.0 {\ldots} LAX JFK 2475
350
2 347.0 299.0 23.0 {\ldots} LAX JFK 2475
351
3 365.0 284.0 52.0 {\ldots} LAX JFK 2475
352
4 301.0 282.0 -15.0 {\ldots} LAX JFK 2475
353
{\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots}
354
10152 103.0 77.0 -2.0 {\ldots} ATL IAD 533
355
10153 103.0 79.0 0.0 {\ldots} ATL IAD 533
356
10154 111.0 78.0 5.0 {\ldots} ATL IAD 533
357
10155 98.0 78.0 -5.0 {\ldots} ATL IAD 533
358
10156 110.0 82.0 -2.0 {\ldots} ATL IAD 533
359
360
TaxiIn TaxiOut CarrierDelay WeatherDelay NASDelay SecurityDelay \textbackslash{}
361
0 3.0 13.0 NaN NaN NaN NaN
362
1 3.0 19.0 NaN NaN NaN NaN
363
2 8.0 40.0 0.0 0.0 23.0 0.0
364
3 3.0 78.0 0.0 0.0 52.0 0.0
365
4 4.0 15.0 NaN NaN NaN NaN
366
{\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots}
367
10152 8.0 18.0 NaN NaN NaN NaN
368
10153 7.0 17.0 NaN NaN NaN NaN
369
10154 5.0 28.0 NaN NaN NaN NaN
370
10155 4.0 16.0 NaN NaN NaN NaN
371
10156 7.0 21.0 NaN NaN NaN NaN
372
373
LateAircraftDelay
374
0 NaN
375
1 NaN
376
2 0.0
377
3 0.0
378
4 NaN
379
{\ldots} {\ldots}
380
10152 NaN
381
10153 NaN
382
10154 NaN
383
10155 NaN
384
10156 NaN
385
386
[10157 rows x 21 columns]
387
\end{Verbatim}
388
389
The Model
390
391
To model flights and delays, we will use a state object which keeps a
392
list of planes and also keeps track of ticks with the time variable.
393
These variables are global but change throughout, so putting them in the
394
state object makes sense. To simulate the planes themselves, a Plane
395
class is created, which contains any variables for the planes and
396
several functions to update them.
397
398
Our model, obviously, is more simple than a real-life airport system. We
399
have limited our traffic to only a few airports, and a small number of
400
planes. We have also decided to focus on airport delays--effectively
401
ignoring in-flight delays due to weather, diversions, or other
402
spontaneous circumstances.
403
404
\begin{Verbatim}[commandchars=\\\{\}]
405
{\color{incolor}In [{\color{incolor}3}]:} \PY{n}{planes} \PY{o}{=} \PY{p}{[}\PY{p}{]}
406
\PY{n}{time} \PY{o}{=} \PY{l+m+mi}{0}
407
\PY{n}{state} \PY{o}{=} \PY{n}{State}\PY{p}{(}\PY{n}{planes} \PY{o}{=} \PY{n}{planes}\PY{p}{,}\PY{n}{time} \PY{o}{=} \PY{n}{time}\PY{p}{)}
408
\end{Verbatim}
409
410
\begin{Verbatim}[commandchars=\\\{\}]
411
{\color{outcolor}Out[{\color{outcolor}3}]:} planes []
412
time 0
413
dtype: object
414
\end{Verbatim}
415
416
\begin{Verbatim}[commandchars=\\\{\}]
417
{\color{incolor}In [{\color{incolor}4}]:} \PY{k}{class} \PY{n+nc}{Plane}\PY{p}{:}
418
419
\PY{k}{def} \PY{n+nf}{\PYZus{}\PYZus{}init\PYZus{}\PYZus{}}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,} \PY{n}{airline}\PY{p}{,} \PY{n}{inFlight}\PY{p}{,} \PY{n}{distance}\PY{p}{,} \PY{n}{target}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{}\PYZsh{} Initializes an instance of the Plane class}
420
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{airline} \PY{o}{=} \PY{n}{airline}
421
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{inFlight} \PY{o}{=} \PY{n}{inFlight}
422
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{=} \PY{n}{distance}
423
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target} \PY{o}{=} \PY{n}{target}
424
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{=} \PY{l+m+mi}{0}
425
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data} \PY{o}{=} \PY{p}{[}\PY{p}{]}
426
427
\PY{k}{def} \PY{n+nf}{move}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{}\PYZsh{}the plane\PYZsq{}s movement tracker, which moves the plane towards its target by one unit every tick}
428
\PY{k}{if} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{\PYZgt{}} \PY{l+m+mi}{0}\PY{p}{:}
429
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n+nb}{str}\PY{p}{(}\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance}\PY{p}{)}\PY{p}{)}
430
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{\PYZhy{}}\PY{o}{=} \PY{l+m+mi}{1}
431
\PY{k}{return} \PY{k+kc}{True}
432
\PY{k}{else}\PY{p}{:}
433
\PY{k}{return} \PY{k+kc}{False}
434
435
\PY{k}{def} \PY{n+nf}{delay}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{}\PYZsh{}the plane\PYZsq{}s delay timer at airports, which counts down tick by one second if it is at an airport}
436
\PY{k}{if} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{\PYZgt{}} \PY{l+m+mi}{0}\PY{p}{:}
437
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{l+m+mi}{0}\PY{p}{)}
438
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{\PYZhy{}}\PY{o}{=} \PY{l+m+mi}{1}
439
\PY{k}{return} \PY{k+kc}{True}
440
\PY{k}{else}\PY{p}{:}
441
\PY{k}{return} \PY{k+kc}{False}
442
443
\PY{k}{def} \PY{n+nf}{go\PYZus{}to}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,} \PY{n}{target}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{}\PYZsh{}sets a new target airport for the plane, while also calculating the distance from its current location to the target}
444
\PY{n}{temp} \PY{o}{=} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target}
445
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target} \PY{o}{=} \PY{n}{target}
446
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{=} \PY{n}{flight\PYZus{}time}\PY{p}{(}\PY{n}{temp}\PY{p}{,}\PY{n}{target}\PY{p}{)}
447
448
\PY{c+c1}{\PYZsh{}\PYZsh{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}Getters\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZsh{}\PYZsh{}}
449
\PY{k}{def} \PY{n+nf}{getAirline}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
450
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{airline}
451
\PY{k}{def} \PY{n+nf}{getInFlight}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
452
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{inFlight}
453
\PY{k}{def} \PY{n+nf}{getDistance}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
454
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance}
455
\PY{k}{def} \PY{n+nf}{getTarget}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
456
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target}
457
\PY{k}{def} \PY{n+nf}{getData}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
458
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data}
459
\PY{k}{def} \PY{n+nf}{getWait}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
460
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait}
461
462
\PY{c+c1}{\PYZsh{}\PYZsh{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}Setters\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZhy{}\PYZsh{}\PYZsh{}}
463
\PY{k}{def} \PY{n+nf}{setAirline}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{airline}\PY{p}{)}\PY{p}{:}
464
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{airline} \PY{o}{=} \PY{n}{airline}
465
\PY{k}{def} \PY{n+nf}{setInFlight}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{inFlight}\PY{p}{)}\PY{p}{:}
466
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{inFlight} \PY{o}{=} \PY{n}{inFlight}
467
\PY{k}{def} \PY{n+nf}{setDistance}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{distance}\PY{p}{)}\PY{p}{:}
468
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{=} \PY{n}{distance}
469
\PY{k}{def} \PY{n+nf}{setTarget}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{target}\PY{p}{)}\PY{p}{:}
470
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target} \PY{o}{=} \PY{n}{target}
471
\PY{k}{def} \PY{n+nf}{setWait}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,} \PY{n}{wait}\PY{p}{)}\PY{p}{:}
472
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{=} \PY{n}{wait}
473
474
\PY{k}{def} \PY{n+nf}{flight\PYZus{}time}\PY{p}{(}\PY{n}{x}\PY{p}{,} \PY{n}{y}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{}Outside the plane class, flight time calculates the time/distance in ticks between any of the 5 airports in the simulation}
475
\PY{k}{if} \PY{p}{(}\PY{n}{x} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}} \PY{o+ow}{and} \PY{n}{y} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{LAX}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{o+ow}{or} \PY{p}{(}\PY{n}{y} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}} \PY{o+ow}{and} \PY{n}{x} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{LAX}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}\PY{p}{:}
476
\PY{k}{return} \PY{l+m+mi}{51}
477
\PY{k}{elif} \PY{p}{(}\PY{n}{x} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}} \PY{o+ow}{and} \PY{n}{y} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{IAD}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{o+ow}{or} \PY{p}{(}\PY{n}{y} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}} \PY{o+ow}{and} \PY{n}{x} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{IAD}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}\PY{p}{:}
478
\PY{k}{return} \PY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dq{}} \PY{o+ow}{and} \PY{n}{y} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{SEA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{o+ow}{or} \PY{p}{(}\PY{n}{y} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{JFK}\PY{l+s+s2}{\PYZdq{}} \PY{o+ow}{and} \PY{n}{x} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{SEA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}\PY{p}{:}
494
\PY{k}{return} \PY{l+m+mi}{76}
495
\PY{k}{else}\PY{p}{:}
496
\PY{k}{return} \PY{k+kc}{False}
497
498
\PY{k}{def} \PY{n+nf}{delay\PYZus{}factor}\PY{p}{(}\PY{n}{baseNum}\PY{p}{,} \PY{n}{margin}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{}\PYZsh{}Adds an element of randomness to the delay, which can be adjusted with the base number and the amout it can deviate}
499
\PY{n}{rnd} \PY{o}{=} \PY{n}{random}\PY{o}{.}\PY{n}{randint}\PY{p}{(}\PY{l+m+mi}{1}\PY{p}{,}\PY{n}{margin}\PY{o}{*}\PY{l+m+mi}{2}\PY{p}{)}
500
\PY{k}{return} \PY{n+nb}{int}\PY{p}{(}\PY{p}{(}\PY{n}{baseNum} \PY{o}{\PYZhy{}} \PY{p}{(}\PY{n}{margin}\PY{p}{)}\PY{p}{)} \PY{o}{+} \PY{n}{rnd}\PY{p}{)}
501
\end{Verbatim}
502
503
\begin{Verbatim}[commandchars=\\\{\}]
504
{\color{incolor}In [{\color{incolor}5}]:} \PY{n}{plane1} \PY{o}{=} \PY{n}{Plane}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{UA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{k+kc}{False}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+s+s2}{\PYZ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{o}{=} \PY{n}{Plane}\PY{p}{(}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{UA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}\PY{k+kc}{False}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
515
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane1}\PY{p}{)}
516
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane2}\PY{p}{)}
517
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane3}\PY{p}{)}
518
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane4}\PY{p}{)}
519
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane5}\PY{p}{)}
520
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane6}\PY{p}{)}
521
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane7}\PY{p}{)}
522
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane8}\PY{p}{)}
523
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane9}\PY{p}{)}
524
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane10}\PY{p}{)}
525
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane11}\PY{p}{)}
526
\end{Verbatim}
527
528
For comparison we are using two different models for airlines, assuming
529
each has only 2 planes, going between 2 airports.
530
531
Delta Airlines (DL) will be using a model where 1 plane is kept in
532
reserve. Any time delta experiences a significant delay (variable
533
maxDelay), the reserve plane will be called in to replace the original,
534
instantly resetting the delay to 0.
535
536
United Airlines (UA) will be using a model where all planes are always
537
in service, flying opposite directions between the 2 airports. Since
538
there is no reserve plane, United makes turnarounds longer to maintain
539
planes and reduce the impact of delays. However, if one of their planes
540
exceeds a significant delay (variable maxDelay), the flight is
541
cancelled, and the plane must wait until the next scheduled flight.
542
Since the planes fly between two airports, this means two previously
543
scheduled flights are cancelled.
544
545
The data will be obtained in the form of a ratio, comparing the number
546
of successful flights for each airline. The variables for maximum delays
547
and turnarounds are designed to be as close to real life as possile
548
based on research. Running the simulation usually takes upwards of 2
549
minutes because of the vast quantity of data being processed. We
550
experimented with smaller time scales and numbers but this resulted in
551
very varied outputs.
552
553
\begin{Verbatim}[commandchars=\\\{\}]
554
{\color{incolor}In [{\color{incolor}6}]:} \PY{k}{def} \PY{n+nf}{run\PYZus{}simulation}\PY{p}{(}\PY{n}{numPlanes}\PY{p}{,} \PY{n}{air1}\PY{p}{,}
555
\PY{n}{air2}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{} The run\PYZus{}simulation function runs the simulation}
556
\PY{n}{state}\PY{o}{.}\PY{n}{time} \PY{o}{=} \PY{l+m+mi}{0}
557
\PY{n}{DL} \PY{o}{=} \PY{l+m+mi}{0}
558
\PY{n}{UA} \PY{o}{=} \PY{l+m+mi}{0}
559
\PY{n}{planes} \PY{o}{=} \PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{:}\PY{p}{(}\PY{p}{(}\PY{n}{numPlanes} \PY{o}{*} \PY{l+m+mi}{2}\PY{p}{)} \PY{o}{\PYZhy{}} \PY{l+m+mi}{1}\PY{p}{)}\PY{p}{]}
560
\PY{k}{for} \PY{n}{x} \PY{o+ow}{in} \PY{n+nb}{range}\PY{p}{(}\PY{l+m+mi}{100000}\PY{p}{)}\PY{p}{:}
561
\PY{n}{state}\PY{o}{.}\PY{n}{time} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1}
562
\PY{n}{DL} \PY{o}{+}\PY{o}{=} \PY{n}{sim1}\PY{p}{(}\PY{n}{planes}\PY{p}{,} \PY{n}{air1}\PY{p}{,} \PY{n}{air2}\PY{p}{,} \PY{l+m+mi}{22}\PY{p}{)}
563
\PY{n}{UA} \PY{o}{+}\PY{o}{=} \PY{n}{sim2}\PY{p}{(}\PY{n}{planes}\PY{p}{,} \PY{n}{air1}\PY{p}{,} \PY{n}{air2}\PY{p}{,} \PY{l+m+mi}{22}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{)}
564
\PY{k}{return} \PY{p}{[}\PY{n}{DL}\PY{p}{,} \PY{n}{UA}\PY{p}{,} \PY{n}{DL} \PY{o}{/} \PY{n}{UA}\PY{p}{]}
565
566
567
\PY{k}{def} \PY{n+nf}{sim1}\PY{p}{(}\PY{n}{planes}\PY{p}{,} \PY{n}{air1}\PY{p}{,} \PY{n}{air2}\PY{p}{,}
568
\PY{n}{maxDelay}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{} Sim1 implements Delta\PYZsq{}s reserve plane model}
569
\PY{n}{success} \PY{o}{=} \PY{l+m+mi}{0}
570
\PY{k}{for} \PY{n}{plane} \PY{o+ow}{in} \PY{n}{planes}\PY{p}{:}
571
\PY{k}{if} \PY{n}{plane}\PY{o}{.}\PY{n}{getAirline}\PY{p}{(}\PY{p}{)} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{DL}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:}
572
\PY{k}{if} \PY{o+ow}{not} \PY{p}{(}\PY{n}{plane}\PY{o}{.}\PY{n}{delay}\PY{p}{(}\PY{p}{)}\PY{p}{)}\PY{p}{:}
573
\PY{k}{if} \PY{n}{plane}\PY{o}{.}\PY{n}{getWait}\PY{p}{(}\PY{p}{)} \PY{o}{\PYZgt{}} \PY{n}{maxDelay}\PY{p}{:}
574
\PY{n}{plane}\PY{o}{.}\PY{n}{setWait}\PY{p}{(}\PY{l+m+mi}{0}\PY{p}{)}
575
\PY{k}{if} \PY{o+ow}{not} \PY{p}{(}\PY{n}{plane}\PY{o}{.}\PY{n}{move}\PY{p}{(}\PY{p}{)}\PY{p}{)}\PY{p}{:}
576
\PY{n}{success} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1}
577
\PY{k}{if} \PY{p}{(}\PY{n}{plane}\PY{o}{.}\PY{n}{getTarget}\PY{p}{(}\PY{p}{)} \PY{o}{==} \PY{n}{air1}\PY{p}{)}\PY{p}{:}
578
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air2}\PY{p}{)}
579
\PY{k}{else}\PY{p}{:}
580
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air1}\PY{p}{)}
581
\PY{n}{plane}\PY{o}{.}\PY{n}{setWait}\PY{p}{(}\PY{n}{delay\PYZus{}factor}\PY{p}{(}\PY{l+m+mi}{15}\PY{p}{,} \PY{l+m+mi}{9}\PY{p}{)}\PY{p}{)}
582
\PY{k}{return} \PY{n}{success}
583
584
585
\PY{k}{def} \PY{n+nf}{sim2}\PY{p}{(}\PY{n}{planes}\PY{p}{,} \PY{n}{air1}\PY{p}{,} \PY{n}{air2}\PY{p}{,} \PY{n}{maxDelay}\PY{p}{,}
586
\PY{n}{addTurn}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{} Sim2 implements United\PYZsq{}s model}
587
\PY{n}{success} \PY{o}{=} \PY{l+m+mi}{0} \PY{c+c1}{\PYZsh{} that operates without reserve planes}
588
\PY{k}{for} \PY{n}{plane} \PY{o+ow}{in} \PY{n}{planes}\PY{p}{:}
589
\PY{k}{if} \PY{n}{plane}\PY{o}{.}\PY{n}{getAirline}\PY{p}{(}\PY{p}{)} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{UA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{:}
590
\PY{k}{if} \PY{o+ow}{not} \PY{p}{(}\PY{n}{plane}\PY{o}{.}\PY{n}{delay}\PY{p}{(}\PY{p}{)}\PY{p}{)}\PY{p}{:}
591
\PY{k}{if} \PY{o+ow}{not} \PY{p}{(}\PY{n}{plane}\PY{o}{.}\PY{n}{move}\PY{p}{(}\PY{p}{)}\PY{p}{)}\PY{p}{:}
592
\PY{n}{success} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1}
593
\PY{k}{if} \PY{p}{(}\PY{n}{plane}\PY{o}{.}\PY{n}{getTarget}\PY{p}{(}\PY{p}{)} \PY{o}{==} \PY{n}{air1}\PY{p}{)}\PY{p}{:}
594
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air2}\PY{p}{)}
595
\PY{k}{else}\PY{p}{:}
596
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air1}\PY{p}{)}
597
\PY{n}{delay} \PY{o}{=} \PY{n}{delay\PYZus{}factor}\PY{p}{(}\PY{l+m+mi}{15}\PY{p}{,} \PY{l+m+mi}{9}\PY{p}{)}
598
\PY{n}{plane}\PY{o}{.}\PY{n}{setWait}\PY{p}{(}\PY{n}{delay} \PY{o}{+} \PY{n}{addTurn}\PY{p}{)}
599
\PY{k}{if} \PY{n}{delay} \PY{o}{\PYZgt{}} \PY{n}{maxDelay}\PY{p}{:}
600
\PY{n}{success} \PY{o}{\PYZhy{}}\PY{o}{=} \PY{l+m+mi}{2}
601
\PY{k}{return} \PY{n}{success}
602
603
604
\PY{n}{test1} \PY{o}{=} \PY{n}{run\PYZus{}simulation}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{IAD}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}
605
\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{JFK}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{c+c1}{\PYZsh{} This section collects data from run\PYZus{}simulation}
606
\PY{n}{test2} \PY{o}{=} \PY{n}{run\PYZus{}simulation}\PY{p}{(}
607
\PY{l+m+mi}{2}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{LAX}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)} \PY{c+c1}{\PYZsh{} and creates lists to store all the different datasets}
608
\PY{n}{test3} \PY{o}{=} \PY{n}{run\PYZus{}simulation}\PY{p}{(}\PY{l+m+mi}{2}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{JFK}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{SEA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
609
\PY{n}{test4} \PY{o}{=} \PY{n}{run\PYZus{}simulation}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{IAD}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{JFK}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
610
\PY{n}{test5} \PY{o}{=} \PY{n}{run\PYZus{}simulation}\PY{p}{(}\PY{l+m+mi}{3}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{LAX}\PY{l+s+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Y{l+s+s2}{SEA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
621
622
\PY{n}{tests} \PY{o}{=} \PY{p}{[}
623
\PY{n}{test1}\PY{p}{,} \PY{n}{test2}\PY{p}{,} \PY{n}{test3}\PY{p}{,} \PY{n}{test4}\PY{p}{,} \PY{n}{test5}\PY{p}{,} \PY{n}{test6}\PY{p}{,} \PY{n}{test7}\PY{p}{,} \PY{n}{test8}\PY{p}{,} \PY{n}{test9}\PY{p}{,} \PY{n}{test10}\PY{p}{,}
624
\PY{n}{test11}\PY{p}{,} \PY{n}{test12}\PY{p}{,} \PY{n}{test13}\PY{p}{,} \PY{n}{test14}\PY{p}{,} \PY{n}{test15}
625
\PY{p}{]}
626
627
\PY{n}{DL\PYZus{}Flights} \PY{o}{=} \PY{p}{[}\PY{p}{]}
628
\PY{k}{for} \PY{n}{test} \PY{o+ow}{in} \PY{n}{tests}\PY{p}{:}
629
\PY{n}{DL\PYZus{}Flights}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{test}\PY{p}{[}\PY{l+m+mi}{0}\PY{p}{]}\PY{p}{)}
630
631
\PY{n}{UA\PYZus{}Flights} \PY{o}{=} \PY{p}{[}\PY{p}{]}
632
\PY{k}{for} \PY{n}{test} \PY{o+ow}{in} \PY{n}{tests}\PY{p}{:}
633
\PY{n}{UA\PYZus{}Flights}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{test}\PY{p}{[}\PY{l+m+mi}{1}\PY{p}{]}\PY{p}{)}
634
635
\PY{n}{ratio} \PY{o}{=} \PY{p}{[}\PY{p}{]}
636
\PY{k}{for} \PY{n}{test} \PY{o+ow}{in} \PY{n}{tests}\PY{p}{:}
637
\PY{n}{ratio}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{test}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{)}
638
639
\PY{n}{num\PYZus{}planes} \PY{o}{=} \PY{p}{[}\PY{l+m+mi}{2}\PY{p}{,} \PY{l+m+mi}{2}\PY{p}{,} \PY{l+m+mi}{2}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{4}\PY{p}{,} \PY{l+m+mi}{4}\PY{p}{,} \PY{l+m+mi}{4}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{6}\PY{p}{,} \PY{l+m+mi}{6}\PY{p}{,} \PY{l+m+mi}{6}\PY{p}{]}
640
\PY{n}{flight\PYZus{}length} \PY{o}{=} \PY{p}{[}\PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{,} \PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{3}\PY{p}{,} \PY{l+m+mi}{5}\PY{p}{]}
641
\end{Verbatim}
642
643
\begin{Verbatim}[commandchars=\\\{\}]
644
{\color{outcolor}Out[{\color{outcolor}6}]:} [1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5]
645
\end{Verbatim}
646
647
The Results
648
649
The ratios of Delta's successful flights versus United's succesful
650
flights are shown below. For each flight path, there are four
651
ratios--each representing a test with a different number of planes. For
652
reference, the flight paths are in order of shortest time to longest.
653
654
\begin{Verbatim}[commandchars=\\\{\}]
655
{\color{incolor}In [{\color{incolor}7}]:} \PY{n+nb}{print}\PY{p}{(}\PY{n}{ratio}\PY{p}{)}
656
\end{Verbatim}
657
658
\begin{Verbatim}[commandchars=\\\{\}]
659
[0.749, 0.6914498141263941, 0.6605504587155964, 0.986452998513134, 0.9151234567901234, 0.8929752066115703, 1.1055034550839091, 1.0265650265650266, 1.0106051154086089, 1.1862637908756586, 1.0993880956795847, 1.1006625891946993, 1.2303370786516854, 1.1479473276529821, 1.1163366336633664]
660
661
\end{Verbatim}
662
663
\begin{Verbatim}[commandchars=\\\{\}]
664
{\color{incolor}In [{\color{incolor}8}]:} \PY{c+c1}{\PYZsh{} Creates a bubble plot to plot the ratio of successful flights}
665
\PY{n}{data} \PY{o}{=} \PY{p}{\PYZob{}}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{a}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{n}{num\PYZus{}planes}\PY{p}{,}
666
\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{c}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{blue}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}
667
\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{p}{(}\PY{n}{flight\PYZus{}length}\PY{p}{)}\PY{p}{\PYZcb{}}
668
\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{b}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]} \PY{o}{=} \PY{n}{ratio}
669
\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{abs}\PY{p}{(}\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{p}{)} \PY{o}{*} \PY{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}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Plot 1: Ratios of Successful Flights v Number of Planes}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
676
\PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)}
677
\end{Verbatim}
678
\texttt{\color{outcolor}Out[{\color{outcolor}8}]:}
679
680
\begin{center}
681
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{ModSim Project 1_files/ModSim Project 1_13_0.png}
682
\end{center}
683
{ \hspace*{\fill} \\}
684
685
686
This graph shows the ratio of successful flights from United to those of
687
Delta. The higher the ratio, the more successful Delta is. The line at y
688
= 1 represents the point at which Delta begins having more successful
689
flights than United. The size of each bubble represents the length of
690
the flight.
691
692
\begin{Verbatim}[commandchars=\\\{\}]
693
{\color{incolor}In [{\color{incolor}9}]:} \PY{c+c1}{\PYZsh{} Creates a bubble plot to plot the number of successful flights for each airline}
694
\PY{n}{data} \PY{o}{=} \PY{p}{\PYZob{}}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{a}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{n}{num\PYZus{}planes}\PY{p}{,}
695
\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{c}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{maroon}\PY{l+s+s2}{\PYZdq{}}\PY{p}{,}
696
\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{:} \PY{n}{flight\PYZus{}length}\PY{p}{\PYZcb{}}
697
\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{b}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]} \PY{o}{=} \PY{n}{DL\PYZus{}Flights}
698
\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+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Y{n}{UA\PYZus{}Flights}
706
\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]} \PY{o}{=} \PY{n}{np}\PY{o}{.}\PY{n}{abs}\PY{p}{(}\PY{n}{data}\PY{p}{[}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{]}\PY{p}{)} \PY{o}{*} \PY{l+m+mi}{20}
707
708
\PY{n}{plt}\PY{o}{.}\PY{n}{scatter}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{a}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{b}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{n}{c}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{c}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{n}{s}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{d}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{n}{data}\PY{o}{=}\PY{n}{data}\PY{p}{)}
709
710
\PY{n}{plt}\PY{o}{.}\PY{n}{xlabel}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Number of Planes}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
711
\PY{n}{plt}\PY{o}{.}\PY{n}{ylabel}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Number of Successful Flights}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
712
\PY{n}{plt}\PY{o}{.}\PY{n}{title}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Plot 2: Number of Successful Flights v Number of Planes}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
713
\PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)}
714
\end{Verbatim}
715
\texttt{\color{outcolor}Out[{\color{outcolor}9}]:}
716
717
\begin{center}
718
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{ModSim Project 1_files/ModSim Project 1_15_0.png}
719
\end{center}
720
{ \hspace*{\fill} \\}
721
722
723
This graph shows the individual number of flights from United (blue) and
724
Delta (red) that are successful. The size of each bubble represents the
725
length of the flights.
726
727
The Interpretation
728
729
The data in these two plots shows most clearly that given a certain time
730
period, more shorter flights can be completed than longer ones. This is
731
no surprise, and more interesting is the ratios of United flights to
732
Delta flights. With less planes, it is clear that United's model of
733
using all of its planes works well, even if they have a slightly longer
734
turnaround. However, as the airlines' fleets grow, Delta gains the
735
advantage. This can best be explained by the fact that Delta constantly
736
has 1 reserve plane, and so the ratio of reserve planes:in service
737
planes decreases, while the advantage of having a reserve plane doesn't.
738
739
Plot 1 shows the ratio increasing throughout (shifting towards Delta's
740
side) but levelling off near the end. This could imply that Delta's
741
strategy works better with more planes, but only up to a point, after
742
which it is still beneficial, but stops improving relative to United.
743
744
Plot 2 shows a very significant change in the number of successful short
745
flights, and a smaller change in the longer flights. This can be
746
attributed to the fact that there are more shorter flights so any
747
imbalances will compound much faster. However, it should also be noted
748
that Delta's method definitely seems more effective with shorter
749
flights. This can be seen in both plots, as in plot 1, the shorter
750
flights (smaller bubbles) have a much larger ratio, and in the second
751
plot, delta's short flights exceed those of United earlier than the long
752
flights.
753
754
In conclusion, United's model tends to be better suited to longer
755
flights and fewer planes, while the opposite is true for Delta.
756
757
758
% Add a bibliography block to the postdoc
759
760
761
762
\end{document}
763
764