aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/geqo/geqo_recombination.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/geqo/geqo_recombination.c')
-rw-r--r--src/backend/optimizer/geqo/geqo_recombination.c93
1 files changed, 49 insertions, 44 deletions
diff --git a/src/backend/optimizer/geqo/geqo_recombination.c b/src/backend/optimizer/geqo/geqo_recombination.c
index df175dcb866..53803079819 100644
--- a/src/backend/optimizer/geqo/geqo_recombination.c
+++ b/src/backend/optimizer/geqo/geqo_recombination.c
@@ -1,18 +1,18 @@
/*------------------------------------------------------------------------
*
* geqo_recombination.c--
-* misc recombination procedures
+* misc recombination procedures
*
-* $Id: geqo_recombination.c,v 1.1 1997/02/19 12:57:42 scrappy Exp $
+* $Id: geqo_recombination.c,v 1.2 1997/09/07 04:43:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* contributed by:
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
- * Martin Utesch * Institute of Automatic Control *
- = = University of Mining and Technology =
- * utesch@aut.tu-freiberg.de * Freiberg, Germany *
+ * Martin Utesch * Institute of Automatic Control *
+ = = University of Mining and Technology =
+ * utesch@aut.tu-freiberg.de * Freiberg, Germany *
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
*/
@@ -42,65 +42,70 @@
/*
* init_tour--
*
- * Randomly generates a legal "traveling salesman" tour
- * (i.e. where each point is visited only once.)
- * Essentially, this routine fills an array with all possible
- * points on the tour and randomly chooses the 'next' city from
- * this array. When a city is chosen, the array is shortened
- * and the procedure repeated.
+ * Randomly generates a legal "traveling salesman" tour
+ * (i.e. where each point is visited only once.)
+ * Essentially, this routine fills an array with all possible
+ * points on the tour and randomly chooses the 'next' city from
+ * this array. When a city is chosen, the array is shortened
+ * and the procedure repeated.
*
*/
void
-init_tour(Gene *tour, int num_gene)
+init_tour(Gene * tour, int num_gene)
{
-Gene *tmp;
-int remainder;
-int next, i;
+ Gene *tmp;
+ int remainder;
+ int next,
+ i;
-tmp = (Gene *) palloc (num_gene*sizeof(Gene));
-
-for(i = 0; i < num_gene; i++) {
- tmp[i] = (Gene) i+1; /* builds tours "1 - 2 - 3" etc. */
- }
+ tmp = (Gene *) palloc(num_gene * sizeof(Gene));
-remainder = num_gene - 1;
+ for (i = 0; i < num_gene; i++)
+ {
+ tmp[i] = (Gene) i + 1; /* builds tours "1 - 2 - 3" etc. */
+ }
-for(i = 0; i < num_gene; i++) {
- next = (int) geqo_randint(remainder, 0); /* choose city between 0 and remainder */
- tour[i] = tmp[next];
- tmp[next] = tmp[remainder];
- remainder--;
- }
+ remainder = num_gene - 1;
-pfree(tmp);
-}
+ for (i = 0; i < num_gene; i++)
+ {
+ next = (int) geqo_randint(remainder, 0); /* choose city between 0
+ * and remainder */
+ tour[i] = tmp[next];
+ tmp[next] = tmp[remainder];
+ remainder--;
+ }
+
+ pfree(tmp);
+}
/* alloc_city_table--
*
- * allocate memory for city table
+ * allocate memory for city table
*
*/
-City *
+City *
alloc_city_table(int num_gene)
{
- City *city_table;
+ City *city_table;
- /* palloc one extra location so that nodes numbered
- 1..n can be indexed directly; 0 will not be used */
+ /*
+ * palloc one extra location so that nodes numbered 1..n can be
+ * indexed directly; 0 will not be used
+ */
- city_table = (City *) palloc ((num_gene+1)*sizeof(City));
+ city_table = (City *) palloc((num_gene + 1) * sizeof(City));
- return (city_table);
- }
+ return (city_table);
+}
/* free_city_table--
*
- * deallocate memory of city table
+ * deallocate memory of city table
*
*/
- void
- free_city_table(City *city_table)
- {
- pfree(city_table);
- }
-
+void
+free_city_table(City * city_table)
+{
+ pfree(city_table);
+}