abc/src/bdd/cudd/cuddGenetic.c
/**Function********************************************************************

  Synopsis    [Selects two parents with the roulette wheel method.]

  Description [Selects two distinct parents with the roulette wheel method.]

  SideEffects [The indices of the selected parents are returned as side
  effects.]

  SeeAlso     []

******************************************************************************/
Function
Synopsis    [Selects two parents with the roulette wheel method.]

Description [Selects two distinct parents with the roulette wheel method.]

SideEffects [The indices of the selected parents are returned as side
effects.]


Function Synopsis [ Selects two parents with the roulette wheel method . ] Description [ Selects two distinct parents with the roulette wheel method . ] SideEffects [ The indices of the selected parents are returned as side effects . ]
static int
roulette(
  int * p1,
  int * p2)
{
    double *wheel;
    double spin;
    int i;
    wheel = ABC_ALLOC(double,popsize);
    if (wheel == NULL) {
        return(0);
    }
    wheel[0] = 1.0 / (double) STOREDD(0,numvars);
    for (i = 1; i < popsize; i++) {
        wheel[i] = wheel[i-1] + 1.0 / (double) STOREDD(i,numvars);
    }
    spin = wheel[numvars-1] * (double) Cudd_Random() / 2147483561.0;
    for (i = 0; i < popsize; i++) {
        if (spin <= wheel[i]) break;
    }
    *p1 = i;
    do {
        spin = wheel[popsize-1] * (double) Cudd_Random() / 2147483561.0;
        for (i = 0; i < popsize; i++) {
            if (spin <= wheel[i]) break;
        }
    } while (i == *p1);
    *p2 = i;
    ABC_FREE(wheel);
    return(1);
}
static int roulette ( int * p1 , int * p2 ) { double * wheel ; double spin ; int i ; wheel = ABC_ALLOC ( double , popsize ) ; if ( wheel == NULL ) { return ( 0 ) ; } wheel [ 0 ] = 1.0 / ( double ) STOREDD ( 0 , numvars ) ; for ( i = 1 ; i < popsize ; i ++ ) { wheel [ i ] = wheel [ i - 1 ] + 1.0 / ( double ) STOREDD ( i , numvars ) ; } spin = wheel [ numvars - 1 ] * ( double ) Cudd_Random ( ) / 2147483561.0 ; for ( i = 0 ; i < popsize ; i ++ ) { if ( spin <= wheel [ i ] ) break ; } * p1 = i ; do { spin = wheel [ popsize - 1 ] * ( double ) Cudd_Random ( ) / 2147483561.0 ; for ( i = 0 ; i < popsize ; i ++ ) { if ( spin <= wheel [ i ] ) break ; } } while ( i == * p1 ) ; * p2 = i ; ABC_FREE ( wheel ) ; return ( 1 ) ; }
Function
Synopsis    [Selects two parents with the roulette wheel method.]
Function Synopsis [ Selects two parents with the roulette wheel method . ]
/* The fitness of an individual is the reciprocal of its size. */ /* Get a random number between 0 and wheel[popsize-1] (that is,
    ** the sum of all fitness values. 2147483561 is the largest number
    ** returned by Cudd_Random.
    */ /* Find the lucky element by scanning the wheel. */ /* Repeat the process for the second parent, making sure it is
    ** distinct from the first.
    */