tiny_malloc error? Urgent please !!

Pages: 1234
Look at the values of the local variables I posted. They are all inf and nan. The word "range" becomes meaningless with such virtual non-quantities. If the values were normal you would probably be right. But your assumptions turn to shreds when you feed your functions with inf and nan.

Regards
So, the problem is not in Ruleta()... probably it's in other function that assigns values to the vectors, isn't it?

Anyway, what I don't undersantd is why using Ruleta function there are problems, and using the other method (K_Tournament) there aren't, because both of the them use the same data structures... :S
So, here is the best info I can give you.

Set a breakpoint in Problacion.H in Poblacion :: Calcula_Fitness_Poblacion on line 233. However, make sure it triggers only when i == 48 && n_puntos_muestra == 4. To ensure that, either make the breakpoint conditional or create an if block with condition and set the breakpoint inside.

The irregularity comes from individual 48 of the population. Its "fitness" is infinite . This may not be an algorithmic bug. It is caused by float overflow. A few lines below the place where you set the breakpoint the value of the variable t is squared. At one occasion t becomes very big and its square overflows the range of float. Only you can say if very big values are to be expected.

Regards

PS: You can avoid the overflow in a generic way by inserting the following code before the inclusion of your header files:
1
2
3
4
5
...
#define float double
#include "SLP.H"
#include "Individuo.H"
...
I tested the program a dozen times and it seems to work with this modification. In other words, if you substitute float with double in your sources, it may solve your problem. (Usually a typedef in a header is used instead.) You could still check your code though.
OK, I'm going to try it... Where I've got to put this sentence? Only in main.cpp? Or in all files? Thanks again !!
Oh my god ! It seems to work !! :O There's no infinite loop in Ruleta() and no memory error ! I'm going to continue executing and I'll post again if there is any problem ok?

The only thing I see is that K-Torneo always returns de same result, but I'm going to look at it and try to find the problem !

Thanks thanks thanks ! I'm going to make some tests ok? Thanks !
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
Last edited on
It depends. Depends on the value of the argument k.

I mean, suppose you have a sequence 1, 2, 3, 4. Now, if you take randomly three of these four numbers, then only in one case the minimum is going to be different from 1. (Namely, this would be the set {2, 3, 4} with minimum 2.)

You pick random selection and seek the min/max-fit amongst the selected individuals. But if the size of the selection is close enough to the size of the entire population, it would be almost non-random for the purposes of the min and max statistics. Then, it would be normal to have repetitive results. Choose a smaller K (very small, like 1 if possible) and see if the program still fails to randomize.

Regards
It's ok, my projects works now !! Thanks to all, especially to simeonz and Duoas.

Regards
Topic archived. No new replies allowed.
Pages: 1234