#include "postgres.h"#include "optimizer/geqo_random.h"#include "optimizer/geqo_recombination.h"
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) |
| 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 geqo().
{
int num_positions;
int i,
pos,
tour2_index,
offspring_index;
/* initialize city table */
for (i = 1; i <= num_gene; i++)
city_table[i].used = 0;
/* choose random positions that will be inherited directly from parent */
num_positions = geqo_randint(root, 2 * num_gene / 3, num_gene / 3);
/* choose random position */
for (i = 0; i < num_positions; i++)
{
pos = geqo_randint(root, num_gene - 1, 0);
offspring[pos] = tour1[pos]; /* transfer cities to child */
city_table[(int) tour1[pos]].used = 1; /* mark city used */
}
tour2_index = 0;
offspring_index = 0;
/* px main part */
while (offspring_index < num_gene)
{
/* next position in offspring filled */
if (!city_table[(int) tour1[offspring_index]].used)
{
/* next city in tour1 not used */
if (!city_table[(int) tour2[tour2_index]].used)
{
/* inherit from tour1 */
offspring[offspring_index] = tour2[tour2_index];
tour2_index++;
offspring_index++;
}
else
{ /* next city in tour2 has been used */
tour2_index++;
}
}
else
{ /* next position in offspring is filled */
offspring_index++;
}
}
}
1.7.1