/// <summary>
        /// Performs a sort of K Nearest Neighbour.
        /// </summary>
        public void KNNSearch()
        {
            CurrentLocation = -1;
            limit           = Convert.ToInt32(UpperTextBox.Text);
            lowerlimit      = Convert.ToInt32(LowerTextBox.Text);
            testInd         = Convert.ToInt32(TestOrientBox.Text);

            int simNum = Convert.ToInt32(SimulateBox.Text);
            List <List <double> >         Tests     = MainData.GetFlattenedTests(testInd, simNum);
            List <List <double> >         map       = MainData.GetFlattenedMap(simNum, -1);
            List <List <List <double> > > Distances = new List <List <List <double> > >();

            // Get distance metrics
            for (int i = 0; i < Tests.Count; i++)
            {
                Distances.Add(GetDistWithDirec(map, Tests[i]));
            }

            // Perform search
            int currentTest = 0;

            foreach (List <List <double> > test in Distances)
            {
                // Get minimums
                List <int>    MinInds = new List <int>();
                List <double> Mins    = new List <double>();
                foreach (List <double> orientation in test)
                {
                    List <object> details = GetMin(limit, orientation.Count, orientation);
                    Mins.Add((double)details[0]);
                    MinInds.Add((int)details[1]);
                }

                // Find min orientation
                double TotalMin       = Mins.Min();
                int    OrientationInd = Mins.IndexOf(TotalMin);
                int    PointInd       = MinInds[OrientationInd];

                // First test must be 0 (?)
                if (currentTest == 0)
                {
                    PointInd = 0;
                }


                MainDataStructure.TestPoint point = MainData.GetTestPoint(currentTest);
                point.CalculatedPoint     = PointInd;
                point.CalculatedDirection = OrientationInd;
                point.CalculatedMin       = TotalMin;
                MainData.SetTest(currentTest, point);
                CurrentLocation = PointInd;


                Console.WriteLine("Test " + currentTest + ":  Expected: " + point.ExpectedPoint + "  Got: " + PointInd + " with " + TotalMin);
                Console.WriteLine("                Direction -> Expected: " + point.ExpectedDirection + "  Got: " + OrientationInd);
                Console.WriteLine("All mins");
                for (int j = 0; j < Mins.Count; j++)
                {
                    Console.WriteLine("Min:" + Mins[j] + "  at: " + MinInds[j]);
                }
                Console.WriteLine("---------------------------" + Environment.NewLine);
                currentTest++;
            }
        }