\documentclass[12pt]{article}
\usepackage[backend=biber,style=ieee]{biblatex}
\usepackage{subfiles}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[margin=1.0in]{geometry}
\usepackage{color}

\bibliography{report}

\title{CS 325 Project 4: The Travelling Salesman Problem (TSP)}
\author{Group 12\\
         Kyle Guthrie \\
         Michael C. Stramel \\
         Alex Miranda
}
\date{December 2, 2016}

\begin{document}
\maketitle

\newpage
\section*{Summary}
\subsection*{Problem Statement}

The purpose of the project was to research and implement algorithms for the Traveling Salesman Problem (TSP). We were provided 10 total problem instances, which consisted of numbered cities and their corresponding x,y coordinates. The goal was to devise agorithms that solve tours to visit each city exactly once and return to the originating city. Additionally, these tours should be found quickly (or efficiently). Our goal was to implement algorithms that, for all 10 problem instances, calculated tour lengths of no worse than 25\% over the optimal tour lengths.  Additionally, for a subset of the problem instances, we were to discover feasible solutions in 3 minutes or less.  For three of the problem instances (example problem set), we were given the optimal tour lengths.  For the other seven problem instances (competition problem set), we used \cite{concorde} to approximate the optimal tour lengths.

\subsection*{Algorithms Researched/Implemented}

Our research included Google searches regarding TSP algorithms, and readings of various texts such as ~\cite{cormen2009} and ~\cite{skiena2008} .  See the bibliography at the conclusion of this report for a full list of references.  Ultimately, we implemented four different algorithms in Python or C.  We will call these algorithms: braindead tour, nearest neighbor, depth first search of the minimum spanning tree, and 2-opt.  Details and pseudocode for each implementation can be found in the following pages.

\subsection*{Results}

Complete results (runtimes and calculate tours) for each problem instance for each algorithm can be found in the last pages of this document.  We found that certain algorithms were fast and that others provided answers under the 25\% threshold, but it was ultimately our 2-opt algorithm that provided the best combination of the two.  It is for this algorithm that we submitted competition results.

\newpage
\section*{Algorithm: Braindead Tour}
\subfile{../Alg00_Braindead_Tour/alg00.tex}

\newpage
\section*{Algorithm: Depth First Search of Minimum Spanning Tree}
\subfile{../Alg01_DFS_of_MST/alg01.tex}

\newpage
\section*{Algorithm: 2-Optimal Tour}
\subfile{../Alg02_2OPT/alg02.tex}

\newpage
\section*{Algorithm: Nearest Neighbor}
\subfile{../Alg04_Nearest_Neighbor/alg04.tex}

\newpage
\section*{Summary Stats: Example 1}
\begin{verbatim}
input size:               76
optimal tour length:      108159

algorithm:                braindead tour
tour length:              150781
len/opt len:              1.39
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0667

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              139725
len/opt len:              1.29
runtime(d:hh:mm:ss.ssss): 0:00:00:01.4073

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              141813
len/opt len:              1.31
runtime(d:hh:mm:ss.ssss): 0:00:00:00.1616

algorithm:                nearest neighbor
tour length:              130921
len/opt len:              1.21
runtime(d:hh:mm:ss.ssss): 0:00:00:00.2948

algorithm:                2-OPT with Nearest Neighbor initial tour
tour length:              109067
len/opt len:              1.008
runtime(d:hh:mm:ss.ssss): 0:00:00:0.0352
\end{verbatim}

\newpage
\section*{Summary Stats: Example 2}
\begin{verbatim}
input size:               280
optimal tour length:      2579

algorithm:                braindead tour
tour length:              2808
len/opt len:              1.09
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0671

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              3819
len/opt len:              1.48
runtime(d:hh:mm:ss.ssss): 0:00:01:27.5504

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              3890
len/opt len:              1.51
runtime(d:hh:mm:ss.ssss): 0:00:00:00.7930

algorithm:                nearest neighbor
tour length:              2975
len/opt len:              1.15
runtime(d:hh:mm:ss.ssss): 0:00:00:04.4363

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              2654
len/opt len:              1.029
runtime(d:hh:mm:ss.ssss): 0:00:00:2.2387
\end{verbatim}

