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
44
45/*
46 * ox1
47 *
48 * position crossover
49 */
50void
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) */
int Gene
Definition geqo_gene.h:33
int geqo_randint(PlannerInfo *root, int upper, int lower)
Definition geqo_random.c:35
void ox1(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
static int fb(int x)
tree ctl root
Definition radixtree.h:1857