public void RunBestRipsTest() { _mutation = new NotRandomMutation(); _selection = new TournamentSelection(); _crossingover = new CyclicalCrossingover(); int bestReps = 150; IFitnessFunction fitnessFunction = new BestReps(bestReps); int pCrossingover = 80; int pMutation = 60; Array.Sort(_closedTracks); double preBestResult = _closedTracks[0].GetTrackLength(); GEngine target = new GEngine(_closedTracks, pCrossingover, pMutation, fitnessFunction, _mutation, _crossingover, _selection); target.Run(); Assert.AreEqual(bestReps, target.FitnessFunction.ActualCountOfReps); Assert.IsTrue(preBestResult >= target.FitnessFunction.BestResult); }
public Configuration() { AliasCrossingover = new List<string>(); AliasMutations = new List<string>(); AliasSelection = new List<string>(); ConfigName = "Новая конфигурация"; AlgMode = AlgorithmMode.Singl; CountOfReplays = 1; ProbOfCrossingover = 100; ProbOfMutation = 100; FitnessParam = 10; Mutation = new NotRandomMutation(); AliasMutations.Add(Mutation.GetName()); Crossingover = new CyclicalCrossingover(); AliasCrossingover.Add(Crossingover.GetName()); Selection = new TournamentSelection(); AliasSelection.Add(Selection.GetName()); Graph = new UndirectedConnectedGraph(10); FitnessFunction = new BestReps((int)FitnessParam); Tracks = new AbstractTrack[10]; Random r = new Random(); for (int i = 0; i < Tracks.Length; i++) { int[] points = new int[10]; for (int j = 0; j < points.Length; j++) { points[j] = -1; } int newRandomChromosome = r.Next(points.Length - 1); for (int j = 0; j < points.Length; j++) { while (points.Contains(newRandomChromosome)) { newRandomChromosome = r.Next(points.Length); } points[j] = newRandomChromosome; } Tracks[i] = new ClosedTrack(points, Graph); } }
public void RunSearchBestTest() { int bestReps = 50; int wantedResult = 6; List<ProxyMutation> proxyMutations = new List<ProxyMutation>(); proxyMutations.Add(new ProxyMutation(new TwoPointMutation())); proxyMutations.Add(new ProxyMutation(new FourPointMutation())); proxyMutations.Add(new ProxyMutation(new NotRandomMutation())); _mutation = new SearchBestMutation(proxyMutations); List<ProxySelection> proxySelectios = new List<ProxySelection>(); proxySelectios.Add(new ProxySelection(new TournamentSelection())); proxySelectios.Add(new ProxySelection(new RouletteSelection())); proxySelectios.Add(new ProxySelection(new RankingSelection())); _selection = new SearchBestSelection(proxySelectios); List<ProxyCrossingover> proxyCrossingovers = new List<ProxyCrossingover>(); proxyCrossingovers.Add(new ProxyCrossingover(new CyclicalCrossingover())); proxyCrossingovers.Add(new ProxyCrossingover(new InversionCrossingover())); proxyCrossingovers.Add(new ProxyCrossingover(new OnePointCrossingover())); proxyCrossingovers.Add(new ProxyCrossingover(new TwoPointCrossingover())); _crossingover = new SearchBestCrossingover(proxyCrossingovers); IFitnessFunction fitnessFunction = new BestReps(bestReps); int pCrossingover = 100; int pMutation = 100; Array.Sort(_closedTracks); double preBestResult = _closedTracks[0].GetTrackLength(); GEngine target = new GEngine(_closedTracks, pCrossingover, pMutation, fitnessFunction, _mutation, _crossingover, _selection); target.Run(); double progress1 = proxySelectios[0].GetProgress(); double progress2 = proxySelectios[1].GetProgress(); double progress3 = proxySelectios[2].GetProgress(); Assert.IsTrue(preBestResult >= target.FitnessFunction.BestResult); }