\newpage
\section*{Summary Stats: Example 3}
\begin{verbatim}
input size:               15112
optimal tour length:      1573084

algorithm:                braindead tour
tour length:              112310765
len/opt len:              71.40
runtime(d:hh:mm:ss.ssss): 0:00:00:00.2477

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              2955932
len/opt len:              1.88
runtime(d:hh:mm:ss.ssss): 0:11:46:52.8194

algorithm:                nearest neighbor
tour length:              1917269
len/opt len:              1.22
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              1675756
len/opt len:              1.065
runtime(d:hh:mm:ss.ssss): 0:06:39:16.6653
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 1}
\begin{verbatim}
input size:               50
optimal tour length:      5333 (from Concorde)

algorithm:                braindead tour
tour length:              27301
len/opt len:              5.12
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0636

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              8397
len/opt len:              1.57
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0546

algorithm:                nearest neighbor
tour length:              5911
len/opt len:              1.11
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0808

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              5373
len/opt len:              1.0075
runtime(d:hh:mm:ss.ssss): 0:00:00:0.0265
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 2}
\begin{verbatim}
input size:               100
optimal tour length:      7384 (from Concorde)

algorithm:                braindead tour
tour length:              48053
len/opt len:              6.51
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0631

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              12681
len/opt len:              1.72
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0768

algorithm:                nearest neighbor
tour length:              8011
len/opt len:              1.08
runtime(d:hh:mm:ss.ssss): 0:00:00:00.2705

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              7487
len/opt len:              1.01
runtime(d:hh:mm:ss.ssss): 0:00:00:0.1035
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 3}
\begin{verbatim}
input size:               250
optimal tour length:      12067 (from Concorde)

algorithm:                braindead tour
tour length:              123877
len/opt len:              10.27
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0639

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              21611
len/opt len:              1.79
runtime(d:hh:mm:ss.ssss): 0:00:00:00.3322

algorithm:                nearest neighbor
tour length:              14826
len/opt len:              1.23
runtime(d:hh:mm:ss.ssss): 0:00:00:03.6776

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              12459
len/opt len:              1.03
runtime(d:hh:mm:ss.ssss): 0:00:00:4.0371
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 4}
\begin{verbatim}
input size:               500
optimal tour length:      16720 (from Concorde)

algorithm:                braindead tour
tour length:              247675
len/opt len:              14.81
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0667

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              31483
len/opt len:              1.88
runtime(d:hh:mm:ss.ssss): 0:00:00:01.8154

algorithm:                nearest neighbor
tour length:              19711
len/opt len:              1.18
runtime(d:hh:mm:ss.ssss): 0:00:00:24.9158

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              17318
len/opt len:              1.04
runtime(d:hh:mm:ss.ssss): 0:00:00:49.9898
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 5}
\begin{verbatim}
input size:               1000
optimal tour length:      22976 (from Concorde)

algorithm:                braindead tour
tour length:              48053
len/opt len:              2.09
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0687

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              44272
len/opt len:              1.93
runtime(d:hh:mm:ss.ssss): 0:00:00:10.8341

algorithm:                nearest neighbor
tour length:              27128
len/opt len:              1.18
runtime(d:hh:mm:ss.ssss): 3 minute limit hit

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              24085
len/opt len:              1.05
runtime(d:hh:mm:ss.ssss): 3 minute limit hit
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 6}
\begin{verbatim}
input size:               2000
optimal tour length:      32448 (from Concorde)

algorithm:                braindead tour
tour length:              1050395
len/opt len:              32.37
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0762

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              61594
len/opt len:              1.90
runtime(d:hh:mm:ss.ssss): 0:00:01:24.4163

algorithm:                nearest neighbor
tour length:              39834
len/opt len:              1.23
runtime(d:hh:mm:ss.ssss): 3 minute limit hit

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              34405
len/opt len:              1.06
runtime(d:hh:mm:ss.ssss): 3 minute limit hit
\end{verbatim}

\newpage
\section*{Summary Stats: Test/Competition 7}
\begin{verbatim}
input size:               5000
optimal tour length:      Unknown

