0

all, I am using GAlib in my VC++ MFC project and encountered a Unhandled exception when using GA initialize() function:

Unhandled exception at 0x765b2eec in XMLDOMFromVC.exe: Microsoft C++ exception: _com_error at memory location 0x00f9de10..

This is my code, which followed the examples in the GAlib:

void CGATrainingDlg::OnBnClickedGaTrainButton()
{
// TODO: Add your control notification handler code here
GARealAlleleSetArray alleles2a;
for(int i=0; i<m_nAlleleSetArrayLen; i++)
    alleles2a.add(0, 1, GAAllele::EXCLUSIVE, GAAllele::INCLUSIVE);

GARealGenome genome2a(alleles2a, ObjectiveTrampoline, this);
genome2a.mutator(GARealIncrementalMutator);
genome2a.crossover(GARealOnePointCrossover);

// Now do a genetic algorithm for each one of the genomes that we created.
GASimpleGA ga(genome2a);

// Now that we have the genomes, create a parameter list that will be used for
// all of the genetic algorithms.
GAParameterList params;
GASimpleGA::registerDefaultParameters(params);
params.set(gaNpCrossover, m_dPCross); 
params.set(gaNpMutation, m_dPMut);

if(BST_CHECKED == IsDlgButtonChecked(IDC_GA_CONVERGENCE_RADIO))
{
    params.set(gaNpConvergence, m_fPconv);
    params.set(gaNnConvergence, m_nConv);
    ga.terminator(GAGeneticAlgorithm::TerminateUponConvergence);
}else{
    params.set(gaNnGenerations, m_nGAGen);
}

params.set(gaNpopulationSize, m_nGAPopSize);
params.set(gaNscoreFrequency, m_nScoreFreq);
params.set(gaNflushFrequency, m_nFlushFreq);
params.set(gaNselectScores, (int)GAStatistics::AllScores);

if((m_fPconv == 0 || m_nConv == 0) && m_nGAGen == 0)
{
    AfxMessageBox(_T("You need to specify parameters for GA Terminator"));
    exit(EXIT_FAILURE);
}

ga.parameters(params);
// the following line is where the exception happened
ga.initialize();
/* some other code*/
}

I have been following an example (ex7.C) that use GA initialize(), but do not know what is the cause of this exception, so any idea how to fix this?

cheers

daiyue
  • 7,196
  • 25
  • 82
  • 149
  • Are you linking GALib dynamically? Have you tried to run your program in a debugger and to step into `ga.initialize`? What functions must be called on a `GASimpleGA` between construction and `initialize`? Does `parameters` automatically `initialize`? – Jonas Bötel Feb 25 '14 at 06:49
  • Does `initialize` call `ObjectiveTrampoline`? Set a breakpoint in `ObjectiveTrampoline` to find out. Does that function crash? Are you accessing the passed `this` in that function? – Jonas Bötel Feb 25 '14 at 07:39

0 Answers0