mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
> There are some minor fixes to the GEQO.
> Please apply them to the direcory "backend/optimizer/geqo". > Two new files with different crossover techniques are included. > Standard procedure is optimization by means of "geqo_erx.c" > (Edge Recombination Crossover). From: "Martin S. Utesch" <utesch@aut.tu-freiberg.de>
This commit is contained in:
parent
f749fe4934
commit
71fd8d4a4b
@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
# Copyright (c) 1994, Regents of the University of California
|
# Copyright (c) 1994, Regents of the University of California
|
||||||
#
|
#
|
||||||
# $Id: Makefile,v 1.2 1997/02/19 14:51:55 scrappy Exp $
|
# $Id: Makefile,v 1.3 1997/03/14 16:02:40 scrappy Exp $
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -21,9 +21,8 @@ CFLAGS+=$(INCLUDE_OPT) -Wno-error
|
|||||||
OBJS = geqo_copy.o geqo_eval.o geqo_main.o geqo_misc.o \
|
OBJS = geqo_copy.o geqo_eval.o geqo_main.o geqo_misc.o \
|
||||||
geqo_params.o geqo_paths.o geqo_pool.o geqo_recombination.o \
|
geqo_params.o geqo_paths.o geqo_pool.o geqo_recombination.o \
|
||||||
geqo_selection.o \
|
geqo_selection.o \
|
||||||
geqo_erx.o geqo_pmx.o geqo_cx.o geqo_px.o
|
geqo_erx.o geqo_pmx.o geqo_cx.o geqo_px.o geqo_ox1.o geqo_ox2.o
|
||||||
|
|
||||||
# not ready yet: geqo_ox1.o geqo_ox2.o
|
|
||||||
# deprecated: minspantree.o
|
# deprecated: minspantree.o
|
||||||
|
|
||||||
all: SUBSYS.o
|
all: SUBSYS.o
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: geqo_main.c,v 1.2 1997/02/19 14:51:59 scrappy Exp $
|
* $Id: geqo_main.c,v 1.3 1997/03/14 16:02:51 scrappy Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -71,22 +71,22 @@ geqo(Query *root)
|
|||||||
Chromosome *daddy;
|
Chromosome *daddy;
|
||||||
Chromosome *kid;
|
Chromosome *kid;
|
||||||
|
|
||||||
|
#if defined(ERX)
|
||||||
Edge *edge_table; /* list of edges */
|
Edge *edge_table; /* list of edges */
|
||||||
int edge_failures=0;
|
int edge_failures=0;
|
||||||
float difference;
|
float difference;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CX) || defined(PX) || defined(QX1) || defined(QX2)
|
#if defined(CX) || defined(PX) || defined(OX1) || defined(OX2)
|
||||||
City *city_table; /* list of cities */
|
City *city_table; /* list of cities */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CX)
|
#if defined(CX)
|
||||||
int cycle_diffs=0;
|
int cycle_diffs=0;
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CX) && defined(GEQO_DEBUG)
|
|
||||||
int mutations=0;
|
int mutations=0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int number_of_rels;
|
int number_of_rels;
|
||||||
|
|
||||||
Pool *pool;
|
Pool *pool;
|
||||||
|
103
src/backend/optimizer/geqo/geqo_ox1.c
Normal file
103
src/backend/optimizer/geqo/geqo_ox1.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* geqo_ox1.c--
|
||||||
|
*
|
||||||
|
* order crossover [OX] routines;
|
||||||
|
* OX1 operator according to Davis
|
||||||
|
* (Proc Int'l Joint Conf on AI)
|
||||||
|
*
|
||||||
|
* $Id: geqo_ox1.c,v 1.1 1997/03/14 16:02:58 scrappy Exp $
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* contributed by:
|
||||||
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
||||||
|
* Martin Utesch * Institute of Automatic Control *
|
||||||
|
= = University of Mining and Technology =
|
||||||
|
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
|
||||||
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* the ox algorithm is adopted from Genitor : */
|
||||||
|
/*************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 1990 */
|
||||||
|
/* Darrell L. Whitley */
|
||||||
|
/* Computer Science Department */
|
||||||
|
/* Colorado State University */
|
||||||
|
/* */
|
||||||
|
/* Permission is hereby granted to copy all or any part of */
|
||||||
|
/* this program for free distribution. The author's name */
|
||||||
|
/* and this copyright notice must be included in any copy. */
|
||||||
|
/* */
|
||||||
|
/*************************************************************/
|
||||||
|
|
||||||
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "nodes/pg_list.h"
|
||||||
|
#include "nodes/relation.h"
|
||||||
|
#include "nodes/primnodes.h"
|
||||||
|
|
||||||
|
#include "utils/palloc.h"
|
||||||
|
#include "utils/elog.h"
|
||||||
|
|
||||||
|
#include "optimizer/internal.h"
|
||||||
|
#include "optimizer/paths.h"
|
||||||
|
#include "optimizer/pathnode.h"
|
||||||
|
#include "optimizer/clauses.h"
|
||||||
|
#include "optimizer/cost.h"
|
||||||
|
|
||||||
|
#include "optimizer/geqo_gene.h"
|
||||||
|
#include "optimizer/geqo.h"
|
||||||
|
#include "optimizer/geqo_recombination.h"
|
||||||
|
#include "optimizer/geqo_random.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* ox1--
|
||||||
|
*
|
||||||
|
* position crossover
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ox1(Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
|
||||||
|
{
|
||||||
|
int left, right, k, p, temp;
|
||||||
|
|
||||||
|
/* initialize city table */
|
||||||
|
for (k = 1; k <= num_gene; k++)
|
||||||
|
city_table[k].used = 0;
|
||||||
|
|
||||||
|
/* select portion to copy from tour1 */
|
||||||
|
left = geqo_randint (num_gene - 1, 0);
|
||||||
|
right = geqo_randint (num_gene - 1, 0);
|
||||||
|
|
||||||
|
if (left > right)
|
||||||
|
{
|
||||||
|
temp = left;
|
||||||
|
left = right;
|
||||||
|
right = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* copy portion from tour1 to offspring */
|
||||||
|
for (k = left; k <= right; k++)
|
||||||
|
{
|
||||||
|
offspring[k] = tour1[k];
|
||||||
|
city_table[(int) tour1[k]].used = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
k = (right + 1) % num_gene; /* index into offspring */
|
||||||
|
p = k; /* index into tour2 */
|
||||||
|
|
||||||
|
/* copy stuff from tour2 to offspring */
|
||||||
|
while (k != left)
|
||||||
|
{
|
||||||
|
if (!city_table[(int) tour2[p]].used)
|
||||||
|
{
|
||||||
|
offspring[k] = tour2[p];
|
||||||
|
k = (k + 1) % num_gene;
|
||||||
|
city_table[(int) tour2[p]].used = 1;
|
||||||
|
}
|
||||||
|
p = (p + 1) % num_gene; /* increment tour2-index */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
113
src/backend/optimizer/geqo/geqo_ox2.c
Normal file
113
src/backend/optimizer/geqo/geqo_ox2.c
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* geqo_ox2.c--
|
||||||
|
*
|
||||||
|
* order crossover [OX] routines;
|
||||||
|
* OX2 operator according to Syswerda
|
||||||
|
* (The Genetic Algorithms Handbook, ed L Davis)
|
||||||
|
*
|
||||||
|
* $Id: geqo_ox2.c,v 1.1 1997/03/14 16:03:02 scrappy Exp $
|
||||||
|
*
|
||||||
|
*-------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* contributed by:
|
||||||
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
||||||
|
* Martin Utesch * Institute of Automatic Control *
|
||||||
|
= = University of Mining and Technology =
|
||||||
|
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
|
||||||
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* the ox algorithm is adopted from Genitor : */
|
||||||
|
/*************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) 1990 */
|
||||||
|
/* Darrell L. Whitley */
|
||||||
|
/* Computer Science Department */
|
||||||
|
/* Colorado State University */
|
||||||
|
/* */
|
||||||
|
/* Permission is hereby granted to copy all or any part of */
|
||||||
|
/* this program for free distribution. The author's name */
|
||||||
|
/* and this copyright notice must be included in any copy. */
|
||||||
|
/* */
|
||||||
|
/*************************************************************/
|
||||||
|
|
||||||
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "nodes/pg_list.h"
|
||||||
|
#include "nodes/relation.h"
|
||||||
|
#include "nodes/primnodes.h"
|
||||||
|
|
||||||
|
#include "utils/palloc.h"
|
||||||
|
#include "utils/elog.h"
|
||||||
|
|
||||||
|
#include "optimizer/internal.h"
|
||||||
|
#include "optimizer/paths.h"
|
||||||
|
#include "optimizer/pathnode.h"
|
||||||
|
#include "optimizer/clauses.h"
|
||||||
|
#include "optimizer/cost.h"
|
||||||
|
|
||||||
|
#include "optimizer/geqo_gene.h"
|
||||||
|
#include "optimizer/geqo.h"
|
||||||
|
#include "optimizer/geqo_recombination.h"
|
||||||
|
#include "optimizer/geqo_random.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* ox2--
|
||||||
|
*
|
||||||
|
* position crossover
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ox2(Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
|
||||||
|
{
|
||||||
|
int k, j, count, pos, select, num_positions;
|
||||||
|
|
||||||
|
/* initialize city table */
|
||||||
|
for (k = 1; k <= num_gene; k++) {
|
||||||
|
city_table[k].used = 0;
|
||||||
|
city_table[k-1].select_list = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* determine the number of positions to be inherited from tour1 */
|
||||||
|
num_positions = geqo_randint (2*num_gene/3, num_gene/3);
|
||||||
|
|
||||||
|
/* make a list of selected cities */
|
||||||
|
for (k=0; k<num_positions; k++) {
|
||||||
|
pos = geqo_randint (num_gene - 1, 0);
|
||||||
|
city_table[pos].select_list = (int) tour1[pos];
|
||||||
|
city_table[(int) tour1[pos]].used = 1; /* mark used */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
k = 0;
|
||||||
|
|
||||||
|
/* consolidate the select list to adjacent positions */
|
||||||
|
while (count < num_positions) {
|
||||||
|
if (city_table[k].select_list == -1) {
|
||||||
|
j = k + 1;
|
||||||
|
while ((city_table[j].select_list == -1) && (j < num_gene))
|
||||||
|
j++;
|
||||||
|
|
||||||
|
city_table[k].select_list = city_table[j].select_list;
|
||||||
|
city_table[j].select_list = -1;
|
||||||
|
count ++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
count ++;
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
|
||||||
|
select = 0;
|
||||||
|
|
||||||
|
for (k=0; k<num_gene; k++) {
|
||||||
|
if (city_table[(int) tour2[k]].used) {
|
||||||
|
offspring[k] = (Gene) city_table[select].select_list;
|
||||||
|
select ++; /* next city in the select list */
|
||||||
|
}
|
||||||
|
else /* city isn't used yet, so inherit from tour2 */
|
||||||
|
offspring[k] = tour2[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user