Header And Logo

PostgreSQL
| The world's most advanced open source database.

geqo_mutation.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002 *
00003 * geqo_mutation.c
00004 *
00005 *    TSP mutation routines
00006 *
00007 * src/backend/optimizer/geqo/geqo_mutation.c
00008 *
00009 *-------------------------------------------------------------------------
00010 */
00011 
00012 /* contributed by:
00013    =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
00014    *  Martin Utesch              * Institute of Automatic Control      *
00015    =                             = University of Mining and Technology =
00016    *  [email protected]  * Freiberg, Germany                   *
00017    =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
00018  */
00019 
00020 /* this is adopted from Genitor : */
00021 /*************************************************************/
00022 /*                                                           */
00023 /*  Copyright (c) 1990                                       */
00024 /*  Darrell L. Whitley                                       */
00025 /*  Computer Science Department                              */
00026 /*  Colorado State University                                */
00027 /*                                                           */
00028 /*  Permission is hereby granted to copy all or any part of  */
00029 /*  this program for free distribution.   The author's name  */
00030 /*  and this copyright notice must be included in any copy.  */
00031 /*                                                           */
00032 /*************************************************************/
00033 
00034 #include "postgres.h"
00035 #include "optimizer/geqo_mutation.h"
00036 #include "optimizer/geqo_random.h"
00037 
00038 void
00039 geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
00040 {
00041     int         swap1;
00042     int         swap2;
00043     int         num_swaps = geqo_randint(root, num_gene / 3, 0);
00044     Gene        temp;
00045 
00046 
00047     while (num_swaps > 0)
00048     {
00049         swap1 = geqo_randint(root, num_gene - 1, 0);
00050         swap2 = geqo_randint(root, num_gene - 1, 0);
00051 
00052         while (swap1 == swap2)
00053             swap2 = geqo_randint(root, num_gene - 1, 0);
00054 
00055         temp = tour[swap1];
00056         tour[swap1] = tour[swap2];
00057         tour[swap2] = temp;
00058 
00059 
00060         num_swaps -= 1;
00061     }
00062 }