/* Name: Asif Rashid */ /* McGill ID: 260268820 */ /* Course: Computers in Engineering */ /* Assignement: A4 */ # include # include # include int main() { int x, y, i, j; int elite[5]; // the first row is taken to be elite int specpool[6][5]; // 6 rows of 5 numbers each (pool of 6 specimens, each with 5 chromosomes) int cycle; // reproduction cycle srand((unsigned) time(NULL)); // s stands for seed /* Read number of cycles */ printf("Please type in the number of reproduction cycles to be carried out\n"); scanf("%i" , &cycle); printf("\n %i \n", cycle); printf("\n\n"); // Just to give the program a good look /* Initial values for each specimen are randomly generated integers, between 00 and 99. They are random as they are based on the time that this code is compiled. */ for(i=0;i<6; i++){ // i taken first as C is row major for(j=0;j<5; j++){ y = 100*rand()/(RAND_MAX+1); // This gives us the random integer for each chromosome spot specpool[i][j] = y; } } /* Random integers for the elite specimen*/ for(j=0;j<5; j++){ elite[j]= specpool[0][j]; // I spot is zero as it is the first column } /* Print the Elite specimen */ printf("Your randomly selected elite specimen is: "); for(j=0;j<5;j++){ printf("%i|", elite[j]); } printf("\n\n"); // Just to give the program a good look /* Print the other pools with their specimens */ printf("Original Pool\n"); for(i=0;i<6; i++){ printf("Specimen #%i: ", i+1, i+1); for(j=0;j<5; j++){ printf("%i|", pool[i][j]); } printf("\n\n"); // Just to give the program a good look } /*Mix specimen with other specimens*/ for(x=0; x < cycle;x++){ printf("Cycle #%i\n",x+1); for(i=1; i < 6; i++){ printf("Specimen #%i: ", i+1); for(j=0; j < 5; j++){ y = (int)rand()/RAND_MAX; if (y == 1){ pool[i][j]= elite[j];} printf("%i|", pool[i][j]); } printf("\n"); } } return 0; }