Exemplo n.º 1
0
        private static void CalcTSP(string filePath)
        {
            var lines = File.ReadAllLines(filePath);
            int verticesCount = int.Parse(lines[0].Split(' ').First());
            var input = new List<Tuple<float, float>>(verticesCount);
            foreach (var line in lines.Skip(1))
            {
                var node = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                input.Add(new Tuple<float, float>(float.Parse(node.First()), float.Parse(node.Skip(1).First())));
            }

            var tsp = new TSPAlg();

            Console.WriteLine("tsp: {0}", tsp.CalcMinCostTour(input.ToArray()));
        }
Exemplo n.º 2
0
        public void TestCase1()
        {
            var input = new[]
                {
                    new Tuple<float, float>(38.24f, 20.42f),
                    new Tuple<float, float>(39.57f, 26.15f),
                    new Tuple<float, float>(40.56f, 25.32f),
                    new Tuple<float, float>(36.26f, 23.12f),
                    new Tuple<float, float>(33.48f, 10.54f),
                    new Tuple<float, float>(37.56f, 12.19f),
                    new Tuple<float, float>(38.42f, 13.11f),
                    new Tuple<float, float>(37.52f, 20.44f),
                };

            var alg = new TSPAlg();
            Assert.AreEqual(37, alg.CalcMinCostTour(input));
        }