algorithm:                braindead tour
tour length:              2580008
len/opt len:              Unknown
runtime(d:hh:mm:ss.ssss): 0:00:00:00.0938

algorithm:                depth first search of minimum spanning true (prim's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): DNF

algorithm:                depth first search of minimum spanning true (kruskal's)
tour length:              DNF
len/opt len:              DNF
runtime(d:hh:mm:ss.ssss): 3 minute limit hit (no results generated)

algorithm:                nearest neighbor
tour length:              62110
len/opt len:              Unknown
runtime(d:hh:mm:ss.ssss): 3 minute limit hit

algorithm:                2-OPT w/ Nearest Neighbor initial tour
tour length:              55149
len/opt len:              Unknown
runtime(d:hh:mm:ss.ssss): 3 minute limit hit
\end{verbatim}

\newpage
\printbibliography

\end{document}


\documentclass[12pt, titlepage]{article}
\usepackage{xspace}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{hyperref}
\usepackage{mathtools}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=red,
    urlcolor=blue
}
\usepackage[round]{natbib}

\input{../../Comments}
\input{../../Common}

\begin{document}

\title{A Fourier Series Library: Unit Verification and Validation Plan for FSL}
\author{Bo Cao}
\date{\today}

\maketitle

\pagenumbering{roman}

\section{Revision History}

\begin{tabularx}{\textwidth}{p{3cm}p{2cm}X}
\toprule {\bf Date} & {\bf Version} & {\bf Notes}\\
\midrule
Oct. 28, 2019  & 1.0 & First draft.\\
Date 2 & 1.1 & Notes\\
\bottomrule
\end{tabularx}

~\newpage

\tableofcontents

\newpage

\section{Symbols, Abbreviations and Acronyms}

Some symbols, abbreviations and acronyms are defined in the Software Requirement and Specification (SRS) document \footnote{This document is available at \url{https://github.com/caobo1994/FourierSeries/blob/master/docs/SRS/SRS.pdf}.}. For simplicity and maintainability, they are not redefined here. Readers shall refer to the SRS documents when a certain item is not defined here.

\renewcommand{\arraystretch}{1.2}
\begin{tabular}{l l}
  \toprule
  \textbf{symbol} & \textbf{description}\\
  \midrule
  T & Test\\
  \bottomrule
\end{tabular}\\

\newpage

\pagenumbering{arabic}

This document provides an overview of the Verification and Validation (VnV) plan for the Fourier Series Library (FSL). It lays out the purpose, methods, and test cases for the VnV procedure.

\section{General Information}

\subsection{Purpose}

The library to be tested is called the Fourier Series Library (FSL). This library performs a set of computations, transformations, and/or input/output at the request of the library user.

\subsection{Scope}

The intended objective of the VnV procedure is to verify that this library has generally met the requirements described in the SRS document. These requirements include the functional requirements (FRs) and the non-functional requirements (NFRs).

Note that if a small part of the NFRs has not been met, the library is still acceptable when the not-met NFRs' impact has been analyzed and deemed non-essential.

The transformation from a function to its CFS involves numerical integration, and the division operation of CFS's contain solving of linear equations. We plan to use existing libraries for these tasks. Instead of test these libraries, we will trust them on the ground of their developers' and other users' through testing.

\section{Plan}

\subsection{Verification and Validation Team}

The author of this library, Bo Cao, will do all the Unit VnV, including the design, coding and execution of the Automated Testing.

\subsection{Automated Testing and Verification Tools}

We have decided that this library will be implemented in \li{C++}.

The unit test library we choose is \li{Catch2}\footnote{Available at \url{https://github.com/catchorg/Catch2}}. This library is designed for simple unit testing in both \li{C} and \li{C++}. We choose this library because it is light-weight, thus easy to install and use. These two properties are especially helpful in our situation, since I expect that most of the other collaborators have little knowledge in C++ and unit testing.

The static analysis will be done by \li{cpplint}. This is a classic \li{C++} program static analysis tool. It is maintain by Google for checking a \li{C++} program's consistency with Google's \li{C++} code style guidance. This tool and guidance can be found at \url{https://github.com/google/styleguide}.

The code coverage of the designed unit test cases will be tested by \li{gcov}. This is the standard code coverage tool that is assisted by the GNU program/library family's \li{C++} compiler, \li{g++}. An detailed introduction can be found in \url{https://gcc.gnu.org/onlinedocs/gcc/Gcov.html}.

The (pseudo-)oracles for unit testing come from manual computation and/or the results computed by MATLAB's Fourier Transformation library.

\subsection{Non-Testing Based Verification}

We will have a code inspection and walkthrough of some functions in this library, if they are deemed too complex. This test will be assisted by the result of \li{cpplint}.

\section{Unit Test Description}

The unit test cases of this library will be based on the system test cases of this library, with the following additions and modifications.
\subsection{Tests for Functional Requirements}
Due to the nature of the library, the test of most functions are defined in the System VnV. We will not elaborate on these defined functions.

We should also notice that these three functions must be tested in order, and these functions must be tested before other functions: \licpp{Subtraction}, \li{Amplitude}, \li{ToleratedEquality}.

\subsubsection{Module 1: Linear Solver}
\begin{enumerate}
	\item Test of \licpp{LinSolve}:\\

	Type: Automatic\\
	Initial State: Loaded library\\
	Input: $m=2, M=\begin{bsmallmatrix}
	1 & 1\\0 & 1
	\end{bsmallmatrix}, b=\begin{bsmallmatrix}
	3\\1
	\end{bsmallmatrix}$
	Output: $a$, whose oracle is$\begin{bsmallmatrix}
	2\\1
	\end{bsmallmatrix}$
	Test Case Derivation: output shall match oracle exactly.
	How the test will be performed: Unit Test will call the function with the input, and compare the output with the oracle.
\end{enumerate}

\subsubsection{Module 2: Integral}
\begin{enumerate}
	\item Test of \licpp{Integral}:\\

	Type: Automatic\\
	Initial State: Loaded library\\
	Input: $f=t\rightarrow t, a=0, b=1$
	Output: $\textit{res}$, whose oracle is 0.5.
	Test Case Derivation: difference between oracle and output shall be smaller than $\epsilon=10^{-6}$.
	How the test will be performed: Unit Test will call the function with the input, and compare the output with the oracle (called Compare later.)
\end{enumerate}

\subsubsection{Module 3: Conversion}
The unit test is the same as the system test, and we give a table describing which system test is for which function.
\begin{table}[h]
	\centering
	\begin{tabular}{c c}
		\hline
		Test name & Function\\
		\hline
		Test of conversion from other data format&\licpp{ConvertFrom}\\
		Test of conversion to other data format&\licpp{ConvertTo}\\
		\hline
	\end{tabular}
\end{table}
\subsubsection{Module 4: Transformation}
The unit test is the same as the system test, and we give a table describing which system test is for which function.
\begin{table}[h]
	\centering
	\begin{tabular}{c c}
		\hline
		Test name & Function\\
		\hline
		Test of coefficient (even function)&\licpp{Transform}\\
		Test of coefficient (odd function)&\\
		Test of approximated function value&\licpp{FunctionValue}\\
		\hline
	\end{tabular}
\end{table}
\subsubsection{Module 5: Basic Operation}
The unit test is the same as the system test except for the \li{CFSMatch} function, and we give a table describing which system test is for which function.

\begin{table}[h]
	\centering
	\begin{tabular}{c c}
		\hline
		Test name & Function\\
		\hline
		Test of addition&\licpp{Addition}\\
		Test of subtraction&\licpp{Subtraction}\\
		Test of multiplication
		&\licpp{Multiplication}\\
		Test of division&\licpp{Division}\\
		Test of amplitude&\licpp{Amplitude}\\
		\hline
	\end{tabular}
\end{table}

The test template for the \licpp{CFSMatch} function is
\begin{enumerate}
	\item Test of \licpp{CFSMatch}:\\

	Type: Automatic\\
	Initial State: Loaded library\\
	Input: $CFSf=[n=2, \omega=1.0, A=\{0, 0, 0\}, B=\{0, 0\}]$, $CFSg=[n=a, \omega=b, A=\{...\}, B=\{...\}]$. The length of $A$ and $B$ in $CFSg$ shall be  decided in accordance with $n$, and the values of elements in $A$ and $B$ shall all be $0$.\\
	Output: $\textit{res}$, whose oracle is $c$.\\
	Test Case Derivation: output shall fully match the oracle.\\
	How the test will be performed: Unit Test will call the function with the input, and compare the output with the oracle.
\end{enumerate}
We generate test cases from this template by doing the following replacements.
\begin{table}[h]
	\centering
	\begin{tabular}{c|c c c}
		\hline
		Case No.&$a$&$b$&$c$\\
		\hline
		1&2&1.0&\licpp{true}\\
		2&2&0.5&\licpp{false}\\
		3&1&1.0&\licpp{false}\\
		4&1&0.5&\licpp{false}\\
		\hline
	\end{tabular}
\end{table}

\textbf{Note: For the sake of clarity, we can also choose other sets of data for the test of multiplication. For each set of data described below, users can generate a test case by replacing the data in the original test case with the data in each set.}
\begin{table}[h]
	\centering
	\begin{tabular}{c|c c c c c c}
		\hline
		Case No.& A of CFSf&B of CFSf&A of CFSg&B of CFSg& A of CFSres & B of CFSres\\
		\hline
		1&$\{1, 0, 0\}$&$\{0, 0\}$&$\{1, 0, 0\}$&$\{0, 0\}$&$\{0.5, 0, 0.5\}$&$\{0, 0\}$\\
		2&$\{1, 0, 0\}$&$\{0, 0\}$&$\{0, 0, 0\}$&$\{0, 1\}$&$\{0, 0, 0\}$&$\{0.5, 0\}$\\
		3&$\{0, 1, 0\}$&$\{0, 0\}$&$\{0, 0, 0\}$&$\{1, 0\}$&$\{0, 0, 0\}$&$\{-0.5, 0\}$\\
		4&$\{0, 0, 0\}$&$\{1, 0\}$&$\{0, 0, 0\}$&$\{1, 0\}$&$\{0.5, 0, -0.5\}$&$\{0, 0\}$\\
	\end{tabular}
\end{table}
\subsubsection{Module 6: Advanced Operations}
The unit test is the same as the system test except for the \licpp{Power} function, and we give a table describing which system test is for which function.

\begin{table}[h]
	\centering
	\begin{tabular}{c c}
		\hline
		Test name & Function\\
		\hline
		Test of tolerated equality function \li{TolEq} (\li{True} result)&\licpp{ToleratedEquality}\\
		Test of tolerated equality function \li{TolEq} (\li{False} result)&\\
		Test of function of CFS
		&\licpp{Function}\\
		\hline
	\end{tabular}
\end{table}
Note: $e^\textit{CFS}$ is \licpp{Function(CFS, expDeriv)}.

The test case template for the \licpp{Power} function is
\begin{enumerate}
	\item Test of \li{Power}:\\
	Input: $\textit{CFSf}=[n=3, \omega=1.0, A=a, B=b]$, $m=3$\\
	Output: \licpp{Power(CFSf, m)}, whose oracle is $\textit{CFSstd}=[n=3, \omega=1.0, A=a_o, B=b_o]$\\
	Test Case Derivation: \licpp{ToleratedEquality(Power(CFSf, m), CFSstd, err)}, which should be \licpp{true} when $\textit{err}=10^{-6}$.
\end{enumerate}
We generate two test cases from this template with the following sets of values.
\begin{table}[h]
	\centering
	\begin{tabular}{c|c c c c}
	\hline
	Case No.&$A$&$B$&$A_o$&$B_o$\\
	\hline
	1&$\{0, 1, 0, 0\}$&$\{0, 0, 0\}$&$\{0, 0.75, 0, 0.25\}$&$\{0, 0, 0\}$\\
	2&$\{0, 0, 0, 0\}$&$\{1, 0, 0\}$&$\{0, 0, 0, 0\}$&$\{0,75, 0, -0.25, 0\}$\\
	\hline
	\end{tabular}
\end{table}

\subsection{Tests for Nonfunctional Requirements}

Same as the System VnV.

\subsection{Traceability Between Test Cases and Modules}
Since the test cases are already grouped in accordance with their module, this section is not necessary.

\bibliographystyle{plainnat}

\bibliography{SRS}

\end{document}