public void TestClosed() { RandomGeneratorExtensions.GetGetNewRandom = () => new RandomGenerator(4541247); // create the problem and make sure 0->1->2->3->4 is the solution. var problem = STSPHelper.CreateSTSP(0, 0, 5, 10, 40); problem.Weights[0][1] = 1; problem.Weights[1][2] = 1; problem.Weights[2][3] = 1; problem.Weights[3][4] = 1; problem.Weights[4][0] = 1; // create a route with one shift. var route = new Optimization.Tours.Tour(new int[] { 0, 2, 3, 1, 4 }, 0); // apply the 1-shift local search, it should find the customer to replocate. var localSearch = new CheapestInsertionOperator(n: 50); STSPFitness delta; Assert.IsTrue(localSearch.Apply(problem, new STSPObjective(), route, out delta)); // test result. Assert.AreEqual(-27, delta.Weight); Assert.AreEqual(0, delta.Customers); Assert.AreEqual(new int[] { 0, 1, 2, 3, 4 }, route.ToArray()); }
public void TestClosed() { RandomGeneratorExtensions.GetGetNewRandom = () => new RandomGenerator(4541247); // create the problem and make sure 0->1->2->3->4 is the solution. var problem = STSPHelper.CreateDirectedSTSP(0, 0, 5, 10, 1, 40); problem.Weights.SetWeight(0, 1, 1); problem.Weights.SetWeight(1, 2, 1); problem.Weights.SetWeight(2, 3, 1); problem.Weights.SetWeight(3, 4, 1); problem.Weights.SetWeight(4, 0, 1); // apply the operator. var route = new Optimization.Tours.Tour(new int[] { 0, 12, 4, 16 }, 0); // apply the 1-shift local search, it should find the customer to replocate. var localSearch = new CheapestInsertionOperator(4, 10); STSPFitness delta; Assert.IsTrue(localSearch.Apply(problem, new STSPObjective(), route, out delta)); }