i have created many "Vectors" each of this Vectors have his own "Fitness" the fitness is got using a fitness function (already done).
Having for example :
Vector v1 = new Vector();
Vector v2 = new Vector();
V1 = // some data
V2 = // some other data
double fitness1 = fitness(v1);
double fitness2 = fitness(v2);
now i have hundreds of Vectors
and each have it's own fitness, i am trying to create a function called globalbest
which returns the Vector
having the best fitness but am not always getting the best one !! could anyone help me please ? Here is the code :
public Vector globalbest(Vector allPopulation) {
Vector global = new Vector();
double max = 0;
for (int i = 0; i < allPopulation.size(); i++) {
double value = fitness((Vector) allPopulation.get(i));
if (value > max) {
global = (Vector) allPopulation.get(i);
max = value ;
}
}
return global;
}