예제 #1
0
        public void RunTest1()
        {
            Global.Config.GenerationsCount     = 20;
            Global.Config.CrossoverProbability = 1f;
            Global.Config.MutationProbability  = 1f;
            Global.Config.ElitismPercent       = 0.5f;

            ga.Run();
        }
예제 #2
0
        public void RunTest()
        {
            var jobShop    = new JobShopLoader().Load("TestExamples/test2.in");
            var mockLogger = new Mock <ILogger>();

            Global.Config.MinPopulationSize          = 100;
            Global.Config.MaxPopulationSize          = 100;
            Global.Config.GenerationsCount           = 10;
            Global.Config.IterationsCount            = 1;
            Global.Config.CrossoverProbability       = 0.75f;
            Global.Config.MutationProbability        = 0.3f;
            Global.Config.MutationPerGeneProbability = 0.01f;
            Global.Config.ElitismPercent             = 0.02f;
            Global.Config.ThreadsCount = 1;

            var ga = new JobShopGeneticAlgorithm(jobShop, Global.Config.IterationsCount, mockLogger.Object, adaptive: true);

            typeof(BasicRandomization).GetField("_globalRandom", BindingFlags.Static | BindingFlags.NonPublic)
            .SetValue(null, new Random(42));
            RandomizationProvider.Current = new BasicRandomization();

            ga.Run();

            int expectedScheduleLength = 26;

            Assert.That(ga.BestSchedule.ScheduleLength, Is.EqualTo(expectedScheduleLength));
        }