public void TestSolutions5ClosedNotFixed() { RandomGeneratorExtensions.GetGetNewRandom = () => { return(new RandomGenerator(45841647)); }; // create problem. var problem = TSPTWHelper.CreateDirectedTSPTW(0, 0, 5, 10, 1); problem.Windows[1] = new TimeWindow() { Min = 5, Max = 15 }; problem.Windows[2] = new TimeWindow() { Min = 15, Max = 25 }; problem.Windows[3] = new TimeWindow() { Min = 25, Max = 35 }; problem.Windows[4] = new TimeWindow() { Min = 35, Max = 45 }; // create the solver. var solver = new VNDOperator(); for (int i = 0; i < 10; i++) { // generate solution. float fitness; var solution = solver.Solve(problem, new TSPTWObjective(), out fitness); // test contents. Assert.AreEqual(50, fitness, string.Format("Solution was: {0} with fitness {1}.", solution.ToInvariantString(), fitness)); var solutionList = new List <int>(); foreach (var directedId in solution) { solutionList.Add(DirectedHelper.ExtractId(directedId)); } Assert.AreEqual(0, solutionList[0]); Assert.IsTrue(solutionList.Remove(0)); Assert.IsTrue(solutionList.Remove(1)); Assert.IsTrue(solutionList.Remove(2)); Assert.IsTrue(solutionList.Remove(3)); Assert.IsTrue(solutionList.Remove(4)); Assert.AreEqual(0, solutionList.Count); } }
public void TestSolutions5ClosedNotFixed() { // create problem. var problem = TSPTWHelper.CreateTSPTW(0, 0, 5, 10); problem.Windows[1] = new TimeWindow() { Min = 5, Max = 15 }; problem.Windows[2] = new TimeWindow() { Min = 15, Max = 25 }; problem.Windows[3] = new TimeWindow() { Min = 25, Max = 35 }; problem.Windows[4] = new TimeWindow() { Min = 35, Max = 45 }; // create the solver. var solver = new VNDOperator(); for (int i = 0; i < 10; i++) { // generate solution. float fitness; var solution = solver.Solve(problem, new TSPTWObjective(), out fitness); // test contents. Assert.AreEqual(50, fitness); var solutionList = new List <int>(solution); Assert.AreEqual(0, solutionList[0]); Assert.IsTrue(solutionList.Remove(0)); Assert.IsTrue(solutionList.Remove(1)); Assert.IsTrue(solutionList.Remove(2)); Assert.IsTrue(solutionList.Remove(3)); Assert.IsTrue(solutionList.Remove(4)); Assert.AreEqual(0, solutionList.Count); } }