Exemplo n.º 1
0
 public void InversionMutationTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 12, 13, 14, 15, 16, 17, 18, 19, 20 });
     Inversion<int> mutation = new Inversion<int>(3, 5);
     IChromosome<int> res = mutation.Mutate(a);
     IChromosome<int> exp = new DigitalChromosome().GenerateFromArray(new int[] { 12, 13, 14, 17, 16, 15, 18, 19, 20 });
     Assert.AreEqual(exp, res);
 }
Exemplo n.º 2
0
 public void FibonacciMutationTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 12, 13, 14, 15, 16, 17, 18, 19, 20 });
     FibonacciMutation<int> mutation = new FibonacciMutation<int>(9);
     IChromosome<int> res = mutation.Mutate(a);
     IChromosome<int> exp = new DigitalChromosome().GenerateFromArray(new int[] { 19, 12, 13, 15, 14, 17, 18, 16, 20 });
     Assert.AreEqual(exp, res);
 }
Exemplo n.º 3
0
 public void OnePointCrossoverTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 2, 1 });
     OnePointCrossover<int> cross = new OnePointCrossover<int>(2);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 2, 1 }), new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 3, 4 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 4
0
 public void GoldenCrossoverTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4, 5 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 5, 4, 3, 2, 1 });
     GoldenCrossover<int> cross = new GoldenCrossover<int>(5);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 2, 1 }), new DigitalChromosome().GenerateFromArray(new int[] { 5, 4, 3, 4, 5 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 5
0
 public void CicleCrossoverTest2()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4, 5, 6 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 2, 4, 5, 1, 6, 3 });
     CicleCrossover<int> cross = new CicleCrossover<int>(6);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 5, 4, 6, 3 }), new DigitalChromosome().GenerateFromArray(new int[] { 2, 4, 3, 1, 5, 6 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 6
0
 public void Fibonacci()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4, 5, 6 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 6, 5, 4, 3, 2, 1 });
     FibonacciCrossover<int> cross = new FibonacciCrossover<int>(6);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 5, 3, 3, 2, 6 })
         , new DigitalChromosome().GenerateFromArray(new int[] { 6, 2, 4, 4, 5, 1 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 7
0
 public void GreedyCrossoverTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 4, 2, 3, 1 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 1, 4, 3, 2 });
     int[,] matrix = new int[4, 4]
     {
         { 0, 2, 3, 4},
         { 1, 0, 2, 3},
         { 1, 2, 0, 5},
         { 3, 7, 6, 0}
     };
     GreedyCrossover cross = new GreedyCrossover(4, 2, matrix);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 1, 2 }), new DigitalChromosome().GenerateFromArray(new int[] { 2, 1, 4, 3 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 8
0
 public void OnePointPMX()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4, 5 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 5, 1, 2 });
     OnePointPMX<int> cross = new OnePointPMX<int>(3);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 4, 5, 3, 1, 2 }), new DigitalChromosome().GenerateFromArray(new int[] { 1, 3, 2, 4, 5 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 9
0
 public void UniversalPointCrossover()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 2, 1 });
     UniversalCrossover<int> cross = new UniversalCrossover<int>(new System.Collections.BitArray(new bool[] { false, true, false, true }));
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 3, 3, 1 }), new DigitalChromosome().GenerateFromArray(new int[] { 4, 2, 2, 4 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 10
0
 public void TwoPointPMX()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4, 5 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 4, 3, 5, 1, 2 });
     TwoPointPMX<int> cross = new TwoPointPMX<int>(1, 3);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 3, 5, 4, 2 })
         , new DigitalChromosome().GenerateFromArray(new int[] { 4, 5, 2, 1, 3 }) }; // different from ex. because, i do it for rows
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 11
0
 public void TwoPointOrderCrossover()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 3, 4, 5, 6 });
     IChromosome<int> b = new DigitalChromosome().GenerateFromArray(new int[] { 2, 4, 5, 1, 6, 3 });
     TwoPointOrderCrossover<int> cross = new TwoPointOrderCrossover<int>(2, 4);
     IChromosome<int>[] res = cross.Crossover(a, b);
     IChromosome<int>[] exp = new IChromosome<int>[2] { new DigitalChromosome().GenerateFromArray(new int[] { 1, 2, 4, 3, 5, 6 }), new DigitalChromosome().GenerateFromArray(new int[] { 2, 4, 1, 5, 6, 3 }) };
     CollectionAssert.AreEqual(res, exp);
 }
Exemplo n.º 12
0
 public void TranslocationMutationTest()
 {
     IChromosome<int> a = new DigitalChromosome().GenerateFromArray(new int[] { 12, 13, 14, 15, 16, 17, 18, 19, 20 });
     Translocation<int> mutation = new Translocation<int>(1, 2, 5, 7);
     IChromosome<int> res = mutation.Mutate(a);
     IChromosome<int> exp = new DigitalChromosome().GenerateFromArray(new int[] { 12, 17, 18, 19, 15, 16, 13, 14, 20 });
     Assert.AreEqual(exp, res);
 }