96 int num_gene,
Edge *edge_table)
104 for (
i = 1;
i <= num_gene;
i++)
114 for (index1 = 0; index1 < num_gene; index1++)
121 index2 = (index1 + 1) % num_gene;
128 edge_total +=
gimme_edge(
root, tour1[index1], tour1[index2], edge_table);
131 edge_total +=
gimme_edge(
root, tour2[index1], tour2[index2], edge_table);
136 return ((
float) (edge_total * 2) / (
float) num_gene);
158 int city1 = (int) gene1;
159 int city2 = (int) gene2;
165 for (
i = 0;
i < edges;
i++)
167 if ((
Gene) abs(edge_table[city1].edge_list[
i]) == city2)
178 edge_table[city1].
edge_list[edges] = city2;
199 int edge_failures = 0;
204 for (
i = 1;
i < num_gene;
i++)
211 remove_gene(
root, new_gene[
i - 1], edge_table[(
int) new_gene[
i - 1]], edge_table);
215 if (edge_table[new_gene[
i - 1]].unused_edges > 0)
216 new_gene[
i] =
gimme_gene(
root, edge_table[(
int) new_gene[
i - 1]], edge_table);
226 edge_table[(int) new_gene[
i - 1]].unused_edges = -1;
229 return edge_failures;
255 genes_remaining = edge_table[possess_edge].
unused_edges;
258 for (
j = 0;
j < genes_remaining;
j++)
261 if ((
Gene) abs(edge_table[possess_edge].edge_list[
j]) == gene)
267 edge_table[possess_edge].
edge_list[genes_remaining - 1];
287 int minimum_count = -1;
312 return (
Gene) abs(
friend);
331 if (edge_table[(
int)
friend].unused_edges < minimum_edges)
333 minimum_edges = edge_table[(int)
friend].unused_edges;
336 else if (minimum_count == -1)
338 else if (edge_table[(
int)
friend].unused_edges == minimum_edges)
356 if (minimum_count == rand_decision)
362 elog(
ERROR,
"neither shared nor minimum number nor random edge found");
376 int remaining_edges = 0;
386 for (
i = 1;
i <= num_gene;
i++)
388 if ((edge_table[
i].unused_edges != -1) && (
i != (
int) fail_gene))
392 if (edge_table[
i].total_edges == 4)
407 for (
i = 1;
i <= num_gene;
i++)
410 if ((
Gene)
i != fail_gene &&
411 edge_table[
i].unused_edges != -1 &&
412 edge_table[
i].total_edges == 4)
417 if (rand_decision == four_count)
422 elog(
LOG,
"no edge found via random decision and total_edges == 4");
424 else if (remaining_edges != 0)
429 for (
i = 1;
i <= num_gene;
i++)
432 if ((
Gene)
i != fail_gene &&
433 edge_table[
i].unused_edges != -1)
438 if (rand_decision == remaining_edges)
443 elog(
LOG,
"no edge found via random decision with remaining edges");
457 for (
i = 1;
i <= num_gene;
i++)
458 if (edge_table[
i].unused_edges >= 0)
461 elog(
LOG,
"no edge found via looking for the last unused point");
static int gimme_edge(PlannerInfo *root, Gene gene1, Gene gene2, Edge *edge_table)
float gimme_edge_table(PlannerInfo *root, Gene *tour1, Gene *tour2, int num_gene, Edge *edge_table)
void free_edge_table(PlannerInfo *root, Edge *edge_table)
static Gene gimme_gene(PlannerInfo *root, Edge edge, Edge *edge_table)
int gimme_tour(PlannerInfo *root, Edge *edge_table, Gene *new_gene, int num_gene)
static Gene edge_failure(PlannerInfo *root, Gene *gene, int index, Edge *edge_table, int num_gene)
static void remove_gene(PlannerInfo *root, Gene gene, Edge edge, Edge *edge_table)
Edge * alloc_edge_table(PlannerInfo *root, int num_gene)
int geqo_randint(PlannerInfo *root, int upper, int lower)
if(TABLE==NULL||TABLE_index==NULL)
void pfree(void *pointer)