-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndividual.java
More file actions
66 lines (55 loc) · 1.82 KB
/
Copy pathIndividual.java
File metadata and controls
66 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.gava;
import java.util.List;
/** La clase Individual describe al individuo y su aptitud.
* @author Hugo Ivan Piza
*
* @param <G> Genotipo del individuo
* @param <P> Fenotipo del Individuo
*/
public abstract class Individual<G, P> implements Comparable<Individual<G, P>> {
protected Genotype<G> genotype;
protected Phenotype<P> phenotype;
protected double fitness = 0;
/** Actualiza el valor del Fenotipo, según lo encontrado en el genotipo.
*
*/
public abstract void updatePhenotype();
public abstract Individual<G, P> clone();
/** Devuelve el Fenotipo del individuo a manera de una lista.
* @return -Lista con los valores del Fenotipo.
*/
public abstract List<P> getPhenotype();
/** Normaliza la evaluación de la función entre valores de 0 a 1, para atribuirselos a la aptitud (fitness).
* @param objectiveFunction Función con la que se va a normalizar.
* @return -Retorna el valor de la aptitud.
*/
public abstract double normalize(ObjectiveFunction<P> objectiveFunction);
/** Constructor del Individuo
* @param genotype Genotipo del individuo
* @param phenotype Fenotipo del individuo
*/
public Individual(Genotype<G> genotype, Phenotype<P> phenotype) {
this.genotype = genotype;
this.phenotype = phenotype;
updatePhenotype();
}
/** Da el valor de la aptitud del Individuo.
* @param fitness Aptitud del Individuo
*/
public void setFitness(double fitness) {
this.fitness = fitness;
}
/** Regresa la aptitud del individuo
* @return Aptitud del Individuo
*/
public double getFitness() {
return this.fitness;
}
public int compareTo(Individual<G, P> individual2) {
if(this.fitness < individual2.getFitness())
return -1;
if(this.fitness > individual2.getFitness())
return 1;
return 0;
}
}