public static void generateDescendants(DNACode[] parents) { for (int i = 0; i < sample.Length; i++) { sample[i] = DNACode.combine(parents); } }
public static DNACode combine(DNACode[] parents, int numToMutate) { DNACode toReturn = combine(parents); toReturn.mutate(numToMutate); return(toReturn); }
public static void newVoidSample(int sampleSize) { sample = new DNACode[sampleSize]; for (int i = 0; i < sampleSize; i++) { sample[i] = new DNACode(); } }
//Carece de sentido public static DNACode[] podaCantidad(int cantidad) { DNACode[] devolver = new DNACode[cantidad]; for (int i = 0; i < cantidad; i++) { devolver[i] = sample[i]; } return(devolver); }
// After the initialization, the sum of all values for the keys must to be equal to DNACode.sumatoryGenValues private void Test_initialize() { DNACode dna = new DNACode().initialize(); int total_quantity = dna.calculateTotalQuantity(); int correctValue = dna.getSumatoryGenValues(); Assert.That(total_quantity, Is.EqualTo(correctValue)); }
private void Test_Constructor() { DNACode dna = new DNACode(); foreach (String key in DNACode.KEYS) { float result = dna.getGen(key); Assert.That(result, Is.EqualTo(0)); } }
static public string dnacode2aminobase(DNACode code) { switch (code) { case DNACode.A: return("Adenine"); case DNACode.G: return("Guanine"); case DNACode.T: return("Thymine"); //case DNACode.C: return "Cytosine"; default: return("Cytosine"); } }
static public string dnacode2symbol(DNACode code) { switch (code) { case DNACode.A: return("A"); case DNACode.G: return("G"); case DNACode.T: return("T"); //case DNACode.C: return "C"; default: return("C"); } }
private void Test_mutate() { int N = 100; for (int i = 0; i < N; i++) { DNACode dna = new DNACode().initialize(); dna.mutate(); int total_quantity = dna.calculateTotalQuantity(); int correctValue = dna.getSumatoryGenValues(); Assert.That(total_quantity, Is.EqualTo(correctValue)); } }
//Combina genes de un vector de padres para crear un nuevo individuo public static DNACode combine(DNACode[] parents) { System.Random rnd = new System.Random(); DNACode toReturn = new DNACode(); foreach (string key in KEYS) { int aux = rnd.Next(0, parents.Length); int val = parents[aux].getGen(key); toReturn.addGen(key, val); } toReturn.addQuantity(-toReturn.incrementFromSumatoryGenValues());//TODO Cambiar descripcion N return(toReturn); }
public static DNACode[] getSubarraySample(int[] indexes) { DNACode[] toReturn = new DNACode[indexes.Length]; int j = 0; foreach (int i in indexes) { if (i >= sample.Length || -i > sample.Length) { throw new IndexOutOfRangeException(); } toReturn[j] = sample[i]; j++; } return(toReturn); }
private void Test_combine() { int N = 100; for (int i = 0; i < N; i++) { DNACode[] parents = new DNACode[2]; parents[0] = new DNACode().initialize(); parents[1] = new DNACode().initialize(); DNACode new_dna = DNACode.combine(parents); int total_quantity = new_dna.calculateTotalQuantity(); int correctValue = new_dna.getSumatoryGenValues(); Assert.That(total_quantity, Is.EqualTo(correctValue)); } }
public static void generateDescendants(DNACode[] parents, bool keepParents) { if (keepParents) { for (int i = 0; i < parents.Length; i++) { sample[i] = parents[i]; } for (int i = parents.Length; i < sample.Length; i++) { sample[i] = DNACode.combine(parents); } } else { generateDescendants(parents); } }