/* Appendix A - Eugenic Simulation Program */ /* Compiled and tested with Borland Turbo C */ #include #include #include #define FALSE 0 #define TRUE 1 /* global variables */ float NN, NU, UU; /* current frequency of genotypes, normalized to one */ float NN_new, NU_new, UU_new; /*Temporary new generation frequency values */ float NN_surv, NU_surv, UU_surv; /* Survival rate to child bearing age. */ float nkids = 3.; /* Assumed no. of kids per family */ float nkids_bc = 2.3125; /* Number of kids in NU<>NU marriages with birth control*/ float nkids_NU_NU; /* Number of kids in NU<>NU marriages (computed) */ float sum, test, testp; /* Temporary variables to normalize and test.*/ float criterion = .0001; /* criterion of convergence, may be changed by user*/ float freq[4]; /* frequencies for NU<>NU marriages*/ int eugenics; /* type of eugenics, see input */ int not_enough_NN; /* Not enough NN to marry all NU */ float UUabort; /* number of UU abortions required for eugenics */ int j; /* Generation counter*/ /* Output routine: */ void output_results() { /* Convert to occurances per 10,000 */ NN = NN*10000.; NU = NU*10000.; UU = UU*10000.; UUabort = UUabort*10000.; /* Print the results */ printf("%10d %10.0f %10.0f %10.0f %10.0f\n",j, NN, NU, UU, UUabort); } /* Main Program */ void main() { for (;;){ /*This loop permits multiple cases to be run*/ /* Begin input*/ printf("\n\n%s\n", " Read in frequencies of the NN, NU & UU genotypes: "); scanf("%f %f %f", &NN, &NU, &UU); if (NN < 0. || NU < 0. || UU < 0.)break; printf("%8.4f %8.4f %8.4f\n",NN, NU, UU); /* (Negative numbers cause program exit) */ printf("%s\n", " Read in survival rates of NN, NU and UU genotypes: "); scanf("%f %f %f", &NN_surv, &NU_surv, &UU_surv); printf("%8.4f %8.4f %8.4f\n",NN_surv, NU_surv, UU_surv); eugenics = 0; /* Eugenics computed only when UU has no survival rate.*/ if (UU_surv == 0) { printf("%s\n", "Eugenics? None=0, Birth Cntrl=1, Abort=2, Counsel=3"); scanf("%d",&eugenics); printf(" Chosen eugenics is: %d\n",eugenics); } /* Initialize data*/ testp = -1.; /* Garbage, no previous value for this variable at this time.*/ if (eugenics == 2) { /* NU<>NU offspring frequencies under assumption of abortion eugenics */ freq[0] = .333333; freq[1] = .666667; freq[2] = .0; freq[3] = .333333; }else{ /* Frequencies if no abortion eugenics (Mendellian Law). */ freq[0] = .25; freq[1] = .5; freq[2] = .25; freq[3] = 0.; } /* Decide the no. of kids in NU<>NU marriages with or without birth control. */ nkids_NU_NU = nkids; if (eugenics == 1) nkids_NU_NU = nkids_bc; /* Normalize frequency data. This takes population increases (declines) out of the simulation.) */ sum = NN + NU + UU; NN = NN/sum; NU = NU/sum; UU = UU/sum; /* Output header. */ printf("\n%s %s", "Generation NN/10000 NU/10000 UU/10000", "Aborts/10000\n"); /* Begin generation loop, limit to 32000 generations. */ for (j=1; j<=32000; j++){ not_enough_NN = FALSE; /* Special code for counseling */ if ((eugenics == 3) && (NN < NU)){ not_enough_NN = TRUE; break; /* Not enough NN people to go around for NU */ } /* Introduce survival rates to child bearing age. Also implied in this number is the willingness and ability to produce children. */ NN = NN*NN_surv; NU = NU*NU_surv; UU = UU*UU_surv; /* Initialize new generation frequencies */ NN_new = 0.; NU_new = 0.; UU_new = 0.; UUabort= 0.; /* Compute results for NN<>NN marriages. */ if (eugenics != 3){ NN_new = NN_new + NN*NN *nkids; }else{ NN_new = NN_new + (NN-NU) *nkids; /* Under eugenics == 3, NN<>NN marriages are allowed only when all of the NU individuals have married NN individuals. */ } /* Compute results for NN<>NU marriages. */ if (eugenics != 3){ NN_new = NN_new + NN*NU *nkids; NU_new = NU_new + NN*NU *nkids; }else{ NN_new = NN_new + NU *nkids; NU_new = NU_new + NU *nkids; /* Under eugenics == 3 the NU individuals must marry an equal number of NN individuals. Therefore the frequency of NN<>NU marriages is NU. */ } /* Compute results for NN<>UU marriages. */ NU_new = NU_new + 2.*NN*UU *nkids; /* Compute results for NU<>NU marriages. */ if (eugenics != 3){ /*( No calculations if eugenics = 3) */ NN_new = NN_new + freq[0]*NU*NU *nkids_NU_NU; NU_new = NU_new + freq[1]*NU*NU *nkids_NU_NU; UU_new = UU_new + freq[2]*NU*NU *nkids_NU_NU; /* (Number-of-kids modified if eugenics == 1.) */ UUabort = UUabort + freq[3]*NU*NU*nkids_NU_NU; /* (Num. of required abortions if eugenics==2.) */ } /* Compute results for NU<>UU marriages. */ NU_new = NU_new + NU*UU *nkids; UU_new = UU_new + NU*UU *nkids; /* Compute results for UU<>UU marriages. */ UU_new = UU_new + UU*UU *nkids; /* update new generation and normalize. */ sum = NN_new + NU_new + UU_new; NN = NN_new/sum; NU = NU_new/sum; UU = UU_new/sum; UUabort = UUabort/sum; if (j == 1) output_results(); /* Test convergence. */ if (not_enough_NN == 1)break; test = UU; if (eugenics == 2) test = UUabort; if (eugenics == 3) test = NU; if ((test < criterion) || (fabs((testp-test)/test) < .1*criterion)) break; testp = test; /* Save value for next loop. */ } j--; output_results(); if (j >= 32000)printf("No convergence!\n"); if (not_enough_NN == TRUE) printf ("Not enough NN to go around"); } } /* Sample Input (Used in Appendix B) This may be put into a separate text file, (e. g. input.txt), and redirected to the input stream (i. e.