Arqueangel
July 23rd, 2009, 03:40 PM
Hello to anyone who decides to help a complete noob :D I have an application that has GALib added as a static library. I run the GA and generate points for plotting in a for loop as shown bellow:
while(!ga.done())
{
// Get the current values from the screen
UpdateData(TRUE);
ga.step();
//CSingleLock lock(&mutex);
//lock.Lock();
if(ga.generation() <= 10)
{
for(int i=0; i<ga.population().size(); i++)
{
genome = ga.population().individual(i);
//convert from float to string
sprintf( floatToString, "%g", genome.fitness());
strcpy (line,floatToString);
strcat (line,"\t");
for(int j=0;j<genome.nPhenotypes();j++)
{
strcat (line,"\t");
sprintf( floatToString, "%g", genome.phenotype(j));
strcat (line,floatToString);
}
strcat (line,"\t");
sprintf( floatToString, "%g", genome.score());
strcat (line,floatToString);
strcat (line,"\n");
//UpdateData(TRUE);
DoBohachevsky2(line, i);
//cout << line;
}
}
//Sleep(100);
//lock.Unlock();
}
// TODO: Add your control notification handler code here
}
The function "DoBohachevsky2(line, i);" basically sends the points over to OpenGL to be plotted. The problem I'm having is that the points are not plotted until the for loop and the while loop ends. I assumed that I would need to do some multithreading to get around this, but I am not quite sure how to do any of this as it is my first time ever. If any genius out there could shed some light as to how to get around this problem that would be great.
while(!ga.done())
{
// Get the current values from the screen
UpdateData(TRUE);
ga.step();
//CSingleLock lock(&mutex);
//lock.Lock();
if(ga.generation() <= 10)
{
for(int i=0; i<ga.population().size(); i++)
{
genome = ga.population().individual(i);
//convert from float to string
sprintf( floatToString, "%g", genome.fitness());
strcpy (line,floatToString);
strcat (line,"\t");
for(int j=0;j<genome.nPhenotypes();j++)
{
strcat (line,"\t");
sprintf( floatToString, "%g", genome.phenotype(j));
strcat (line,floatToString);
}
strcat (line,"\t");
sprintf( floatToString, "%g", genome.score());
strcat (line,floatToString);
strcat (line,"\n");
//UpdateData(TRUE);
DoBohachevsky2(line, i);
//cout << line;
}
}
//Sleep(100);
//lock.Unlock();
}
// TODO: Add your control notification handler code here
}
The function "DoBohachevsky2(line, i);" basically sends the points over to OpenGL to be plotted. The problem I'm having is that the points are not plotted until the for loop and the while loop ends. I assumed that I would need to do some multithreading to get around this, but I am not quite sure how to do any of this as it is my first time ever. If any genius out there could shed some light as to how to get around this problem that would be great.