Beispiel #1
0
        public IActionResult GetPermutationsSimple(string vers)
        {
            List <String> result = new List <string>();

            List <string> list = new List <string>()
            {
                "1", "2", "3", "4"
            };
            IList <IList <string> > perms = TSPHelper.Permutations(list);

            foreach (IList <string> perm in perms)
            {
                string sequence = "";

                foreach (string s in perm)
                {
                    Console.Write(s);
                    sequence += s + ", ";
                }

                result.Add(sequence);
                Console.WriteLine();
            }

            return(Json(result.ToArray()));
        }
Beispiel #2
0
        public IActionResult FindRoute()
        {
            // Get cities x,y coordiates from file
            List <City> cities = TSPHelper.ParseCitiesFromFile(DATASET_FILE_1);

            // Take the first 4
            IEnumerable <City> filteredCities = cities.Take <City>(4);

            // Get permunations for 4 cities
            List <string> list = new List <string>()
            {
                "1", "2", "3", "4"
            };
            IList <IList <string> > perms = TSPHelper.Permutations(list);

            TSPRoute winner = TSPBasic.CalculateTSP(perms, filteredCities.ToArray());

            // print the results in console

            string output = "";

            Console.WriteLine();
            Console.WriteLine();
            output += "Winner route is: ";
            foreach (City city in winner.Cities)
            {
                output += city.Id.ToString() + ", ";
            }
            Console.WriteLine(output + "  with distance: " + winner.TotalDist.ToString("#.00"));

            return(Json(new
            {
                distance = winner.TotalDist.ToString("#.00"),
                cityOrder = output
            }));
        }