
toxgene.core.genes.trees.ToxAlternatives Maven / Gradle / Ivy
/**
* Contains a set of alternative elements/attributes.
*
* @author Denilson Barbosa
* @version 0.1
*/
package toxgene.core.genes.trees;
import java.io.PrintStream;
import java.util.Vector;
import toxgene.core.ToXgeneErrorException;
import toxgene.core.genes.ContainerGene;
import toxgene.core.genes.Gene;
import toxgene.core.genes.lists.ListGene;
import toxgene.core.genes.lists.ToxListElement;
import toxgene.core.genes.lists.ToxListElementException;
import toxgene.core.random.ToxRandom;
import toxgene.util.FloatObjectPair;
public class ToxAlternatives implements TreeGene, ContainerGene, ListGene{
private Vector options;
private float mass;
/**
* Pseudo-random number generator
*/
private ToxRandom randomGenerator;
private boolean drawn[];
private FloatObjectPair chosen[];
private int level;
public ToxAlternatives(ToxRandom rand){
level = 0;
options = new Vector();
mass = 0;
randomGenerator = rand;
drawn = new boolean[1];
chosen = new FloatObjectPair[1];
drawn[level] = false;
}
/**
* Resets the gene.
*/
public void reset(){
for (int i=0; i chosen[depth].key()){
i++;
try {
chosen[depth] = (FloatObjectPair) options.get(i);
}
catch (ArrayIndexOutOfBoundsException e){
break;
}
}
drawn[depth] = true;
}
public void addOption(float percent, Gene gene){
mass += percent;
if (mass > 100.0){
throw new ToXgeneErrorException("invalid probability distribution!!!");
}
options.add(new FloatObjectPair(mass, gene));
}
public int numIterators(){
int result = 0;
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy