PostgreSQL Source Code
git master
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
"
35
#include "
optimizer/geqo_mutation.h
"
36
#include "
optimizer/geqo_random.h
"
37
38
#if defined(CX)
/* currently used only in CX mode */
39
40
void
41
geqo_mutation
(
PlannerInfo
*root,
Gene
*tour,
int
num_gene)
42
{
43
int
swap1;
44
int
swap2;
45
int
num_swaps =
geqo_randint
(root, num_gene / 3, 0);
46
Gene
temp;
47
48
49
while
(num_swaps > 0)
50
{
51
swap1 =
geqo_randint
(root, num_gene - 1, 0);
52
swap2 =
geqo_randint
(root, num_gene - 1, 0);
53
54
while
(swap1 == swap2)
55
swap2 =
geqo_randint
(root, num_gene - 1, 0);
56
57
temp = tour[swap1];
58
tour[swap1] = tour[swap2];
59
tour[swap2] = temp;
60
61
62
num_swaps -= 1;
63
}
64
}
65
66
#endif
/* defined(CX) */
geqo_mutation.h
geqo_randint
#define geqo_randint(root, upper, lower)
Definition:
geqo_random.h:38
Gene
int Gene
Definition:
geqo_gene.h:30
geqo_mutation
void geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
PlannerInfo
Definition:
relation.h:154
geqo_random.h
postgres.h
src
backend
optimizer
geqo
geqo_mutation.c
Generated on Mon Apr 23 2018 06:13:16 for PostgreSQL Source Code by
1.8.13