コード例 #1
0
        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);
        }
コード例 #2
0
 public void StartGA()
 {
     AbstractTrack.ClearCount();
     AbstractTrack[] tracks = new AbstractTrack[_newConfig.Tracks.Length];
     for (int i = 0; i < tracks.Length; i++)
     {
         tracks[i] = _newConfig.Tracks[i].Clone();
     }
     _newGA = new GEngine(tracks, _newConfig.ProbOfCrossingover, _newConfig.ProbOfMutation, _newConfig.FitnessFunction, _newConfig.Mutation, _newConfig.Crossingover, _newConfig.Selection);
     _threadRunGA = new Thread(_newGA.Run);
     _threadRunGA.Name ="LaborOfGA";
     try
     {
         _threadRunGA.Start();
     }
     catch (ThreadAbortException)
     {
         CleaningDB();
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void RunReachWantedResultTest()
        {
            _mutation = new NotRandomMutation();
            _selection = new TournamentSelection();
            _crossingover = new CyclicalCrossingover();

            int wantedResult = 6;
            IFitnessFunction fitnessFunction = new ReachWantedResult(wantedResult);
            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(wantedResult, target.FitnessFunction.BestResult);
            Assert.IsTrue(preBestResult > target.FitnessFunction.BestResult);
        }