It seems to continue working... :) Just one thing abusing you... There's any idea for K_Torneo to return always de same result?
The code :
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
|
int Poblacion :: K_Torneo (const int k)
{
double seleccionado;
int k_torneo = k;
int aux;
vector<int> seleccionables (k_torneo);
for (int i = 0; i < k_torneo; i++)
{
aux = (int) population[i].Numeros_Aleatorios_Entre_a_y_b (0, population.size()-1);
seleccionables[i] = aux;
}
vector<double> fitness_seleccionables;
for (int i = 0 ; i < k_torneo; i++)
fitness_seleccionables.push_back (population[seleccionables[i]].fitness) ;
seleccionado = * min_element (fitness_seleccionables.begin(), fitness_seleccionables.end());
for (int i = 0; i < seleccionables.size(); i++)
if (population[seleccionables[i]].fitness == seleccionado)
{
return seleccionables[i];
}
}
|
Is equivalent to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int Poblacion :: K_Torneo (const int k)
{
double seleccionado;
int k_torneo = k;
int aux;
vector<float> fitness_seleccionables;
for (int i = 0; i < k_torneo; i++)
{
aux = (int) population[i].Numeros_Aleatorios_Entre_a_y_b (0, population.size()-1);
fitness_seleccionables.push_back (population[aux].fitness) ;
}
[code]seleccionado = * min_element (fitness_seleccionables.begin(),fitness_seleccionables.end())
|
for (int i = 0; i < population.size(); i++)
if (population[i].fitness == seleccionado)
{
return i;
}
}[/code]
I don't know why, but always happen that, for example, the returned value is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
1
1
1
1
...(for example 100 times)
1
1
35
35
35
... (same times)
35
35
74
74
.... etc
|
So, the result for all the individuals from population is the same:
fitness individual 1 : 0.0225
fitness individual 2 : 0.0225
...
fitness individual n : 0.0225
------
EDIT: the "aux" random generated value is always differente because I've put a breakpoint at that line
EDIT 2 : Doing more tests, I think that the problem is in
seleccionado = * min_element (fitness_seleccionables.begin(),fitness_seleccionables.end())
, but I don't know why always returns the same, because the individuals set is diferent every time