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

Go to the source code of this file.

Functions

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

Function Documentation

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

Definition at line 46 of file geqo_px.c.

References geqo_randint, i, and City::used.

Referenced by byteapos(), geqo(), and interpret_function_parameter_list().

48 {
49  int num_positions;
50  int i,
51  pos,
52  tour2_index,
53  offspring_index;
54 
55  /* initialize city table */
56  for (i = 1; i <= num_gene; i++)
57  city_table[i].used = 0;
58 
59  /* choose random positions that will be inherited directly from parent */
60  num_positions = geqo_randint(root, 2 * num_gene / 3, num_gene / 3);
61 
62  /* choose random position */
63  for (i = 0; i < num_positions; i++)
64  {
65  pos = geqo_randint(root, num_gene - 1, 0);
66 
67  offspring[pos] = tour1[pos]; /* transfer cities to child */
68  city_table[(int) tour1[pos]].used = 1; /* mark city used */
69  }
70 
71  tour2_index = 0;
72  offspring_index = 0;
73 
74 
75  /* px main part */
76 
77  while (offspring_index < num_gene)
78  {
79 
80  /* next position in offspring filled */
81  if (!city_table[(int) tour1[offspring_index]].used)
82  {
83 
84  /* next city in tour1 not used */
85  if (!city_table[(int) tour2[tour2_index]].used)
86  {
87 
88  /* inherit from tour1 */
89  offspring[offspring_index] = tour2[tour2_index];
90 
91  tour2_index++;
92  offspring_index++;
93  }
94  else
95  { /* next city in tour2 has been used */
96  tour2_index++;
97  }
98 
99  }
100  else
101  { /* next position in offspring is filled */
102  offspring_index++;
103  }
104 
105  }
106 
107 }
#define geqo_randint(root, upper, lower)
Definition: geqo_random.h:38
int i