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
44
45/*
46 * px
47 *
48 * position crossover
49 */
50void
53{
54 int num_positions;
55 int i,
56 pos,
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 */
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;
78
79
80 /* px main part */
81
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 */
95
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 */
107 }
108 }
109}
110
111#endif /* defined(PX) */
int Gene
Definition geqo_gene.h:33
int geqo_randint(PlannerInfo *root, int upper, int lower)
Definition geqo_random.c:35
void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
int i
Definition isn.c:77
static int fb(int x)
tree ctl root
Definition radixtree.h:1857