I have a "population" of objects that is suppose to do a lot of stuff during its lifecycle... I had everything working fine (not fancy code, though) with an array, but now I've received instructions to let the population change size over generations. This means my array no longer works...I want to change it to a vector (or map), keeping the basic structure of the code. But it beats my skills...I read a thread (http://www.thescripts.com/forum/thread452569.html) about something similar (2d vectors), but I didn't quite get it.
Here's part of the code:
- #include <vector>
-
-
#define Ngener 3000
-
#define Nfitgene 2
-
#define popSize 1000
-
-
using namespace std;
-
-
class individual {
-
public:
-
int habgene[2], fitgene[2][Nfitgene];
-
int chromosum() {return habgene[0] + habgene[1];}
-
int chromofitsum (int index) {return fitgene[0][index] + fitgene[1][index];};
-
int chosenHab;
-
int alive;
-
} bicho [popSize];
-
-
int i, j, k, generation = 0;
-
-
//---------------------------------------------------------------
-
int main ()
-
{
-
-
for(i=0; i<popSize; i++)
-
{
-
bicho[i].habgene[0]=binaryPick(freq0_A); /*binaryPick is a function that doesn't matter right now*/
-
bicho[i].habgene[1]=binaryPick(freq0_A);
-
for (j=0; j<Nfitgene; j++)
-
{
-
bicho[i].fitgene[0][j]=binaryPick(fitfreq0_A[j]);
-
bicho[i].fitgene[1][j]=binaryPick(fitfreq0_A[j]);
-
}
-
}
-
/* individuals will survive, reproduce, die and descendants will form a new population*/
-
-
}
please give me some pointers, considering that my C++ knowledge is quite limited.