Branch data Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : *
3 : : * geqo_gene.h
4 : : * genome representation in optimizer/geqo
5 : : *
6 : : * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 : : * Portions Copyright (c) 1994, Regents of the University of California
8 : : *
9 : : * src/include/optimizer/geqo_gene.h
10 : : *
11 : : *-------------------------------------------------------------------------
12 : : */
13 : :
14 : : /*
15 : : * contributed by:
16 : : * =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
17 : : * * Martin Utesch * Institute of Automatic Control *
18 : : * = = University of Mining and Technology =
19 : : * * utesch@aut.tu-freiberg.de * Freiberg, Germany *
20 : : * =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
21 : : */
22 : :
23 : :
24 : : #ifndef GEQO_GENE_H
25 : : #define GEQO_GENE_H
26 : :
27 : : #include <float.h>
28 : : #include <limits.h>
29 : :
30 : : #include "nodes/nodes.h"
31 : :
32 : : /*
33 : : * we presume that int instead of Relid
34 : : * is o.k. for Gene; so don't change it!
35 : : */
36 : : typedef int Gene;
37 : :
38 : : /*
39 : : * Fitness of a candidate join order.
40 : : *
41 : : * A tour for which no valid plan could be constructed is represented by
42 : : * disabled_nodes = INT_MAX and cost = DBL_MAX.
43 : : */
44 : : typedef struct Fitness
45 : : {
46 : : int disabled_nodes;
47 : : Cost cost;
48 : : } Fitness;
49 : :
50 : : /*
51 : : * Is this a valid tour?
52 : : */
53 : : static inline bool
54 : 1820 : fitness_is_valid(Fitness fitness)
55 : : {
56 [ - + - - ]: 1820 : return fitness.disabled_nodes < INT_MAX || fitness.cost < DBL_MAX;
57 : : }
58 : :
59 : : /*
60 : : * Which fitness is better?
61 : : */
62 : : static inline int
63 : 5512 : fitness_compare(Fitness fitness1, Fitness fitness2)
64 : : {
65 [ + + ]: 5512 : if (fitness1.disabled_nodes != fitness2.disabled_nodes)
66 [ + + ]: 122 : return fitness1.disabled_nodes < fitness2.disabled_nodes ? -1 : 1;
67 [ - + ]: 5390 : if (fitness1.cost != fitness2.cost)
68 [ # # ]: 0 : return fitness1.cost < fitness2.cost ? -1 : 1;
69 : 5390 : return 0;
70 : : }
71 : :
72 : : typedef struct Chromosome
73 : : {
74 : : Gene *string;
75 : : Fitness worth;
76 : : } Chromosome;
77 : :
78 : : typedef struct Pool
79 : : {
80 : : Chromosome *data;
81 : : int size;
82 : : int string_length;
83 : : } Pool;
84 : :
85 : : #endif /* GEQO_GENE_H */
|