PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
geqo_ox2.c File Reference
Include dependency graph for geqo_ox2.c:

Go to the source code of this file.

Functions

void ox2 (PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
 

Function Documentation

void ox2 ( PlannerInfo root,
Gene tour1,
Gene tour2,
Gene offspring,
int  num_gene,
City city_table 
)

Definition at line 46 of file geqo_ox2.c.

References geqo_randint, select, City::select_list, and City::used.

Referenced by geqo().

47 {
48  int k,
49  j,
50  count,
51  pos,
52  select,
53  num_positions;
54 
55  /* initialize city table */
56  for (k = 1; k <= num_gene; k++)
57  {
58  city_table[k].used = 0;
59  city_table[k - 1].select_list = -1;
60  }
61 
62  /* determine the number of positions to be inherited from tour1 */
63  num_positions = geqo_randint(root, 2 * num_gene / 3, num_gene / 3);
64 
65  /* make a list of selected cities */
66  for (k = 0; k < num_positions; k++)
67  {
68  pos = geqo_randint(root, num_gene - 1, 0);
69  city_table[pos].select_list = (int) tour1[pos];
70  city_table[(int) tour1[pos]].used = 1; /* mark used */
71  }
72 
73 
74  count = 0;
75  k = 0;
76 
77  /* consolidate the select list to adjacent positions */
78  while (count < num_positions)
79  {
80  if (city_table[k].select_list == -1)
81  {
82  j = k + 1;
83  while ((city_table[j].select_list == -1) && (j < num_gene))
84  j++;
85 
86  city_table[k].select_list = city_table[j].select_list;
87  city_table[j].select_list = -1;
88  count++;
89  }
90  else
91  count++;
92  k++;
93  }
94 
95  select = 0;
96 
97  for (k = 0; k < num_gene; k++)
98  {
99  if (city_table[(int) tour2[k]].used)
100  {
101  offspring[k] = (Gene) city_table[select].select_list;
102  select++; /* next city in the select list */
103  }
104  else
105  /* city isn't used yet, so inherit from tour2 */
106  offspring[k] = tour2[k];
107  }
108 
109 }
#define geqo_randint(root, upper, lower)
Definition: geqo_random.h:38
int Gene
Definition: geqo_gene.h:30
int select_list
#define select(n, r, w, e, timeout)
Definition: win32.h:374