コード例 #1
0
 public void TestFitness()
 {
     Grid g = new Grid(9,10);
     EvolutionarySolver es = new EvolutionarySolver();
     Assert.AreEqual(71,es.GetFitness(g));
     g.Place(8,g.GetEmptyPositions().First());
     Assert.AreEqual(70, es.GetFitness(g));
     g.Place(8, g.GetEmptyPositions().First());
     Assert.AreEqual(2069, es.GetFitness(g));
 }
コード例 #2
0
        public void TestInitialPopulation()
        {
            Grid g = new Grid(9,8);
            EvolutionarySolver es = new EvolutionarySolver();
            var initPop = es.GetInitialPopulation(g);
            foreach (var grid in initPop)
            {
                  Assert.IsTrue(grid.GetNumPlaced() >= g.GetNumPlaced());
                var empty = grid.GetEmptyPositions();
                  var isect = g.GetEmptyPositions().Intersect(empty).ToList();

                foreach (var i in isect)
                {
                    Assert.IsTrue(empty.Contains(i));
                }

            }
        }
コード例 #3
0
 public double GetFitness(Grid g)
 {
     return g.GetNumMistakes()*MistakesFactor + g.GetEmptyPositions().Count;
 }