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.h
"
36
37
#if defined(CX)
/* currently used only in CX mode */
38
39
#include "
optimizer/geqo_mutation.h
"
40
#include "
optimizer/geqo_random.h
"
41
42
void
43
geqo_mutation
(
PlannerInfo
*
root
,
Gene
*tour,
int
num_gene)
44
{
45
int
swap1;
46
int
swap2;
47
int
num_swaps =
geqo_randint
(
root
, num_gene / 3, 0);
48
Gene
temp;
49
50
51
while
(num_swaps > 0)
52
{
53
swap1 =
geqo_randint
(
root
, num_gene - 1, 0);
54
swap2 =
geqo_randint
(
root
, num_gene - 1, 0);
55
56
while
(swap1 == swap2)
57
swap2 =
geqo_randint
(
root
, num_gene - 1, 0);
58
59
temp = tour[swap1];
60
tour[swap1] = tour[swap2];
61
tour[swap2] = temp;
62
63
64
num_swaps -= 1;
65
}
66
}
67
68
#endif
/* defined(CX) */
geqo.h
Gene
int Gene
Definition:
geqo_gene.h:30
geqo_mutation.h
geqo_mutation
void geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
geqo_randint
int geqo_randint(PlannerInfo *root, int upper, int lower)
Definition:
geqo_random.c:36
geqo_random.h
postgres.h
root
tree ctl root
Definition:
radixtree.h:1857
PlannerInfo
Definition:
pathnodes.h:220
src
backend
optimizer
geqo
geqo_mutation.c
Generated on Sat Mar 22 2025 06:13:17 for PostgreSQL Source Code by
1.9.4