 # Genetic Algorithm

Hello I’ve homework and I need help.  I’ve created a 20x20 array of 0 and 1s and I’ve counted how many 1s in a row. After this stage, I could not progress. Please help me:)
I want to pick two random row and compare and whichever is have more 1 it will be selected like a tournoment selection. I want this step to be repeated twice.
After this step I want to crossover two chromosomes and I want to get a new chromosome.

``````#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define SIZE 20

void init(int a[SIZE][SIZE], int sum[SIZE]);
void dump(int a[SIZE][SIZE], int sum[SIZE]);

int main()
{
int a[SIZE][SIZE];
int sum[SIZE];
init(a, sum);
dump(a, sum);
return 0;
}

void init(int a[SIZE][SIZE], int sum[SIZE])
{
srand(time(NULL));
int i,j;
for (i=0; i<SIZE; ++i)
{
sum[i] = 0;
for(j=0; j<SIZE; ++j)
{
a[i][j] = rand() % 2;
sum[i] += a[i][j];
}
}
}
void dump(int a[SIZE][SIZE], int sum[SIZE])
{
int i,j;
for (i=0; i<SIZE; ++i)
{
for(j=0; j<SIZE; ++j)
printf("% 2d", a[i][j]);
printf(" sum = %d\n", sum[i]);
}
}
``````