PostgreSQL Source Code git master
Loading...
Searching...
No Matches
geqo_selection.c File Reference
#include "postgres.h"
#include <math.h>
#include "optimizer/geqo_copy.h"
#include "optimizer/geqo_random.h"
#include "optimizer/geqo_selection.h"
Include dependency graph for geqo_selection.c:

Go to the source code of this file.

Functions

static int linear_rand (PlannerInfo *root, int pool_size, double bias)
 
void geqo_selection (PlannerInfo *root, Chromosome *momma, Chromosome *daddy, Pool *pool, double bias)
 

Function Documentation

◆ geqo_selection()

void geqo_selection ( PlannerInfo root,
Chromosome momma,
Chromosome daddy,
Pool pool,
double  bias 
)

Definition at line 55 of file geqo_selection.c.

57{
58 int first,
59 second;
60
61 first = linear_rand(root, pool->size, bias);
62 second = linear_rand(root, pool->size, bias);
63
64 /*
65 * Ensure we have selected different genes, except if pool size is only
66 * one, when we can't.
67 */
68 if (pool->size > 1)
69 {
70 while (first == second)
71 second = linear_rand(root, pool->size, bias);
72 }
73
74 geqo_copy(root, momma, &pool->data[first], pool->string_length);
75 geqo_copy(root, daddy, &pool->data[second], pool->string_length);
76}
void geqo_copy(PlannerInfo *root, Chromosome *chromo1, Chromosome *chromo2, int string_length)
Definition geqo_copy.c:47
static int linear_rand(PlannerInfo *root, int pool_size, double bias)
static int fb(int x)
tree ctl root
Definition radixtree.h:1857
int string_length
Definition geqo_gene.h:45
int size
Definition geqo_gene.h:44
Chromosome * data
Definition geqo_gene.h:43

References Pool::data, fb(), geqo_copy(), linear_rand(), root, Pool::size, and Pool::string_length.

Referenced by geqo().

◆ linear_rand()

static int linear_rand ( PlannerInfo root,
int  pool_size,
double  bias 
)
static

Definition at line 89 of file geqo_selection.c.

90{
91 double index; /* index between 0 and pool_size */
92 double max = (double) pool_size;
93
94 /*
95 * geqo_rand() is not supposed to return 1.0, but if it does then we will
96 * get exactly max from this equation, whereas we need 0 <= index < max.
97 * Also it seems possible that roundoff error might deliver values
98 * slightly outside the range; in particular avoid passing a value
99 * slightly less than 0 to sqrt(). If we get a bad value just try again.
100 */
101 do
102 {
103 double sqrtval;
104
105 sqrtval = (bias * bias) - 4.0 * (bias - 1.0) * geqo_rand(root);
106 if (sqrtval > 0.0)
108 index = max * (bias - sqrtval) / 2.0 / (bias - 1.0);
109 } while (index < 0.0 || index >= max);
110
111 return (int) index;
112}
double geqo_rand(PlannerInfo *root)
Definition geqo_random.c:27
Definition type.h:97

References fb(), geqo_rand(), and root.

Referenced by geqo_selection().