1
/*------------------------------------------------------------------------
4
* misc recombination procedures
6
* src/backend/optimizer/geqo/geqo_recombination.c
8
*-------------------------------------------------------------------------
12
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
13
* Martin Utesch * Institute of Automatic Control *
14
= = University of Mining and Technology =
15
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
16
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
19
/* -- parts of this are adapted from D. Whitley's Genitor algorithm -- */
23
#include "optimizer/geqo_random.h"
24
#include "optimizer/geqo_recombination.h"
30
* Randomly generates a legal "traveling salesman" tour
31
* (i.e. where each point is visited only once.)
32
* Essentially, this routine fills an array with all possible
33
* points on the tour and randomly chooses the 'next' city from
34
* this array. When a city is chosen, the array is shortened
35
* and the procedure repeated.
38
init_tour(PlannerInfo *root, Gene *tour, int num_gene)
45
/* Fill a temp array with the IDs of all not-yet-visited cities */
46
tmp = (Gene *) palloc(num_gene * sizeof(Gene));
48
for (i = 0; i < num_gene; i++)
49
tmp[i] = (Gene) (i + 1);
51
remainder = num_gene - 1;
53
for (i = 0; i < num_gene; i++)
55
/* choose value between 0 and remainder inclusive */
56
next = geqo_randint(root, remainder, 0);
57
/* output that element of the tmp array */
60
tmp[next] = tmp[remainder];
69
* allocate memory for city table
72
alloc_city_table(PlannerInfo *root, int num_gene)
77
* palloc one extra location so that nodes numbered 1..n can be indexed
78
* directly; 0 will not be used
80
city_table = (City *) palloc((num_gene + 1) * sizeof(City));
87
* deallocate memory of city table
90
free_city_table(PlannerInfo *root, City *city_table)