PostgreSQL Source Code
git master
Loading...
Searching...
No Matches
geqo_px.c
Go to the documentation of this file.
1
/*------------------------------------------------------------------------
2
*
3
* geqo_px.c
4
*
5
* position crossover [PX] routines;
6
* PX operator according to Syswerda
7
* (The Genetic Algorithms Handbook, L Davis, ed)
8
*
9
* src/backend/optimizer/geqo/geqo_px.c
10
*
11
*-------------------------------------------------------------------------
12
*/
13
14
/*
15
* contributed by:
16
* =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
17
* * Martin Utesch * Institute of Automatic Control *
18
* = = University of Mining and Technology =
19
* * utesch@aut.tu-freiberg.de * Freiberg, Germany *
20
* =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
21
*/
22
23
/* the px algorithm is adopted from Genitor : */
24
/*************************************************************/
25
/* */
26
/* Copyright (c) 1990 */
27
/* Darrell L. Whitley */
28
/* Computer Science Department */
29
/* Colorado State University */
30
/* */
31
/* Permission is hereby granted to copy all or any part of */
32
/* this program for free distribution. The author's name */
33
/* and this copyright notice must be included in any copy. */
34
/* */
35
/*************************************************************/
36
37
#include "
postgres.h
"
38
#include "
optimizer/geqo.h
"
39
40
#if defined(PX)
41
42
#include "
optimizer/geqo_random.h
"
43
#include "
optimizer/geqo_recombination.h
"
44
45
/*
46
* px
47
*
48
* position crossover
49
*/
50
void
51
px
(
PlannerInfo
*
root
,
Gene
*
tour1
,
Gene
*
tour2
,
Gene
*
offspring
,
int
num_gene
,
52
City
*
city_table
)
53
{
54
int
num_positions
;
55
int
i
,
56
pos,
57
tour2_index
,
58
offspring_index
;
59
60
/* initialize city table */
61
for
(
i
= 1;
i
<=
num_gene
;
i
++)
62
city_table
[
i
].used = 0;
63
64
/* choose random positions that will be inherited directly from parent */
65
num_positions
=
geqo_randint
(
root
, 2 *
num_gene
/ 3,
num_gene
/ 3);
66
67
/* choose random position */
68
for
(
i
= 0;
i
<
num_positions
;
i
++)
69
{
70
pos =
geqo_randint
(
root
,
num_gene
- 1, 0);
71
72
offspring
[pos] =
tour1
[pos];
/* transfer cities to child */
73
city_table
[(
int
)
tour1
[pos]].used = 1;
/* mark city used */
74
}
75
76
tour2_index
= 0;
77
offspring_index
= 0;
78
79
80
/* px main part */
81
82
while
(
offspring_index
<
num_gene
)
83
{
84
85
/* next position in offspring filled */
86
if
(!
city_table
[(
int
)
tour1
[
offspring_index
]].used)
87
{
88
89
/* next city in tour1 not used */
90
if
(!
city_table
[(
int
)
tour2
[
tour2_index
]].used)
91
{
92
93
/* inherit from tour1 */
94
offspring
[
offspring_index
] =
tour2
[
tour2_index
];
95
96
tour2_index
++;
97
offspring_index
++;
98
}
99
else
100
{
/* next city in tour2 has been used */
101
tour2_index
++;
102
}
103
}
104
else
105
{
/* next position in offspring is filled */
106
offspring_index
++;
107
}
108
}
109
}
110
111
#endif
/* defined(PX) */
geqo.h
Gene
int Gene
Definition
geqo_gene.h:33
geqo_randint
int geqo_randint(PlannerInfo *root, int upper, int lower)
Definition
geqo_random.c:35
geqo_random.h
geqo_recombination.h
px
void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
i
int i
Definition
isn.c:77
postgres.h
fb
static int fb(int x)
Definition
preproc-init.c:92
root
tree ctl root
Definition
radixtree.h:1857
City
Definition
geqo_recombination.h:64
PlannerInfo
Definition
pathnodes.h:303
src
backend
optimizer
geqo
geqo_px.c
Generated on Sat May 30 2026 02:13:12 for PostgreSQL Source Code by
1.9.8