Commit 9db7d47f authored by Tom Lane's avatar Tom Lane

#ifdef out assorted unused GEQO code.

I'd always assumed that backend/optimizer/geqo/'s remarkably poor
showing on code coverage metrics was because we weren't exercising
it much in the regression tests.  But it turns out that a good chunk
of the problem is that there's a bunch of code that is physically
unreachable (because the calls to it are #ifdef'd out in geqo_main.c)
but is being built anyway.  Making the called code have #if guards
similar to the calling code saves a couple of kilobytes of executable
size and should make the coverage numbers more reflective of reality.

It's arguable that we should just delete all the unused recombination
mechanisms altogether, but I didn't feel a need to go that far today.
parent 0d188526
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "optimizer/geqo_recombination.h" #include "optimizer/geqo_recombination.h"
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#if defined(CX)
/* cx /* cx
* *
...@@ -119,3 +120,5 @@ cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, ...@@ -119,3 +120,5 @@ cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring,
return num_diffs; return num_diffs;
} }
#endif /* defined(CX) */
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "optimizer/geqo_recombination.h" #include "optimizer/geqo_recombination.h"
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#if defined(ERX)
static int gimme_edge(PlannerInfo *root, Gene gene1, Gene gene2, Edge *edge_table); static int gimme_edge(PlannerInfo *root, Gene gene1, Gene gene2, Edge *edge_table);
static void remove_gene(PlannerInfo *root, Gene gene, Edge edge, Edge *edge_table); static void remove_gene(PlannerInfo *root, Gene gene, Edge edge, Edge *edge_table);
...@@ -466,3 +467,5 @@ edge_failure(PlannerInfo *root, Gene *gene, int index, Edge *edge_table, int num ...@@ -466,3 +467,5 @@ edge_failure(PlannerInfo *root, Gene *gene, int index, Edge *edge_table, int num
elog(ERROR, "no edge found"); elog(ERROR, "no edge found");
return 0; /* to keep the compiler quiet */ return 0; /* to keep the compiler quiet */
} }
#endif /* defined(ERX) */
...@@ -46,14 +46,14 @@ double Geqo_seed; ...@@ -46,14 +46,14 @@ double Geqo_seed;
static int gimme_pool_size(int nr_rel); static int gimme_pool_size(int nr_rel);
static int gimme_number_generations(int pool_size); static int gimme_number_generations(int pool_size);
/* define edge recombination crossover [ERX] per default */ /* complain if no recombination mechanism is #define'd */
#if !defined(ERX) && \ #if !defined(ERX) && \
!defined(PMX) && \ !defined(PMX) && \
!defined(CX) && \ !defined(CX) && \
!defined(PX) && \ !defined(PX) && \
!defined(OX1) && \ !defined(OX1) && \
!defined(OX2) !defined(OX2)
#define ERX #error "must choose one GEQO recombination mechanism in geqo.h"
#endif #endif
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include "optimizer/geqo_mutation.h" #include "optimizer/geqo_mutation.h"
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#if defined(CX) /* currently used only in CX mode */
void void
geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene) geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
{ {
...@@ -60,3 +62,5 @@ geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene) ...@@ -60,3 +62,5 @@ geqo_mutation(PlannerInfo *root, Gene *tour, int num_gene)
num_swaps -= 1; num_swaps -= 1;
} }
} }
#endif /* defined(CX) */
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#include "optimizer/geqo_recombination.h" #include "optimizer/geqo_recombination.h"
#if defined(OX1)
/* ox1 /* ox1
* *
...@@ -90,3 +91,5 @@ ox1(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, ...@@ -90,3 +91,5 @@ ox1(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene,
} }
} }
#endif /* defined(OX1) */
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#include "optimizer/geqo_recombination.h" #include "optimizer/geqo_recombination.h"
#if defined(OX2)
/* ox2 /* ox2
* *
...@@ -107,3 +108,5 @@ ox2(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, ...@@ -107,3 +108,5 @@ ox2(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene,
} }
} }
#endif /* defined(OX2) */
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#include "optimizer/geqo_recombination.h" #include "optimizer/geqo_recombination.h"
#if defined(PMX)
/* pmx /* pmx
* *
...@@ -219,3 +220,5 @@ pmx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene) ...@@ -219,3 +220,5 @@ pmx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene)
pfree(indx); pfree(indx);
pfree(check_list); pfree(check_list);
} }
#endif /* defined(PMX) */
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "optimizer/geqo_random.h" #include "optimizer/geqo_random.h"
#include "optimizer/geqo_recombination.h" #include "optimizer/geqo_recombination.h"
#if defined(PX)
/* px /* px
* *
...@@ -105,3 +106,5 @@ px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, ...@@ -105,3 +106,5 @@ px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene,
} }
} }
#endif /* defined(PX) */
...@@ -58,6 +58,9 @@ init_tour(PlannerInfo *root, Gene *tour, int num_gene) ...@@ -58,6 +58,9 @@ init_tour(PlannerInfo *root, Gene *tour, int num_gene)
} }
} }
/* city table is used in these recombination methods: */
#if defined(CX) || defined(PX) || defined(OX1) || defined(OX2)
/* alloc_city_table /* alloc_city_table
* *
* allocate memory for city table * allocate memory for city table
...@@ -85,3 +88,5 @@ free_city_table(PlannerInfo *root, City *city_table) ...@@ -85,3 +88,5 @@ free_city_table(PlannerInfo *root, City *city_table)
{ {
pfree(city_table); pfree(city_table);
} }
#endif /* CX || PX || OX1 || OX2 */
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#define GEQO_DEBUG #define GEQO_DEBUG
*/ */
/* recombination mechanism */ /* choose one recombination mechanism here */
/* /*
#define ERX #define ERX
#define PMX #define PMX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment