public void LoadBerlin52Problem()
        {
            TspFile tspFile;
            var loader = new TspFileLoader();
            using (var reader = new StreamReader(Samples.Berlin52_Problem))
            {
                tspFile = loader.Load(reader);
                reader.Close();
            }

            Assert.IsNotNull(tspFile);

            Assert.AreEqual("berlin52", tspFile.Name);
            Assert.AreEqual(FileType.TSP, tspFile.Type);
            Assert.AreEqual("52 locations in Berlin (Groetschel)", tspFile.Comment);
            Assert.AreEqual(52, tspFile.Dimension);
            Assert.AreEqual(EdgeWeightType.Euclidean2D, tspFile.EdgeWeightType);
            Assert.AreEqual(52, tspFile.Nodes.Count);

            Assert.AreEqual(1, tspFile.Nodes[0][0]);
            Assert.AreEqual(565.0, tspFile.Nodes[0][1]);
            Assert.AreEqual(575.0, tspFile.Nodes[0][2]);

            Assert.AreEqual(2, tspFile.Nodes[1][0]);
            Assert.AreEqual(25.0, tspFile.Nodes[1][1]);
            Assert.AreEqual(185.0, tspFile.Nodes[1][2]);

            Assert.AreEqual(52, tspFile.Nodes[51][0]);
            Assert.AreEqual(1740.0, tspFile.Nodes[51][1]);
            Assert.AreEqual(245.0, tspFile.Nodes[51][2]);
        }
Example #2
0
        /// <summary>
        /// Loads TSP file
        /// </summary>
        /// <param name="fileName">file to load</param>
        /// <returns>Loaed tsp file</returns>
        public static TspFile Load(string fileName)
        {
            TspFile       result = null;
            TspFileLoader loader = new TspFileLoader();

            using (StreamReader reader = new StreamReader(fileName))
            {
                result = loader.Load(reader);
                reader.Close();
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// Loads TSP from string
        /// </summary>
        /// <param name="content">tsp task</param>
        /// <returns>Load tsp file</returns>
        public static TspFile LoadFromString(string content)
        {
            TspFile       result = null;
            TspFileLoader loader = new TspFileLoader();

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(content)))
            {
                using (StreamReader reader = new StreamReader(ms))
                {
                    result = loader.Load(reader);
                    reader.Close();
                }
            }
            return(result);
        }
        public void LoadBerlin52Tour()
        {
            TspFile tspFile;
            var loader = new TspFileLoader();
            using (var reader = new StreamReader(Samples.Berlin52_Tour))
            {
                tspFile = loader.Load(reader);
                reader.Close();
            }

            Assert.IsNotNull(tspFile);

            Assert.AreEqual("berlin52.opt.tour", tspFile.Name);
            Assert.AreEqual(FileType.TOUR, tspFile.Type);
            Assert.AreEqual(52, tspFile.Dimension);
            Assert.AreEqual(52, tspFile.Tour.Count);

            Assert.AreEqual(1, tspFile.Tour[0]);
            Assert.AreEqual(49, tspFile.Tour[1]);
            Assert.AreEqual(22, tspFile.Tour[51]);
        }
Example #5
0
        /// <summary>
        /// Loads TSP file
        /// </summary>
        /// <param name="fileName">file to load</param>
        /// <returns>Loaed tsp file</returns>
        public static TspFile Load(string fileName)
        {
            TspFile result = null;
            TspFileLoader loader = new TspFileLoader();
            using (StreamReader reader = new StreamReader(fileName))
            {
                result = loader.Load(reader);
                reader.Close();
            }

            return result;
        }