1997-02-19 13:59:07 +01:00
|
|
|
/*------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* geqo_misc.c
|
1997-02-19 13:59:07 +01:00
|
|
|
* misc. printout and debug stuff
|
|
|
|
*
|
2023-01-02 21:00:37 +01:00
|
|
|
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/optimizer/geqo/geqo_misc.c
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* contributed by:
|
|
|
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
|
|
|
* Martin Utesch * Institute of Automatic Control *
|
|
|
|
= = University of Mining and Technology =
|
|
|
|
* utesch@aut.tu-freiberg.de * Freiberg, Germany *
|
|
|
|
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
1999-08-16 04:17:58 +02:00
|
|
|
|
2006-07-15 05:35:21 +02:00
|
|
|
#include "optimizer/geqo_misc.h"
|
1999-08-16 04:17:58 +02:00
|
|
|
|
2002-11-06 01:00:45 +01:00
|
|
|
|
2002-07-20 06:59:10 +02:00
|
|
|
#ifdef GEQO_DEBUG
|
1997-02-19 13:59:07 +01:00
|
|
|
|
|
|
|
|
2002-11-06 01:00:45 +01:00
|
|
|
/*
|
|
|
|
* avg_pool
|
1997-02-19 13:59:07 +01:00
|
|
|
*/
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
static double
|
1997-02-19 13:59:07 +01:00
|
|
|
avg_pool(Pool *pool)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
double cumulative = 0.0;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
if (pool->size <= 0)
|
2003-07-25 02:01:09 +02:00
|
|
|
elog(ERROR, "pool_size is zero");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
/*
|
|
|
|
* Since the pool may contain multiple occurrences of DBL_MAX, divide by
|
|
|
|
* pool->size before summing, not after, to avoid overflow. This loses a
|
|
|
|
* little in speed and accuracy, but this routine is only used for debug
|
|
|
|
* printouts, so we don't care that much.
|
|
|
|
*/
|
1997-02-19 13:59:07 +01:00
|
|
|
for (i = 0; i < pool->size; i++)
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
cumulative += pool->data[i].worth / pool->size;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
return cumulative;
|
1997-02-19 13:59:07 +01:00
|
|
|
}
|
|
|
|
|
1999-02-14 00:22:53 +01:00
|
|
|
/* print_pool
|
1997-02-19 13:59:07 +01:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_pool(FILE *fp, Pool *pool, int start, int stop)
|
|
|
|
{
|
|
|
|
int i,
|
|
|
|
j;
|
|
|
|
|
|
|
|
/* be extra careful that start and stop are valid inputs */
|
|
|
|
|
|
|
|
if (start < 0)
|
|
|
|
start = 0;
|
|
|
|
if (stop > pool->size)
|
|
|
|
stop = pool->size;
|
|
|
|
|
|
|
|
if (start + stop > pool->size)
|
|
|
|
{
|
|
|
|
start = 0;
|
|
|
|
stop = pool->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = start; i < stop; i++)
|
|
|
|
{
|
|
|
|
fprintf(fp, "%d)\t", i);
|
|
|
|
for (j = 0; j < pool->string_length; j++)
|
|
|
|
fprintf(fp, "%d ", pool->data[i].string[j]);
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
fprintf(fp, "%g\n", pool->data[i].worth);
|
1997-02-19 13:59:07 +01:00
|
|
|
}
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
|
|
|
|
fflush(fp);
|
1997-02-19 13:59:07 +01:00
|
|
|
}
|
|
|
|
|
1999-02-14 00:22:53 +01:00
|
|
|
/* print_gen
|
1997-02-19 13:59:07 +01:00
|
|
|
*
|
|
|
|
* printout for chromosome: best, worst, mean, average
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
print_gen(FILE *fp, Pool *pool, int generation)
|
|
|
|
{
|
|
|
|
int lowest;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2018-04-01 21:01:28 +02:00
|
|
|
/* Get index to lowest ranking gene in population. */
|
1997-02-19 13:59:07 +01:00
|
|
|
/* Use 2nd to last since last is buffer. */
|
|
|
|
lowest = pool->size > 1 ? pool->size - 2 : 0;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-02-19 13:59:07 +01:00
|
|
|
fprintf(fp,
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
"%5d | Best: %g Worst: %g Mean: %g Avg: %g\n",
|
1997-02-19 13:59:07 +01:00
|
|
|
generation,
|
|
|
|
pool->data[0].worth,
|
|
|
|
pool->data[lowest].worth,
|
|
|
|
pool->data[pool->size / 2].worth,
|
|
|
|
avg_pool(pool));
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
|
|
|
|
fflush(fp);
|
1997-02-19 13:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
print_edge_table(FILE *fp, Edge *edge_table, int num_gene)
|
|
|
|
{
|
|
|
|
int i,
|
|
|
|
j;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-02-19 13:59:07 +01:00
|
|
|
fprintf(fp, "\nEDGE TABLE\n");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-02-19 13:59:07 +01:00
|
|
|
for (i = 1; i <= num_gene; i++)
|
|
|
|
{
|
|
|
|
fprintf(fp, "%d :", i);
|
|
|
|
for (j = 0; j < edge_table[i].unused_edges; j++)
|
|
|
|
fprintf(fp, " %d", edge_table[i].edge_list[j]);
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-02-19 13:59:07 +01:00
|
|
|
fprintf(fp, "\n");
|
Fix GEQO to work again in CVS tip, by being more careful about memory
allocation in best_inner_indexscan(). While at it, simplify GEQO's
interface to the main planner --- make_join_rel() offers exactly the
API it really wants, whereas calling make_rels_by_clause_joins() and
make_rels_by_clauseless_joins() required jumping through hoops.
Rewrite gimme_tree for clarity (sometimes iteration is much better than
recursion), and approximately halve GEQO's runtime by recognizing that
tours of the forms (a,b,c,d,...) and (b,a,c,d,...) are equivalent
because of symmetry in make_join_rel().
2002-12-16 22:30:30 +01:00
|
|
|
|
|
|
|
fflush(fp);
|
1997-02-19 13:59:07 +01:00
|
|
|
}
|
|
|
|
|
2002-07-20 06:59:10 +02:00
|
|
|
#endif /* GEQO_DEBUG */
|