PostgreSQL Source Code git master
Loading...
Searching...
No Matches
geqo_recombination.c File Reference
Include dependency graph for geqo_recombination.c:

Go to the source code of this file.

Functions

void init_tour (PlannerInfo *root, Gene *tour, int num_gene)
 

Function Documentation

◆ init_tour()

void init_tour ( PlannerInfo root,
Gene tour,
int  num_gene 
)

Definition at line 35 of file geqo_recombination.c.

36{
37 int i,
38 j;
39
40 /*
41 * We must fill the tour[] array with a random permutation of the numbers
42 * 1 .. num_gene. We can do that in one pass using the "inside-out"
43 * variant of the Fisher-Yates shuffle algorithm. Notionally, we append
44 * each new value to the array and then swap it with a randomly-chosen
45 * array element (possibly including itself, else we fail to generate
46 * permutations with the last city last). The swap step can be optimized
47 * by combining it with the insertion.
48 */
49 if (num_gene > 0)
50 tour[0] = (Gene) 1;
51
52 for (i = 1; i < num_gene; i++)
53 {
54 j = geqo_randint(root, i, 0);
55 /* i != j check avoids fetching uninitialized array element */
56 if (i != j)
57 tour[i] = tour[j];
58 tour[j] = (Gene) (i + 1);
59 }
60}
int Gene
Definition geqo_gene.h:33
int geqo_randint(PlannerInfo *root, int upper, int lower)
Definition geqo_random.c:35
int j
Definition isn.c:78
int i
Definition isn.c:77
static int fb(int x)
tree ctl root
Definition radixtree.h:1857

References fb(), geqo_randint(), i, j, and root.

Referenced by random_init_pool().