PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
geqo_mutation.c
Go to the documentation of this file.
1 /*------------------------------------------------------------------------
2 *
3 * geqo_mutation.c
4 *
5 * TSP mutation routines
6 *
7 * src/backend/optimizer/geqo/geqo_mutation.c
8 *
9 *-------------------------------------------------------------------------
10 */
11 
12 /* contributed by:
13  =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
14  * Martin Utesch * Institute of Automatic Control *
15  = = University of Mining and Technology =
16  * utesch@aut.tu-freiberg.de * Freiberg, Germany *
17  =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
18  */
19 
20 /* this is adopted from Genitor : */
21 /*************************************************************/
22 /* */
23 /* Copyright (c) 1990 */
24 /* Darrell L. Whitley */
25 /* Computer Science Department */
26 /* Colorado State University */
27 /* */
28 /* Permission is hereby granted to copy all or any part of */
29 /* this program for free distribution. The author's name */
30 /* and this copyright notice must be included in any copy. */
31 /* */
32 /*************************************************************/
33 
34 #include "postgres.h"
36 #include "optimizer/geqo_random.h"
37 
38 void
39 geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
40 {
41  int swap1;
42  int swap2;
43  int num_swaps = geqo_randint(root, num_gene / 3, 0);
44  Gene temp;
45 
46 
47  while (num_swaps > 0)
48  {
49  swap1 = geqo_randint(root, num_gene - 1, 0);
50  swap2 = geqo_randint(root, num_gene - 1, 0);
51 
52  while (swap1 == swap2)
53  swap2 = geqo_randint(root, num_gene - 1, 0);
54 
55  temp = tour[swap1];
56  tour[swap1] = tour[swap2];
57  tour[swap2] = temp;
58 
59 
60  num_swaps -= 1;
61  }
62 }
#define geqo_randint(root, upper, lower)
Definition: geqo_random.h:38
int Gene
Definition: geqo_gene.h:30
void geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
Definition: geqo_mutation.c:39