mirror of
https://github.com/postgres/postgres.git
synced 2025-12-06 00:02:13 +03:00
Merge in GEQO Optimizer
From: "Martin S. Utesch" <utesch@aut.tu-freiberg.de>
This commit is contained in:
76
src/backend/optimizer/geqo/geqo_mutation.c
Normal file
76
src/backend/optimizer/geqo/geqo_mutation.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*------------------------------------------------------------------------
|
||||
*
|
||||
* geqo_mutation.c--
|
||||
*
|
||||
* TSP mutation routines
|
||||
*
|
||||
* $Id: geqo_mutation.c,v 1.1 1997/02/19 12:57:13 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* contributed by:
|
||||
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
||||
* Martin Utesch * Institute of Automatic Control *
|
||||
= = University of Mining and Technology =
|
||||
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
|
||||
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
||||
*/
|
||||
|
||||
/* this 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_random.h"
|
||||
#include "optimizer/geqo_mutation.h"
|
||||
|
||||
void
|
||||
geqo_mutation (Gene *tour, int num_gene)
|
||||
{
|
||||
int swap1;
|
||||
int swap2;
|
||||
int num_swaps = geqo_randint (num_gene/3, 0);
|
||||
Gene temp;
|
||||
|
||||
|
||||
while (num_swaps > 0) {
|
||||
swap1 = geqo_randint (num_gene-1, 0);
|
||||
swap2 = geqo_randint (num_gene-1, 0);
|
||||
|
||||
while (swap1 == swap2)
|
||||
swap2 = geqo_randint (num_gene-1, 0);
|
||||
|
||||
temp = tour[swap1];
|
||||
tour[swap1] = tour[swap2];
|
||||
tour[swap2] = temp;
|
||||
|
||||
|
||||
num_swaps -= 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user