Exemple #1
0
        static string delim = ",";   // delimiter for csv

        static void Main(string[] args)
        {
            // file name for data set
            string fn = "berlin52";

            // initialise TSP instance and load file
            TSPInstance berlin = new TSPInstance(fn);

            // Initialise CSV file. Create and open streamwriter for writing, and create table headings
            InitialiseCSV(fn);

            // Loop for running tests n times
            for (int i = 0; i < 5; ++i)
            {
                RunNearestNeighbour(berlin);
                RunTwoOpt(berlin);
                writer.WriteLine();
            }

            // close writer connection to file and dispose of it
            writer.Close();
            writer.Dispose();

            // stop console window from closing
            //Console.ReadLine();
        }
Exemple #2
0
        // Method to run, time and print results from TwoOpt test
        public static void RunTwoOpt(TSPInstance test)
        {
            // start stopwatch
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            // create new tour from NearestNeighbour.
            List <PointF> twoOpt = test.TwoOpt(test.NearestNeighbour(test.originalCitiesData));

            // Stop timer
            stopwatch.Stop();
            long elaspedTime = stopwatch.ElapsedMilliseconds;

            // Print results
            PrintResult(elaspedTime, test.CalculateLength(twoOpt), test.Correct(twoOpt));
        }
Exemple #3
0
        // Method to run, time and print results from nearest neighbour test
        public static void RunNearestNeighbour(TSPInstance test)
        {
            // Start timer
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            // create new tour from original read-in data, using nearest neighbour algorithm
            List <PointF> nn = test.NearestNeighbour(test.originalCitiesData);

            // Stop timer
            stopwatch.Stop();
            long elaspedTime = stopwatch.ElapsedMilliseconds;

            // print results
            // calculate total length of tour
            // check if solution is correct (no duplicates/dimensions are correct/everything exists in the list)
            PrintResult(elaspedTime, test.CalculateLength(nn), test.Correct(nn));
        }