PostgreSQL Source Code
git master
Loading...
Searching...
No Matches
geqo_ox1.c
Go to the documentation of this file.
1
/*------------------------------------------------------------------------
2
*
3
* geqo_ox1.c
4
*
5
* order crossover [OX] routines;
6
* OX1 operator according to Davis
7
* (Proc Int'l Joint Conf on AI)
8
*
9
* src/backend/optimizer/geqo/geqo_ox1.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 ox 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(OX1)
41
42
#include "
optimizer/geqo_random.h
"
43
#include "
optimizer/geqo_recombination.h
"
44
45
/*
46
* ox1
47
*
48
* position crossover
49
*/
50
void
51
ox1
(
PlannerInfo
*
root
,
Gene
*
tour1
,
Gene
*
tour2
,
Gene
*
offspring
,
int
num_gene
,
52
City
*
city_table
)
53
{
54
int
left,
55
right,
56
k,
57
p,
58
temp
;
59
60
/* initialize city table */
61
for
(k = 1; k <=
num_gene
; k++)
62
city_table
[k].used = 0;
63
64
/* select portion to copy from tour1 */
65
left =
geqo_randint
(
root
,
num_gene
- 1, 0);
66
right =
geqo_randint
(
root
,
num_gene
- 1, 0);
67
68
if
(left > right)
69
{
70
temp
= left;
71
left = right;
72
right =
temp
;
73
}
74
75
/* copy portion from tour1 to offspring */
76
for
(k = left; k <= right; k++)
77
{
78
offspring
[k] =
tour1
[k];
79
city_table
[(
int
)
tour1
[k]].used = 1;
80
}
81
82
k = (right + 1) %
num_gene
;
/* index into offspring */
83
p = k;
/* index into tour2 */
84
85
/* copy stuff from tour2 to offspring */
86
while
(k != left)
87
{
88
if
(!
city_table
[(
int
)
tour2
[p]].used)
89
{
90
offspring
[k] =
tour2
[p];
91
k = (k + 1) %
num_gene
;
92
city_table
[(
int
)
tour2
[p]].used = 1;
93
}
94
p = (p + 1) %
num_gene
;
/* increment tour2-index */
95
}
96
}
97
98
#endif
/* defined(OX1) */
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
ox1
void ox1(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
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_ox1.c
Generated on Fri May 29 2026 19:13:12 for PostgreSQL Source Code by
1.9.8