~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/backend/optimizer/geqo/geqo_mutation.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------
 
2
*
 
3
* geqo_mutation.c
 
4
*
 
5
*        TSP mutation routines
 
6
*
 
7
* $PostgreSQL$
 
8
*
 
9
*-------------------------------------------------------------------------
 
10
*/
 
11
 
 
12
/* contributed by:
 
13
   =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
 
14
   *  Martin Utesch                              * Institute of Automatic Control          *
 
15
   =                                                     = University of Mining and Technology =
 
16
   *  utesch@aut.tu-freiberg.de  * Freiberg, Germany                               *
 
17
   =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
 
18
 */
 
19
 
 
20
/* this is adopted from Genitor : */
 
21
/*************************************************************/
 
22
/*                                                                                                                       */
 
23
/*      Copyright (c) 1990                                                                               */
 
24
/*      Darrell L. Whitley                                                                               */
 
25
/*      Computer Science Department                                                              */
 
26
/*      Colorado State University                                                                */
 
27
/*                                                                                                                       */
 
28
/*      Permission is hereby granted to copy all or any part of  */
 
29
/*      this program for free distribution.   The author's name  */
 
30
/*      and this copyright notice must be included in any copy.  */
 
31
/*                                                                                                                       */
 
32
/*************************************************************/
 
33
 
 
34
#include "postgres.h"
 
35
#include "optimizer/geqo_mutation.h"
 
36
#include "optimizer/geqo_random.h"
 
37
 
 
38
void
 
39
geqo_mutation(Gene *tour, int num_gene)
 
40
{
 
41
        int                     swap1;
 
42
        int                     swap2;
 
43
        int                     num_swaps = geqo_randint(num_gene / 3, 0);
 
44
        Gene            temp;
 
45
 
 
46
 
 
47
        while (num_swaps > 0)
 
48
        {
 
49
                swap1 = geqo_randint(num_gene - 1, 0);
 
50
                swap2 = geqo_randint(num_gene - 1, 0);
 
51
 
 
52
                while (swap1 == swap2)
 
53
                        swap2 = geqo_randint(num_gene - 1, 0);
 
54
 
 
55
                temp = tour[swap1];
 
56
                tour[swap1] = tour[swap2];
 
57
                tour[swap2] = temp;
 
58
 
 
59
 
 
60
                num_swaps -= 1;
 
61
        }
 
62
}