home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
APR94_1.ZIP
/
GA.ZIP
/
SOURCE.ZIP
/
GRAPHGA.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-10
|
3KB
|
108 lines
//Copyright (C) Man Machine Interfaces 1994. All rights reserved.
//graphga.h
#include "stdafx.h"
//Headers needed for EOS programs
//You need EOS v1.1 to compile this code
#include "eos.h"
#include "geno.h"
#include "basicga.h"
#include "nptxgeno.h"
#include "genrepop.h"
#include "gaenviro.h"
//headers specific to graph GA
#include "gdriver.h"
#include "graphga.h"
#include "graphind.h"
#include "grphphen.h"
#include "wmatrix.h"
CGraphDrawerGA::CGraphDrawerGA(CGAGraphDriver &driver)
: m_Driver(driver)
{
}
//print out GA generation stats when testing
void CGraphDrawerGA::Report(uint gen)
{
#ifdef STANDALONE_TEST
printf("================================ GENERATION %d ==============================\n",gen) ;
ulong size = m_pPopulation->GetSize() ;
for (uint i = 0; i <size; i++) {
PTBinaryIndividual pIndiv ;
pIndiv = (PTBinaryIndividual) m_pPopulation->GetParent(i) ;
printf("%g\n",pIndiv->GetFitness()) ;
}
printf("Sum: %6.4g, Min: %6.4g, Max: %6.4g, Avg: %6.4g\n\n",
m_pEnvironment->SumFitness,
m_pEnvironment->MinFitness,
m_pEnvironment->MaxFitness,
m_pEnvironment->SumFitness/size) ;
#endif //STANDALONE_TEST
}
//Create the population of individuals
//We use 2 Point Crossover and Elitism
void CGraphDrawerGA::CreatePopulation(long size, PTIndividual prototype)
{
PTNPtCrossGenotype pGeno = new TNPtCrossGenotype(m_Driver.CalcChromosomeLength(),1,2) ;
CGraphDrawingPheno * pPheno = new CGraphDrawingPheno(m_Driver,m_Driver.GetWidth(),m_Driver.GetHeight()) ;
CGraphDrawingInd indiv(pGeno,pPheno);
m_pPopulation = new TGenReplacePopulation(size,&indiv) ;
m_pPopulation->SetElitism(2) ;
}
//print out GA exit stats when testing
void CGraphDrawerGA::ExitReport()
{
m_Driver.m_pBest = m_pEnvironment->GlobalFittestIndivid ;
m_Driver.m_pWorst = m_pEnvironment->GlobalWorstIndivid ;
#ifdef STANDALONE_TEST
double fitness ;
PTIndividual pIndiv = FittestIndividual(fitness) ;
pIndiv->Decode() ; //because TFinancialStrategy::Copy() does not build pheno info for performance
CWordMatrix *pGrid ;
pIndiv->GetPhenoInfo(&pGrid) ;
int numRows = pGrid->GetNumRows() ;
int numCols = pGrid->GetNumCols() ;
for (int row=0; row<numRows; row++) {
for (int col=0; col<numCols; col++) {
printf("%u ",pGrid->GetAt(row,col)) ;
}
printf("\n") ;
}
printf("%g\n",fitness) ;
WORD numNodes = m_Driver.GetNumNodes() ;
for (WORD node1=1;node1<=numNodes;node1++)
for (WORD node2=1;node2<=numNodes;node2++)
if (node1 != node2 && m_Driver.Connected(node1,node2))
printf("Node(%u) --> Node(%u)\n",node1,node2) ;
#endif //STANDALONE_TEST
}
//allow for windows processing!
void CGraphDrawerGA::InterGeneration(ulong, PTIndividual, PTIndividual, PTIndividual, PTIndividual)
{
MSG msg ; //MSW message struct
while (PeekMessage(&msg,AfxGetApp()->m_pMainWnd->m_hWnd,0,0,PM_REMOVE)) { //while there are msgs for status window
TranslateMessage(&msg) ;
DispatchMessage(&msg) ;
}
// SetCursor(LoadCursor(NULL, IDC_WAIT));
}
BOOL CGraphDrawerGA::Stop()
{
return m_Driver.m_Stop ;
}