public class Chromosome
extends java.lang.Object
implements java.lang.Comparable
This class represents the chromosome (rule) of the CORE algorithm
Constructor and Description |
---|
Chromosome()
Default constructor.
|
Chromosome(Chromosome c)
Deep-copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addNominalGene(int pos,
Attribute a,
int relation,
java.util.ArrayList<java.lang.String> values)
Adds a nominal gene to this chromosome (rule)
|
void |
addRealBoundedGene(int pos,
Attribute a,
int relation,
double[] value)
Adds a real-valued gene, and sets its bounds
|
void |
addRealGene(int pos,
Attribute a,
int relation,
double value)
Adds a real valued gene
|
int |
compareTo(java.lang.Object o) |
int |
evaluate(double[] input)
Evaluates an input example (array of doubles as extracted from KEEL API)
|
int |
getClas()
Gets the class of this rule
|
int |
getNumGenes()
Gets the number of genes of this chromosome
|
boolean |
isEvaluated()
Gets the evaluation status
|
void |
mutate()
Applies a mutation on this chromosome, adding a gene (0.5 prob) or deleting
one gene (0.5 prob or if this chromosome has genes for all the attributes)
|
void |
mutateGene(int gen)
Applies a random mutation of the specified gene
|
void |
removeGene(Gene gene)
Remove a specific gene from the chromosome, using the Object.equals()
method (must be the SAME object with SAME id)
|
void |
removeGene(int index)
Deletes one gene from the chromosome
|
void |
resetTokens()
Reset the count of captured tokens for this rule in the tokens
competition
|
boolean |
same(Chromosome c)
Test if two chromosomes are equals by comparing their values
|
void |
setClass(int c)
Sets the class of this chromosome
|
void |
setEvaluated(boolean ev)
Set this chromosome as evaluated (fitness computed for the current set of genes) or not
|
void |
setFitness(double fit)
Sets the fitness for this rule
|
void |
swap(Chromosome c,
int cutpoint)
Performs the one-point crossover with other chromosome
|
void |
tokenCaptured()
Increases the amount of captured tokens by 1
|
void |
tokenLost()
Decreases the amount of captured tokens by 1
|
public Chromosome()
Default constructor. No memory allocated.
public Chromosome(Chromosome c)
Deep-copy constructor.
c
- original chromosomepublic void addNominalGene(int pos, Attribute a, int relation, java.util.ArrayList<java.lang.String> values)
Adds a nominal gene to this chromosome (rule)
pos
- Position in which we put the genea
- the attribute related to this gene (nominal!)relation
- the type of the relation which implements the gene (see Gene.java)values
- the nominal values that covers this genepublic void addRealGene(int pos, Attribute a, int relation, double value)
Adds a real valued gene
pos
- Position in which we put the genea
- the attribute related to this gene (real or integer!)relation
- the type of the relation which implements the gene (see Gene.java)value
- the real values that covers this genepublic void addRealBoundedGene(int pos, Attribute a, int relation, double[] value)
Adds a real-valued gene, and sets its bounds
pos
- the position of the gene in the chromosomea
- the attribute related to this gene (real!)relation
- the type of relation (see Gene.java)value
- array of 2 positions, with the minimum bound (position [0]) and maximum bound (position [1])public void removeGene(int index)
Deletes one gene from the chromosome
index
- position of the gene to be deletedpublic void removeGene(Gene gene)
Remove a specific gene from the chromosome, using the Object.equals() method (must be the SAME object with SAME id)
gene
- gene object to be deleted from the chromosomepublic int evaluate(double[] input)
Evaluates an input example (array of doubles as extracted from KEEL API)
input
- the input instancepublic int getNumGenes()
Gets the number of genes of this chromosome
public void mutateGene(int gen)
Applies a random mutation of the specified gene
gen
- index of the gene to be mutatedpublic void mutate()
Applies a mutation on this chromosome, adding a gene (0.5 prob) or deleting one gene (0.5 prob or if this chromosome has genes for all the attributes)
public void setClass(int c)
Sets the class of this chromosome
c
- the new consequent classpublic int getClas()
Gets the class of this rule
public void setEvaluated(boolean ev)
Set this chromosome as evaluated (fitness computed for the current set of genes) or not
ev
- the new evaluation statuspublic boolean isEvaluated()
Gets the evaluation status
public void setFitness(double fit)
Sets the fitness for this rule
fit
- the new fitnesspublic void resetTokens()
Reset the count of captured tokens for this rule in the tokens competition
public void tokenCaptured()
Increases the amount of captured tokens by 1
public void tokenLost()
Decreases the amount of captured tokens by 1
public void swap(Chromosome c, int cutpoint)
Performs the one-point crossover with other chromosome
c
- the chrosomome to be crossed withcutpoint
- the cutpoint of this swapping operationpublic int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public boolean same(Chromosome c)
Test if two chromosomes are equals by comparing their values
c
- the chromosome to be compared with