1997-02-19 13:59:07 +01:00
|
|
|
/*------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* geqo_mutation.c
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
|
|
|
* TSP mutation routines
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/optimizer/geqo/geqo_mutation.c
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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 "optimizer/geqo_mutation.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "optimizer/geqo_random.h"
|
1997-02-19 13:59:07 +01:00
|
|
|
|
2017-06-04 19:34:05 +02:00
|
|
|
#if defined(CX) /* currently used only in CX mode */
|
|
|
|
|
1997-02-19 13:59:07 +01:00
|
|
|
void
|
2009-07-16 22:55:44 +02:00
|
|
|
geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
|
1997-02-19 13:59:07 +01:00
|
|
|
{
|
|
|
|
int swap1;
|
|
|
|
int swap2;
|
2009-07-16 22:55:44 +02:00
|
|
|
int num_swaps = geqo_randint(root, num_gene / 3, 0);
|
1997-02-19 13:59:07 +01:00
|
|
|
Gene temp;
|
|
|
|
|
|
|
|
|
|
|
|
while (num_swaps > 0)
|
|
|
|
{
|
2009-07-16 22:55:44 +02:00
|
|
|
swap1 = geqo_randint(root, num_gene - 1, 0);
|
|
|
|
swap2 = geqo_randint(root, num_gene - 1, 0);
|
1997-02-19 13:59:07 +01:00
|
|
|
|
|
|
|
while (swap1 == swap2)
|
2009-07-16 22:55:44 +02:00
|
|
|
swap2 = geqo_randint(root, num_gene - 1, 0);
|
1997-02-19 13:59:07 +01:00
|
|
|
|
|
|
|
temp = tour[swap1];
|
|
|
|
tour[swap1] = tour[swap2];
|
|
|
|
tour[swap2] = temp;
|
|
|
|
|
|
|
|
|
|
|
|
num_swaps -= 1;
|
|
|
|
}
|
|
|
|
}
|
2017-06-04 19:34:05 +02:00
|
|
|
|
|
|
|
#endif /* defined(CX) */
|