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

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 46 of file geqo_ox1.c.

References geqo_randint, and City::used.

Referenced by geqo().

48 {
49  int left,
50  right,
51  k,
52  p,
53  temp;
54 
55  /* initialize city table */
56  for (k = 1; k <= num_gene; k++)
57  city_table[k].used = 0;
58 
59  /* select portion to copy from tour1 */
60  left = geqo_randint(root, num_gene - 1, 0);
61  right = geqo_randint(root, num_gene - 1, 0);
62 
63  if (left > right)
64  {
65  temp = left;
66  left = right;
67  right = temp;
68  }
69 
70  /* copy portion from tour1 to offspring */
71  for (k = left; k <= right; k++)
72  {
73  offspring[k] = tour1[k];
74  city_table[(int) tour1[k]].used = 1;
75  }
76 
77  k = (right + 1) % num_gene; /* index into offspring */
78  p = k; /* index into tour2 */
79 
80  /* copy stuff from tour2 to offspring */
81  while (k != left)
82  {
83  if (!city_table[(int) tour2[p]].used)
84  {
85  offspring[k] = tour2[p];
86  k = (k + 1) % num_gene;
87  city_table[(int) tour2[p]].used = 1;
88  }
89  p = (p + 1) % num_gene; /* increment tour2-index */
90  }
91 
92 }
#define geqo_randint(root, upper, lower)
Definition: geqo_random.h:38