1
/*-------------------------------------------------------------------------
4
* linear selection scheme for the genetic query optimizer
6
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
7
* Portions Copyright (c) 1994, Regents of the University of California
9
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_selection.c,v 1.18 2004-12-31 21:59:58 pgsql Exp $
11
*-------------------------------------------------------------------------
15
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
16
* Martin Utesch * Institute of Automatic Control *
17
= = University of Mining and Technology =
18
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
19
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
22
/* this is adopted from D. Whitley's Genitor algorithm */
24
/*************************************************************/
26
/* Copyright (c) 1990 */
27
/* Darrell L. Whitley */
28
/* Computer Science Department */
29
/* Colorado State University */
31
/* Permission is hereby granted to copy all or any part of */
32
/* this program for free distribution. The author's name */
33
/* and this copyright notice must be included in any copy. */
35
/*************************************************************/
41
#include "optimizer/geqo_copy.h"
42
#include "optimizer/geqo_random.h"
43
#include "optimizer/geqo_selection.h"
45
static int linear(int max, double bias);
49
* according to bias described by input parameters,
50
* second genes are selected from the pool
53
geqo_selection(Chromosome *momma, Chromosome *daddy, Pool *pool, double bias)
58
first = (int) linear(pool->size, bias);
59
second = (int) linear(pool->size, bias);
63
while (first == second)
64
second = (int) linear(pool->size, bias);
67
geqo_copy(momma, &pool->data[first], pool->string_length);
68
geqo_copy(daddy, &pool->data[second], pool->string_length);
72
* generates random integer between 0 and input max number
73
* using input linear bias
75
* probability distribution function is: f(x) = bias - 2(bias - 1)x
76
* bias = (prob of first rule) / (prob of middle rule)
81
linear(int pool_size, double bias) /* bias is y-intercept of linear
84
double index; /* index between 0 and pop_size */
85
double max = (double) pool_size;
87
index = max * (bias - sqrt((bias * bias) - 4.0 * (bias - 1.0) * geqo_rand()))