예제 #1
0
파일: Tests.cs 프로젝트: CmdrKeen/GRASP
        public void TestCost()
        {
            var grasp = new GRASP();
              var cities1 = new List<City> {new City(0, 0), new City(1, 1), new City(2, 2), new City(3, 3)};

              Assert.AreEqual(1 * 2, grasp.Cost(new List<int>() { 0, 1 }, cities1));
              Assert.AreEqual(3 + 4, grasp.Cost(new List<int>() { 0, 1, 2, 3 }, cities1));
              Assert.AreEqual(4 * 2, grasp.Cost(new List<int>() { 0, 3 }, cities1));
        }
예제 #2
0
파일: Tests.cs 프로젝트: CmdrKeen/GRASP
        public void TestLocalSearch()
        {
            var grasp = new GRASP(20);

              var cities1 = new List<City> {new City(0, 0), new City(3, 3), new City(1, 1), new City(2, 2), new City(4, 4)};

              var best = new Candidate();
              best.Vector = new List<int>() {0, 1, 2, 3, 4};
              best.Cost = grasp.Cost(best.Vector, cities1);
              var rs = grasp.LocalSearch(best, cities1);

              Assert.IsNotNull(rs);
              Assert.IsNotNull(rs.Vector);
              Assert.IsNotNull(rs.Cost);
              Assert.AreNotSame(best, rs);
              Assert.AreNotEqual(best.Vector, rs.Vector);
              Assert.AreNotEqual(best.Cost, rs.Cost);

              // No improvement
              grasp = new GRASP(10);
              best = new Candidate();
              best.Vector = new List<int>() {0, 2, 3, 1, 4};
              best.Cost = grasp.Cost(best.Vector, cities1);

              rs = grasp.LocalSearch(best, cities1);
              Assert.IsNotNull(rs);
              Assert.AreEqual(best.Cost, rs.Cost);
        }