public void TestA1() { initialiseA(); Boolean passed = true; int[] countNumbers; countNumbers = new int[150]; GeneticEngine testEngine = new GeneticEngine(APopulator, AEvaluator, AGeneticOperator, AFitnessThresholdTerminator, AOutputter, null); currentGeneration = testEngine.Generation; int temp = 0; //Check that 100 individuals were generated: if (currentGeneration.Count != 100) throw new Exception("Count not set to 100."); //Check that individuals exist with values 1-100 exactly once each. for (int i = 0; i < 100; i++) { temp = (((IntegerIndividual)(currentGeneration.Get(i)).Individual)).value; countNumbers[temp - 1]++; } for (int i = 0; i < 100; i++) { if (countNumbers[i] != 1) { passed = false; break; } } //if (!passed) throw new Exception("Individuals not populated from 1-100 exactly once each"); Assert.IsTrue(passed); //If no exceptions halt test: Console.WriteLine("Test A1 Successful"); }
public void Operate(IGeneration source, ArrayList destination) { //Are the individuals in source already ordered by fitness? If so: for (int i = 0; i < 50; i++) { IntegerIndividual theIndividual = (IntegerIndividual)source.Get(i).Individual; IntegerIndividual operatedIndividual1 = new IntegerIndividual(); IntegerIndividual operatedIndividual2 = new IntegerIndividual(); operatedIndividual1.value = theIndividual.value + 1; operatedIndividual2.value = theIndividual.value + 2; destination.Add(operatedIndividual1); destination.Add(operatedIndividual2); } }
public void TestA2() { initialiseA(); Boolean passed = true; int[] countNumber; countNumber = new int[198]; GeneticEngine testEngine = new GeneticEngine(APopulator, AEvaluator, AGeneticOperator, AFitnessThresholdTerminator, AOutputter, null); //testEngine.Step(); //testEngine.Step(); currentGeneration = testEngine.Generation; int temp = 0; //Check that individuals exist from 2 to 200. for (int i = 0; i < currentGeneration.Count; i++) { temp = (((IntegerIndividual)(currentGeneration.Get(i)).Individual)).value; countNumber[temp - 1]++; } for (int i = 0; i < currentGeneration.Count; i++) { if (countNumber[i] == 0) { passed = false; break; } } //if (!passed) throw new Exception("Individuals not generated from 2-200 correctly."); Assert.IsTrue(passed); //If no exceptions halt test, then successful: Console.WriteLine("Test A2 Successful"); }
//[TestMethod] public void TestA5() { initialiseA(); GeneticEngine testEngine = new GeneticEngine(APopulator, AEvaluator, AGeneticOperator, AFitnessThresholdTerminator, AOutputter, null); //testEngine.Reset(); testEngine.Run(); int[] countNumber; //Boolean passed = true; countNumber = new int[100]; currentGeneration = testEngine.Generation; int temp = 0; int min = 0; int max = 0; min = (((IntegerIndividual)(currentGeneration.Get(0)).Individual)).value; max = (((IntegerIndividual)(currentGeneration.Get(0)).Individual)).value; //Check that individuals exist from 101 to 200. for (int i = 0; i < currentGeneration.Count; i++) { temp = (((IntegerIndividual)(currentGeneration.Get(i)).Individual)).value; if (temp > max) max = temp; if (temp < min) min = temp; //countNumber[temp - 101]++; } //if (min != 101) passed = false; //if (max != 200) passed = false; Assert.AreEqual(max, 200); Assert.AreEqual(min, 101); //If we need to check ever single individual and make sure there is exactly 1 instance of every integer from 101-200. /* for (int i = 0; i < currentGeneration.Count; i++) { if (countNumber[i] == 0) { passed = false; break; } } */ //if (!passed) throw new Exception("Individuals not generated from 101-200 correctly."); //Assert.IsTrue(passed); //If no exceptions halt test, then successful: Console.WriteLine("Test A5 Successful"); }
public void Operate(IGeneration source, ArrayList destination) { int num_to_mutate = (int)( source.Count * fraction_to_mutate ); for (int ii = 0; ii < num_to_mutate; ii++) { destination.Add( Mutate( (RoadNetwork)source.Get(ii).Individual ) ); } }