#include "postgres.h"#include <math.h>#include "optimizer/geqo_copy.h"#include "optimizer/geqo_random.h"#include "optimizer/geqo_selection.h"
Go to the source code of this file.
Functions | |
| static int | linear_rand (PlannerInfo *root, int max, double bias) |
| void | geqo_selection (PlannerInfo *root, Chromosome *momma, Chromosome *daddy, Pool *pool, double bias) |
| void geqo_selection | ( | PlannerInfo * | root, | |
| Chromosome * | momma, | |||
| Chromosome * | daddy, | |||
| Pool * | pool, | |||
| double | bias | |||
| ) |
Definition at line 54 of file geqo_selection.c.
References Pool::data, geqo_copy(), linear_rand(), Pool::size, and Pool::string_length.
Referenced by geqo().
{
int first,
second;
first = linear_rand(root, pool->size, bias);
second = linear_rand(root, pool->size, bias);
/*
* Ensure we have selected different genes, except if pool size is only
* one, when we can't.
*
* This code was observed to hang up in an infinite loop when the
* platform's implementation of erand48() was broken. We now always use
* our own version.
*/
if (pool->size > 1)
{
while (first == second)
second = linear_rand(root, pool->size, bias);
}
geqo_copy(root, momma, &pool->data[first], pool->string_length);
geqo_copy(root, daddy, &pool->data[second], pool->string_length);
}
| static int linear_rand | ( | PlannerInfo * | root, | |
| int | max, | |||
| double | bias | |||
| ) | [static] |
Definition at line 92 of file geqo_selection.c.
References geqo_rand().
Referenced by geqo_selection().
{
double index; /* index between 0 and pop_size */
double max = (double) pool_size;
/*
* If geqo_rand() returns exactly 1.0 then we will get exactly max from
* this equation, whereas we need 0 <= index < max. Also it seems
* possible that roundoff error might deliver values slightly outside the
* range; in particular avoid passing a value slightly less than 0 to
* sqrt(). If we get a bad value just try again.
*/
do
{
double sqrtval;
sqrtval = (bias * bias) - 4.0 * (bias - 1.0) * geqo_rand(root);
if (sqrtval > 0.0)
sqrtval = sqrt(sqrtval);
index = max * (bias - sqrtval) / 2.0 / (bias - 1.0);
} while (index < 0.0 || index >= max);
return (int) index;
}
1.7.1