/** * Gets a list of the affected genes. * * @param selected is the list of selected genes. * @return the list of affected genes. */ public ArrayList<ArrayList<Gene>> getAffected(ArrayList<Gene> selected) { ArrayList<ArrayList<Gene>> results = new ArrayList<ArrayList<Gene>>(); for (ArrayList<Gene> x : causes) { boolean conditions = true; // check if the list of conditions are met. int j = 0; while (conditions == true && j < x.size()) { boolean gene_found = false; int i = 0; Gene gene_x = x.get(j); // check input list against condision while (gene_found == false && i < selected.size()) { if (gene_x.equals(selected.get(i))) { gene_found = true; } i++; } if (gene_found == false) { conditions = false; } j++; } if (conditions == true) { results.add(x); } } return results; }
/** * Checks if any of the conditions for the disease are met. * * @param selected is the list of selected genes. * @return true if conditions met. */ public boolean isAffected(ArrayList<Gene> selected) { for (ArrayList<Gene> x : causes) { boolean conditions = true; // check if the list of conditions are met. int j = 0; while (conditions == true && j < x.size()) { // goes through sub list Gene gene_x = x.get(j); // gets current gene boolean gene_found = false; int i = 0; // check input list against condition while (gene_found == false && i < selected.size()) { if (gene_x.equals(selected.get(i))) { gene_found = true; } i++; } if (gene_found == false) { conditions = false; } j++; } if (conditions == true) { return true; } } return false; }
public int addLink(int historicalID) { int attempts = 0; int maxAttempts = 5; boolean success = false; int input; int output; Gene link; do { input = rand.nextInt(numInputs + neurons.size() - numOutputs); if (rand.nextDouble() < GeneticAlgorithm.biasRate) { input = numInputs - 1; } else if (input >= numInputs) { input += numOutputs; } do { output = rand.nextInt(neurons.size()) + numInputs; } while (output == input); // make sure link is not backwards if (neuronType(input) == 1 && neuronType(output) == 1) { if (getNeuron(input).getx() > getNeuron(output).getx()) { // if input is ahead of output, swap int temp = input; input = output; output = temp; } else if (getNeuron(input).getx() == getNeuron(output).getx()) { // if input is same as output, move one getNeuron(output).setx(getNeuron(output).getx() + 0.1); } } link = new Gene(input, output, historicalID, false); success = true; for (Gene l : links) { if (l.equals(link)) { success = false; } } attempts++; } while (attempts < maxAttempts && !success); if (success) { addLink(link); return historicalID + 1; } else { return historicalID; } }