\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathpazo}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=.8\maxwidth]{#1}}
\usepackage{caption}
\DeclareCaptionLabelFormat{nolabel}{}
\captionsetup{labelformat=nolabel}
\usepackage{adjustbox}
\usepackage{xcolor}
\usepackage{enumerate}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{textcomp}
\AtBeginDocument{
\def\PYZsq{\textquotesingle}
}
\usepackage{upquote}
\usepackage{eurosym}
\usepackage[mathletters]{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{fancyvrb}
\usepackage{grffile}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage[inline]{enumitem}
\usepackage[normalem]{ulem}
\usepackage{mathrsfs}
\definecolor{urlcolor}{rgb}{0,.145,.698}
\definecolor{linkcolor}{rgb}{.71,0.21,0.01}
\definecolor{citecolor}{rgb}{.12,.54,.11}
\definecolor{ansi-black}{HTML}{3E424D}
\definecolor{ansi-black-intense}{HTML}{282C36}
\definecolor{ansi-red}{HTML}{E75C58}
\definecolor{ansi-red-intense}{HTML}{B22B31}
\definecolor{ansi-green}{HTML}{00A250}
\definecolor{ansi-green-intense}{HTML}{007427}
\definecolor{ansi-yellow}{HTML}{DDB62B}
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
\definecolor{ansi-blue}{HTML}{208FFB}
\definecolor{ansi-blue-intense}{HTML}{0065CA}
\definecolor{ansi-magenta}{HTML}{D160C4}
\definecolor{ansi-magenta-intense}{HTML}{A03196}
\definecolor{ansi-cyan}{HTML}{60C6C8}
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
\definecolor{ansi-white}{HTML}{C5C1B4}
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF}
\definecolor{ansi-default-inverse-bg}{HTML}{000000}
\providecommand{\tightlist}{
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
\newcommand{\ImportTok}[1]{{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
\newcommand{\BuiltInTok}[1]{{#1}}
\newcommand{\ExtensionTok}[1]{{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\def\br{\hspace*{\fill} \\* }
\def\gt{>}
\def\lt{<}
\let\Oldtex\TeX
\let\Oldlatex\LaTeX
\renewcommand{\TeX}{\textrm{\Oldtex}}
\renewcommand{\LaTeX}{\textrm{\Oldlatex}}
\title{ModSim Project 1}
\makeatletter
\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax
\let\PY@ul=\relax \let\PY@tc=\relax
\let\PY@bc=\relax \let\PY@ff=\relax}
\def\PY@tok#1{\csname PY@tok@#1\endcsname}
\def\PY@toks#1+{\ifx\relax#1\empty\else
\PY@tok{#1}\expandafter\PY@toks\fi}
\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{
\PY@it{\PY@bf{\PY@ff{#1}}}}}}}
\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}}
\expandafter\def\csname PY@tok@w\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}}
\expandafter\def\csname PY@tok@c\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@cp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.74,0.48,0.00}{##1}}}
\expandafter\def\csname PY@tok@k\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@kp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@kt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}}
\expandafter\def\csname PY@tok@o\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@ow\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\expandafter\def\csname PY@tok@nb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@nf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@nc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@nn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@ne\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.82,0.25,0.23}{##1}}}
\expandafter\def\csname PY@tok@nv\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@no\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@nl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.63,0.00}{##1}}}
\expandafter\def\csname PY@tok@ni\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.60,0.60,0.60}{##1}}}
\expandafter\def\csname PY@tok@na\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.49,0.56,0.16}{##1}}}
\expandafter\def\csname PY@tok@nt\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@nd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}}
\expandafter\def\csname PY@tok@s\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@sd\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@si\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\expandafter\def\csname PY@tok@se\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.13}{##1}}}
\expandafter\def\csname PY@tok@sr\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.40,0.53}{##1}}}
\expandafter\def\csname PY@tok@ss\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@sx\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@m\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@gh\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@gu\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@gd\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@gi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.63,0.00}{##1}}}
\expandafter\def\csname PY@tok@gr\endcsname{\def\PY@tc##1{\textcolor[rgb]{1.00,0.00,0.00}{##1}}}
\expandafter\def\csname PY@tok@ge\endcsname{\let\PY@it=\textit}
\expandafter\def\csname PY@tok@gs\endcsname{\let\PY@bf=\textbf}
\expandafter\def\csname PY@tok@gp\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}}
\expandafter\def\csname PY@tok@go\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.53,0.53,0.53}{##1}}}
\expandafter\def\csname PY@tok@gt\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}}
\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}}}
\expandafter\def\csname PY@tok@kc\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@kd\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@kn\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@kr\endcsname{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@bp\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}}
\expandafter\def\csname PY@tok@fm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}}
\expandafter\def\csname PY@tok@vc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@vg\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@vi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@vm\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}}
\expandafter\def\csname PY@tok@sa\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@sb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@sc\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@dl\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@s2\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@sh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@s1\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}}
\expandafter\def\csname PY@tok@mb\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@mf\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@mh\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@mi\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@il\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@mo\endcsname{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}}
\expandafter\def\csname PY@tok@ch\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@cm\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@cpf\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@c1\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\expandafter\def\csname PY@tok@cs\endcsname{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.25,0.50,0.50}{##1}}}
\def\PYZbs{\char`\\}
\def\PYZus{\char`\_}
\def\PYZob{\char`\{}
\def\PYZcb{\char`\}}
\def\PYZca{\char`\^}
\def\PYZam{\char`\&}
\def\PYZlt{\char`\<}
\def\PYZgt{\char`\>}
\def\PYZsh{\char`\#}
\def\PYZpc{\char`\%}
\def\PYZdl{\char`\$}
\def\PYZhy{\char`\-}
\def\PYZsq{\char`\'}
\def\PYZdq{\char`\"}
\def\PYZti{\char`\~}
\def\PYZat{@}
\def\PYZlb{[}
\def\PYZrb{]}
\makeatother
\definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
\definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
\sloppy
\hypersetup{
breaklinks=true,
colorlinks=true,
urlcolor=urlcolor,
linkcolor=linkcolor,
citecolor=citecolor,
}
\geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in}
\begin{document}
\maketitle
Modeling Flight Delays
The Question
What is the best way to increase the number of flights without delays?
We will model airplane traffic between several airports and test two
different modeling strategies to avoid flight delays and maintain flight
turnaround efficiency.
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}1}]:} \PY{c+c1}{\PYZsh{} Configure Jupyter so figures appear in the notebook}
\PY{o}{\PYZpc{}}\PY{k}{matplotlib} inline
\PY{c+c1}{\PYZsh{} Configure Jupyter to display the assigned value after an assignment}
\PY{o}{\PYZpc{}}\PY{k}{config} InteractiveShell.ast\PYZus{}node\PYZus{}interactivity=\PYZsq{}last\PYZus{}expr\PYZus{}or\PYZus{}assign\PYZsq{}
\PY{c+c1}{\PYZsh{} import functions from the modsim library}
\PY{k+kn}{from} \PY{n+nn}{modsim} \PY{k}{import} \PY{o}{*}
\PY{c+c1}{\PYZsh{} set the random number generator}
\PY{n}{np}\PY{o}{.}\PY{n}{random}\PY{o}{.}\PY{n}{seed}\PY{p}{(}\PY{l+m+mi}{7}\PY{p}{)}
\PY{k+kn}{import} \PY{n+nn}{random}
\PY{k+kn}{import} \PY{n+nn}{pandas} \PY{k}{as} \PY{n+nn}{pd}
\PY{k+kn}{import} \PY{n+nn}{datetime}
\PY{k+kn}{from} \PY{n+nn}{dateutil}\PY{n+nn}{.}\PY{n+nn}{parser} \PY{k}{import} \PY{n}{parse}
\PY{k+kn}{import} \PY{n+nn}{math}
\PY{k+kn}{import} \PY{n+nn}{numpy} \PY{k}{as} \PY{n+nn}{np}
\end{Verbatim}
Below is data collected in 2008 which details flights and delays. This
data was narrowed to include only Delta (DL) and United (UA) flights
between airports LAX, JFK, ATL, IAD, SEA. By using only flights between
specific airports, we reduce the likelihood that the data is influenced
primarily by the airport or the airline.
\begin{Verbatim}[commandchars=\\\{\}]
{\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}{)}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
{\color{outcolor}Out[{\color{outcolor}2}]:} Year Month DayofMonth DayOfWeek DepTime ArrTime UniqueCarrier \textbackslash{}
0 2008 1 1 2 613.0 1407.0 UA
1 2008 1 2 3 615.0 1435.0 UA
2 2008 1 3 4 607.0 1454.0 UA
3 2008 1 4 5 618.0 1523.0 UA
4 2008 1 5 6 615.0 1416.0 UA
{\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots}
10152 2008 2 29 5 2128.0 2311.0 DL
10153 2008 2 29 5 1858.0 2041.0 DL
10154 2008 2 29 5 1455.0 1646.0 DL
10155 2008 2 29 5 824.0 1002.0 DL
10156 2008 2 29 5 957.0 1147.0 DL
ActualElapsedTime AirTime ArrDelay {\ldots} Origin Dest Distance \textbackslash{}
0 294.0 278.0 -24.0 {\ldots} LAX JFK 2475
1 320.0 298.0 4.0 {\ldots} LAX JFK 2475
2 347.0 299.0 23.0 {\ldots} LAX JFK 2475
3 365.0 284.0 52.0 {\ldots} LAX JFK 2475
4 301.0 282.0 -15.0 {\ldots} LAX JFK 2475
{\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots}
10152 103.0 77.0 -2.0 {\ldots} ATL IAD 533
10153 103.0 79.0 0.0 {\ldots} ATL IAD 533
10154 111.0 78.0 5.0 {\ldots} ATL IAD 533
10155 98.0 78.0 -5.0 {\ldots} ATL IAD 533
10156 110.0 82.0 -2.0 {\ldots} ATL IAD 533
TaxiIn TaxiOut CarrierDelay WeatherDelay NASDelay SecurityDelay \textbackslash{}
0 3.0 13.0 NaN NaN NaN NaN
1 3.0 19.0 NaN NaN NaN NaN
2 8.0 40.0 0.0 0.0 23.0 0.0
3 3.0 78.0 0.0 0.0 52.0 0.0
4 4.0 15.0 NaN NaN NaN NaN
{\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots} {\ldots}
10152 8.0 18.0 NaN NaN NaN NaN
10153 7.0 17.0 NaN NaN NaN NaN
10154 5.0 28.0 NaN NaN NaN NaN
10155 4.0 16.0 NaN NaN NaN NaN
10156 7.0 21.0 NaN NaN NaN NaN
LateAircraftDelay
0 NaN
1 NaN
2 0.0
3 0.0
4 NaN
{\ldots} {\ldots}
10152 NaN
10153 NaN
10154 NaN
10155 NaN
10156 NaN
[10157 rows x 21 columns]
\end{Verbatim}
The Model
To model flights and delays, we will use a state object which keeps a
list of planes and also keeps track of ticks with the time variable.
These variables are global but change throughout, so putting them in the
state object makes sense. To simulate the planes themselves, a Plane
class is created, which contains any variables for the planes and
several functions to update them.
Our model, obviously, is more simple than a real-life airport system. We
have limited our traffic to only a few airports, and a small number of
planes. We have also decided to focus on airport delays--effectively
ignoring in-flight delays due to weather, diversions, or other
spontaneous circumstances.
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}3}]:} \PY{n}{planes} \PY{o}{=} \PY{p}{[}\PY{p}{]}
\PY{n}{time} \PY{o}{=} \PY{l+m+mi}{0}
\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}{)}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
{\color{outcolor}Out[{\color{outcolor}3}]:} planes []
time 0
dtype: object
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}4}]:} \PY{k}{class} \PY{n+nc}{Plane}\PY{p}{:}
\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}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{airline} \PY{o}{=} \PY{n}{airline}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{inFlight} \PY{o}{=} \PY{n}{inFlight}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{=} \PY{n}{distance}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target} \PY{o}{=} \PY{n}{target}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{=} \PY{l+m+mi}{0}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data} \PY{o}{=} \PY{p}{[}\PY{p}{]}
\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}
\PY{k}{if} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{\PYZgt{}} \PY{l+m+mi}{0}\PY{p}{:}
\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}{)}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{\PYZhy{}}\PY{o}{=} \PY{l+m+mi}{1}
\PY{k}{return} \PY{k+kc}{True}
\PY{k}{else}\PY{p}{:}
\PY{k}{return} \PY{k+kc}{False}
\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}
\PY{k}{if} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{\PYZgt{}} \PY{l+m+mi}{0}\PY{p}{:}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{l+m+mi}{0}\PY{p}{)}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{\PYZhy{}}\PY{o}{=} \PY{l+m+mi}{1}
\PY{k}{return} \PY{k+kc}{True}
\PY{k}{else}\PY{p}{:}
\PY{k}{return} \PY{k+kc}{False}
\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}
\PY{n}{temp} \PY{o}{=} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target} \PY{o}{=} \PY{n}{target}
\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}{)}
\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{}}
\PY{k}{def} \PY{n+nf}{getAirline}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{airline}
\PY{k}{def} \PY{n+nf}{getInFlight}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{inFlight}
\PY{k}{def} \PY{n+nf}{getDistance}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance}
\PY{k}{def} \PY{n+nf}{getTarget}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target}
\PY{k}{def} \PY{n+nf}{getData}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{data}
\PY{k}{def} \PY{n+nf}{getWait}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait}
\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{}}
\PY{k}{def} \PY{n+nf}{setAirline}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{airline}\PY{p}{)}\PY{p}{:}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{airline} \PY{o}{=} \PY{n}{airline}
\PY{k}{def} \PY{n+nf}{setInFlight}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{inFlight}\PY{p}{)}\PY{p}{:}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{inFlight} \PY{o}{=} \PY{n}{inFlight}
\PY{k}{def} \PY{n+nf}{setDistance}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{distance}\PY{p}{)}\PY{p}{:}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{distance} \PY{o}{=} \PY{n}{distance}
\PY{k}{def} \PY{n+nf}{setTarget}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,}\PY{n}{target}\PY{p}{)}\PY{p}{:}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{target} \PY{o}{=} \PY{n}{target}
\PY{k}{def} \PY{n+nf}{setWait}\PY{p}{(}\PY{n+nb+bp}{self}\PY{p}{,} \PY{n}{wait}\PY{p}{)}\PY{p}{:}
\PY{n+nb+bp}{self}\PY{o}{.}\PY{n}{wait} \PY{o}{=} \PY{n}{wait}
\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}
\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}{:}
\PY{k}{return} \PY{l+m+mi}{51}
\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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}\PY{l+s+s2}{SEA}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}\PY{p}{:}
\PY{k}{return} \PY{l+m+mi}{70}
\PY{k}{elif} \PY{p}{(}\PY{n}{x} \PY{o}{==} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{JFK}\PY{l+s+s2}{\PYZdq{}} \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}{:}
\PY{k}{return} \PY{l+m+mi}{76}
\PY{k}{else}\PY{p}{:}
\PY{k}{return} \PY{k+kc}{False}
\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}
\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}{)}
\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}{)}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}5}]:} \PY{n}{plane1} \PY{o}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{,}\PY{k+kc}{False}\PY{p}{,}\PY{l+m+mi}{0}\PY{p}{,}\PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{LAX}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
\PY{n}{plane11} \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}{\PYZdq{}}\PY{l+s+s2}{ATL}\PY{l+s+s2}{\PYZdq{}}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane1}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane2}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane3}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane4}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane5}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane6}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane7}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane8}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane9}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane10}\PY{p}{)}
\PY{n}{state}\PY{o}{.}\PY{n}{planes}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{plane11}\PY{p}{)}
\end{Verbatim}
For comparison we are using two different models for airlines, assuming
each has only 2 planes, going between 2 airports.
Delta Airlines (DL) will be using a model where 1 plane is kept in
reserve. Any time delta experiences a significant delay (variable
maxDelay), the reserve plane will be called in to replace the original,
instantly resetting the delay to 0.
United Airlines (UA) will be using a model where all planes are always
in service, flying opposite directions between the 2 airports. Since
there is no reserve plane, United makes turnarounds longer to maintain
planes and reduce the impact of delays. However, if one of their planes
exceeds a significant delay (variable maxDelay), the flight is
cancelled, and the plane must wait until the next scheduled flight.
Since the planes fly between two airports, this means two previously
scheduled flights are cancelled.
The data will be obtained in the form of a ratio, comparing the number
of successful flights for each airline. The variables for maximum delays
and turnarounds are designed to be as close to real life as possile
based on research. Running the simulation usually takes upwards of 2
minutes because of the vast quantity of data being processed. We
experimented with smaller time scales and numbers but this resulted in
very varied outputs.
\begin{Verbatim}[commandchars=\\\{\}]
{\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}{,}
\PY{n}{air2}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{} The run\PYZus{}simulation function runs the simulation}
\PY{n}{state}\PY{o}{.}\PY{n}{time} \PY{o}{=} \PY{l+m+mi}{0}
\PY{n}{DL} \PY{o}{=} \PY{l+m+mi}{0}
\PY{n}{UA} \PY{o}{=} \PY{l+m+mi}{0}
\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}{]}
\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}{:}
\PY{n}{state}\PY{o}{.}\PY{n}{time} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1}
\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}{)}
\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}{)}
\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}{]}
\PY{k}{def} \PY{n+nf}{sim1}\PY{p}{(}\PY{n}{planes}\PY{p}{,} \PY{n}{air1}\PY{p}{,} \PY{n}{air2}\PY{p}{,}
\PY{n}{maxDelay}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{} Sim1 implements Delta\PYZsq{}s reserve plane model}
\PY{n}{success} \PY{o}{=} \PY{l+m+mi}{0}
\PY{k}{for} \PY{n}{plane} \PY{o+ow}{in} \PY{n}{planes}\PY{p}{:}
\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}{:}
\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}{:}
\PY{k}{if} \PY{n}{plane}\PY{o}{.}\PY{n}{getWait}\PY{p}{(}\PY{p}{)} \PY{o}{\PYZgt{}} \PY{n}{maxDelay}\PY{p}{:}
\PY{n}{plane}\PY{o}{.}\PY{n}{setWait}\PY{p}{(}\PY{l+m+mi}{0}\PY{p}{)}
\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}{:}
\PY{n}{success} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1}
\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}{:}
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air2}\PY{p}{)}
\PY{k}{else}\PY{p}{:}
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air1}\PY{p}{)}
\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}{)}
\PY{k}{return} \PY{n}{success}
\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}{,}
\PY{n}{addTurn}\PY{p}{)}\PY{p}{:} \PY{c+c1}{\PYZsh{} Sim2 implements United\PYZsq{}s model}
\PY{n}{success} \PY{o}{=} \PY{l+m+mi}{0} \PY{c+c1}{\PYZsh{} that operates without reserve planes}
\PY{k}{for} \PY{n}{plane} \PY{o+ow}{in} \PY{n}{planes}\PY{p}{:}
\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}{:}
\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}{:}
\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}{:}
\PY{n}{success} \PY{o}{+}\PY{o}{=} \PY{l+m+mi}{1}
\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}{:}
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air2}\PY{p}{)}
\PY{k}{else}\PY{p}{:}
\PY{n}{plane}\PY{o}{.}\PY{n}{go\PYZus{}to}\PY{p}{(}\PY{n}{air1}\PY{p}{)}
\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}{)}
\PY{n}{plane}\PY{o}{.}\PY{n}{setWait}\PY{p}{(}\PY{n}{delay} \PY{o}{+} \PY{n}{addTurn}\PY{p}{)}
\PY{k}{if} \PY{n}{delay} \PY{o}{\PYZgt{}} \PY{n}{maxDelay}\PY{p}{:}
\PY{n}{success} \PY{o}{\PYZhy{}}\PY{o}{=} \PY{l+m+mi}{2}
\PY{k}{return} \PY{n}{success}
\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}{,}
\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}
\PY{n}{test2} \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}{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}
\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}{)}
\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}{)}
\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+s2}{\PYZdq{}}\PY{p}{)}
\PY{n}{test6} \PY{o}{=} \PY{n}{run\PYZus{}simulation}\P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}\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}{,}
\PY{n}{test11}\PY{p}{,} \PY{n}{test12}\PY{p}{,} \PY{n}{test13}\PY{p}{,} \PY{n}{test14}\PY{p}{,} \PY{n}{test15}
\PY{p}{]}
\PY{n}{DL\PYZus{}Flights} \PY{o}{=} \PY{p}{[}\PY{p}{]}
\PY{k}{for} \PY{n}{test} \PY{o+ow}{in} \PY{n}{tests}\PY{p}{:}
\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}{)}
\PY{n}{UA\PYZus{}Flights} \PY{o}{=} \PY{p}{[}\PY{p}{]}
\PY{k}{for} \PY{n}{test} \PY{o+ow}{in} \PY{n}{tests}\PY{p}{:}
\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}{)}
\PY{n}{ratio} \PY{o}{=} \PY{p}{[}\PY{p}{]}
\PY{k}{for} \PY{n}{test} \PY{o+ow}{in} \PY{n}{tests}\PY{p}{:}
\PY{n}{ratio}\PY{o}{.}\PY{n}{append}\PY{p}{(}\PY{n}{test}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{]}\PY{p}{)}
\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}{]}
\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}{]}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
{\color{outcolor}Out[{\color{outcolor}6}]:} [1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5, 1, 3, 5]
\end{Verbatim}
The Results
The ratios of Delta's successful flights versus United's succesful
flights are shown below. For each flight path, there are four
ratios--each representing a test with a different number of planes. For
reference, the flight paths are in order of shortest time to longest.
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}7}]:} \PY{n+nb}{print}\PY{p}{(}\PY{n}{ratio}\PY{p}{)}
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
[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]
\end{Verbatim}
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}8}]:} \PY{c+c1}{\PYZsh{} Creates a bubble plot to plot the ratio of successful flights}
\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}{,}
\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}{,}
\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{}}
\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}
\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}{15}
\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}{)}
\PY{n}{plot}\PY{p}{(}\PY{p}{[}\PY{l+m+mi}{2}\PY{p}{,} \PY{l+m+mi}{6}\PY{p}{]}\PY{p}{,} \PY{p}{[}\PY{l+m+mi}{1}\PY{p}{,} \PY{l+m+mi}{1}\PY{p}{]}\PY{p}{,} \PY{n}{color}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{purple}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{n}{linestyle}\PY{o}{=}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{\PYZhy{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{,} \PY{n}{linewidth}\PY{o}{=}\PY{l+m+mi}{2}\PY{p}{)}
\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}{)}
\PY{n}{plt}\PY{o}{.}\PY{n}{ylabel}\PY{p}{(}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{Ratio of Successful Flights}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)}
\PY{n}{plt}\PY{o}{.}\PY{n}{title}\PY{p}{(}\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}{)}
\PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)}
\end{Verbatim}
\texttt{\color{outcolor}Out[{\color{outcolor}8}]:}
\begin{center}
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{ModSim Project 1_files/ModSim Project 1_13_0.png}
\end{center}
{ \hspace*{\fill} \\}
This graph shows the ratio of successful flights from United to those of
Delta. The higher the ratio, the more successful Delta is. The line at y
= 1 represents the point at which Delta begins having more successful
flights than United. The size of each bubble represents the length of
the flight.
\begin{Verbatim}[commandchars=\\\{\}]
{\color{incolor}In [{\color{incolor}9}]:} \PY{c+c1}{\PYZsh{} Creates a bubble plot to plot the number of successful flights for each airline}
\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}{,}
\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}{,}
\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{}}
\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}
\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}
\PY{n}{plt}\PY{o}{.}\PY{n}{scatter}\PY{p}{(}\PY{l+s+s1}{\P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l+m+mi}{20}
\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}{)}
\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}{)}
\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}{)}
\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}{)}
\PY{n}{plt}\PY{o}{.}\PY{n}{show}\PY{p}{(}\PY{p}{)}
\end{Verbatim}
\texttt{\color{outcolor}Out[{\color{outcolor}9}]:}
\begin{center}
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{ModSim Project 1_files/ModSim Project 1_15_0.png}
\end{center}
{ \hspace*{\fill} \\}
This graph shows the individual number of flights from United (blue) and
Delta (red) that are successful. The size of each bubble represents the
length of the flights.
The Interpretation
The data in these two plots shows most clearly that given a certain time
period, more shorter flights can be completed than longer ones. This is
no surprise, and more interesting is the ratios of United flights to
Delta flights. With less planes, it is clear that United's model of
using all of its planes works well, even if they have a slightly longer
turnaround. However, as the airlines' fleets grow, Delta gains the
advantage. This can best be explained by the fact that Delta constantly
has 1 reserve plane, and so the ratio of reserve planes:in service
planes decreases, while the advantage of having a reserve plane doesn't.
Plot 1 shows the ratio increasing throughout (shifting towards Delta's
side) but levelling off near the end. This could imply that Delta's
strategy works better with more planes, but only up to a point, after
which it is still beneficial, but stops improving relative to United.
Plot 2 shows a very significant change in the number of successful short
flights, and a smaller change in the longer flights. This can be
attributed to the fact that there are more shorter flights so any
imbalances will compound much faster. However, it should also be noted
that Delta's method definitely seems more effective with shorter
flights. This can be seen in both plots, as in plot 1, the shorter
flights (smaller bubbles) have a much larger ratio, and in the second
plot, delta's short flights exceed those of United earlier than the long
flights.
In conclusion, United's model tends to be better suited to longer
flights and fewer planes, while the opposite is true for Delta.
\end{document}