1997-02-19 13:59:07 +01:00
|
|
|
/*------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* geqo_mutation.c--
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* TSP mutation routines
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
1997-09-08 23:56:23 +02:00
|
|
|
* $Id: geqo_mutation.c,v 1.4 1997/09/08 21:44:27 momjian Exp $
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* contributed by:
|
|
|
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
1997-09-07 07:04:48 +02:00
|
|
|
* Martin Utesch * Institute of Automatic Control *
|
|
|
|
= = University of Mining and Technology =
|
|
|
|
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
|
1997-02-19 13:59:07 +01:00
|
|
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* this is adopted from Genitor : */
|
|
|
|
/*************************************************************/
|
1997-09-07 07:04:48 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
1997-02-19 13:59:07 +01:00
|
|
|
/*************************************************************/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
void
|
1997-09-08 23:56:23 +02:00
|
|
|
geqo_mutation(Gene *tour, int num_gene)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
int swap1;
|
|
|
|
int swap2;
|
|
|
|
int num_swaps = geqo_randint(num_gene / 3, 0);
|
|
|
|
Gene temp;
|
1997-02-19 13:59:07 +01:00
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
while (num_swaps > 0)
|
|
|
|
{
|
|
|
|
swap1 = geqo_randint(num_gene - 1, 0);
|
|
|
|
swap2 = geqo_randint(num_gene - 1, 0);
|
1997-02-19 13:59:07 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
while (swap1 == swap2)
|
|
|
|
swap2 = geqo_randint(num_gene - 1, 0);
|
1997-02-19 13:59:07 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
temp = tour[swap1];
|
|
|
|
tour[swap1] = tour[swap2];
|
|
|
|
tour[swap2] = temp;
|
1997-02-19 13:59:07 +01:00
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
num_swaps -= 1;
|
|
|
|
}
|
1997-02-19 13:59:07 +01:00
|
|
|
}
|