// // This chop interprets input channels as a mating pool of parent genotypes // and randomly "mates" them, outputting a new population of offspring // genotypes // // note that mate will always match up parents exactly the same way, // given the same seed, so seed must be changed to randomize pairing // // The first input should contain parent channels to mate. // The second input should contain offspring channels. // The third input contains crossover channels, one for each offspring // which determine how the parents' genes are mixed. // // Each offspring which will have its genes reset to some // combinations of a randomly selected pair of parents #include #pragma help "This chop interprets input channels as a mating pool of parent genotypes and "mates" them, outputting a new population of offspring genotypes." #pragma label seed "Seed" #pragma range seed 1 10000 #pragma label elitism "Elitism" #pragma range elitism 0 1 chop mate(int seed = 1; int elitism = 0) { int num_kids = chnumchan(0); // first input holds offspring channels int num_parents = chnumchan(1); // second input holds parents float tmp1 = 0, find_seed = 3982; int momi = 0, dadi = 0; // if elitism set, let parents live into next gen // so if one of first "num_parents" offspring channels, just copy parent val if ((float)elitism > 0.5 && C < num_parents) { V = chinput(1,C,I); } else { // pick some parents and mate them // choose a mom tmp1 = num_parents*random((C+2)*(seed+92937)); momi = floor(tmp1); dadi = momi; // init to same // if there are other parents, find a dad (must be different from mom!) if(num_parents > 1) { while (dadi==momi) { tmp1 = num_parents*random((C+2)*(seed+find_seed)); dadi = floor(tmp1); find_seed += 1; } } //printf("momi=%g, dadi=%g, C=%g, I=%g\n", momi, dadi, C, I); if(chinput(2,C,I)<0.5) { // if 3rd input's channel is low, use mom's gene V = chinput(1,momi,I); } else { // else if 3rd input's channel is high, use dad's gene V = chinput(1,dadi,I); } } }