/* ITI 1121/1521 - Assignment 1 * Marcel Turcotte (turcotte@site.uottawa.ca) */ /** * A Chromosome is a candidate solution. Its representation * depends on the specific problem to be solved. Two chromosomes can * be combined (see method crossover) to produce a new offspring. As * with natural chromosomes, these artificial ones suffer mutations. * Each chromosome has a fitness value that indicates the * quality of this solution. A Population is a collection of * chromosomes. At each iteration (generation), the genetic algorithm * selects a pair of chromosomes for reproduction. The offspring is * inserted into the population, and the least fitted individual is * eliminated. The size of the population is fixed.

* * You must complete the implementation of the class Chromosome * following all the directives. *

* * Note 1: In order to make sure that class Chromosome is valid * (can be compiled), the methods return dummy values that need to be * replaced by your solution to the problem. For instance, the method * copy returns the value null, you must replace the statement by your * solution. * * Note 2: Consult the documentation (JavaDoc) and assignment * Web page for complementary information. * */ public class Chromosome { /** * A constructor that initializes this chromosome with random moves for this chain. * * @param chain the chain of constituents */ public Chromosome(String chain) { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. } /** * A constructor that initializes the content of this Chromosome with that * of other. * * @param other is an other Chromomose */ public Chromosome(Chromosome other) { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. } /** * Returns an integer value that reflects the quality of the * solution. Small negative values are best, larget positive * values indicate solutions with overlapping constituents. The * fitness value of a chromosome is the difference of two terms, * one for the overlapping constituents and the other for the * hydrophobic contacts. The first term is the number of * overlapping constituents times OVERLAP_PENALTY. The * second term is the number of non-contiguous hydrophobic * constituents that are adjacent in the folded chain. E.g. a * solution that has no overlapping constituents and forms two * hydrophobic contacts has a fitness of -2, a solution that has * four overlapping constituents and forms 6 hydrophobic contacts * has a fitness value of 394. * * @return the fitness value of this solution */ public int getFitness() { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. return 0; } /** * With probability CROSSOVER_RATE the method returns a new * Chromosome consisting of a certain number of contiguous genes * from this solution and the rest of the genes coming from * other. Otherwise, the returned solution is a copy of this one. * * @param other the other chromosome that will be used for the crossover * @return a new chromosome resulting from the crossover of this and the * other parent */ public Chromosome crossOver(Chromosome other) { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. return null; } /** * Applies mutations to this chromosome. Each gene of the * chromosome has MUTATION_RATE chances of being mutated. */ public void mutate() { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. } /** * Returns a String representation of this Chromosome. Here is an example. * *
Chromosome [fitness=-2, genes=[Down, Right, Right, Up, Left, Up, Right], chain=hphpphhp]
* * @return the String representation of this Chromosome */ public String toString() { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. return null; } /** Returns the size of this chromosome, which is the number of genes. * * @return returns the size of the chromosome, which is the number of genes. */ public int size() { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. return 0; } /** Returns the value of the gene at the given position of the * chromosome. The first gene is found at position 0. * * @param pos the given position * @return returns the gene at the given position. */ public Move getGene(int pos) { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. return null; } /** Returns the chain of constitents of this chromosome. * * @return returns the chain of constituents. */ public String getChain() { // REPLACE THE BODY OF THIS METHOD WITH YOUR OWN IMPLEMENTATION. return null; } }