PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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)
 
Cityalloc_city_table (PlannerInfo *root, int num_gene)
 
void free_city_table (PlannerInfo *root, City *city_table)
 

Function Documentation

City* alloc_city_table ( PlannerInfo root,
int  num_gene 
)

Definition at line 66 of file geqo_recombination.c.

References palloc().

Referenced by geqo().

67 {
68  City *city_table;
69 
70  /*
71  * palloc one extra location so that nodes numbered 1..n can be indexed
72  * directly; 0 will not be used
73  */
74  city_table = (City *) palloc((num_gene + 1) * sizeof(City));
75 
76  return city_table;
77 }
struct City City
void * palloc(Size size)
Definition: mcxt.c:891
void free_city_table ( PlannerInfo root,
City city_table 
)

Definition at line 84 of file geqo_recombination.c.

References pfree().

Referenced by geqo().

85 {
86  pfree(city_table);
87 }
void pfree(void *pointer)
Definition: mcxt.c:992
void init_tour ( PlannerInfo root,
Gene tour,
int  num_gene 
)

Definition at line 34 of file geqo_recombination.c.

References geqo_randint, and i.

Referenced by random_init_pool().

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