Freethought & Rationalism ArchiveThe archives are read only. |
07-25-2003, 11:57 AM | #31 |
Senior Member
Join Date: Jun 2000
Location: Houston, Texas
Posts: 932
|
Sweet....that solves one problem I've been having. What I was using wasn't sufficient anymore...
|
07-25-2003, 04:29 PM | #32 |
Junior Member
Join Date: Nov 2001
Location: USA
Posts: 77
|
A lot of my recent work involves revamping and extending some proprietary algorithms so that they act as extensions to the C++ Standard Template Library (STL). So offline, just to work out some ideas, I'm writing a GA/EP template library in C++. To the greatest extent possible, all the definitions and interfaces up and down the chain are based on STL design patterns and interfaces.
Some parts are fairly trivial. For example, iterators are for moving through a population of organisms, fitness functions will work like predicate functors, etc. Other parts are more challenging -- e.g. is it possible to genericize genotype to phenotype mapping so the fitness functions themselves can be parameterized library components? Along the way, I'll try to make sure it's multi-thread, multi-CPU aware, uses custom memory allocation for speed, etc. I'm trying to figure out a really efficient roulette-wheel picker. I also hope to find an efficient way to manage systems where organisms breed continuously as opposed to breeding in cohorts. Endless hours of fun... -Neil |
07-29-2003, 05:48 PM | #33 |
Veteran Member
Join Date: Nov 2001
Location: NCSU
Posts: 5,853
|
Since CX asked, here is some of the core code for the project, from a later version that I am fooling around with.
Code:
int nXoff[4] = {0,1,0,-1}; int nYoff[4] = {1,0,-1,0}; //The Central Loop void CChildView::StepPopulation() { static unsigned int uSpan = (unsigned int)Cell::s_rngExp(20.0); //m_pngSave.Save(); ++m_uGen; bool bUpdate = false; if(uSpan-- == 0u) { Cell::s_cellOptimum.Mutate(1.0); bUpdate = true; uSpan = (unsigned int)(0.5+Cell::s_rngExp(20.0)); } m_dAvgFitness = 0.0; for(int i=0;i<100;++i) { for(int j=0;j<100;++j) { Cell* pCell = &m_arCells[i][j]; m_dAvgFitness += pCell->m_dFitness; if(bUpdate) { pCell->CalcFitness(); m_wndPalMap.SetColor(j,i,(CGdiplusPalMap::PalVal)(32.0*pCell->m_dFitness)); } if(pCell->TryDeath() || pCell->m_uAge == 0) { unsigned int u = Cell::s_rngUint(3); int nX = j+nXoff[u]; int nY = i+nYoff[u]; if(nX < 0 || nX >= 100 || nY < 0 || nY >=100 || m_arCells[nY][nX].m_uAge <= 1) { pCell->m_uAge = 0; m_wndPalMap.SetColor(j,i,33); continue; } pCell->Clone(m_arCells[nY][nX]); m_wndPalMap.SetColor(j,i,(CGdiplusPalMap::PalVal)(32.0*pCell->m_dFitness)); } else { pCell->m_uAge += 1; } } } m_dAvgFitness /= 10000.0; m_pAvgFit->m_data.push_back(PointF(m_uGen, 1.0-m_dAvgFitness)); } |
Thread Tools | Search this Thread |
|