Header And Logo

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

geqo_misc.c

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *
00003  * geqo_misc.c
00004  *     misc. printout and debug stuff
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * src/backend/optimizer/geqo/geqo_misc.c
00010  *
00011  *-------------------------------------------------------------------------
00012  */
00013 
00014 /* contributed by:
00015    =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
00016    *  Martin Utesch              * Institute of Automatic Control      *
00017    =                             = University of Mining and Technology =
00018    *  [email protected]  * Freiberg, Germany                   *
00019    =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
00020  */
00021 
00022 #include "postgres.h"
00023 
00024 #include "optimizer/geqo_misc.h"
00025 
00026 
00027 #ifdef GEQO_DEBUG
00028 
00029 
00030 /*
00031  * avg_pool
00032  */
00033 static double
00034 avg_pool(Pool *pool)
00035 {
00036     int         i;
00037     double      cumulative = 0.0;
00038 
00039     if (pool->size <= 0)
00040         elog(ERROR, "pool_size is zero");
00041 
00042     /*
00043      * Since the pool may contain multiple occurrences of DBL_MAX, divide by
00044      * pool->size before summing, not after, to avoid overflow.  This loses a
00045      * little in speed and accuracy, but this routine is only used for debug
00046      * printouts, so we don't care that much.
00047      */
00048     for (i = 0; i < pool->size; i++)
00049         cumulative += pool->data[i].worth / pool->size;
00050 
00051     return cumulative;
00052 }
00053 
00054 /* print_pool
00055  */
00056 void
00057 print_pool(FILE *fp, Pool *pool, int start, int stop)
00058 {
00059     int         i,
00060                 j;
00061 
00062     /* be extra careful that start and stop are valid inputs */
00063 
00064     if (start < 0)
00065         start = 0;
00066     if (stop > pool->size)
00067         stop = pool->size;
00068 
00069     if (start + stop > pool->size)
00070     {
00071         start = 0;
00072         stop = pool->size;
00073     }
00074 
00075     for (i = start; i < stop; i++)
00076     {
00077         fprintf(fp, "%d)\t", i);
00078         for (j = 0; j < pool->string_length; j++)
00079             fprintf(fp, "%d ", pool->data[i].string[j]);
00080         fprintf(fp, "%g\n", pool->data[i].worth);
00081     }
00082 
00083     fflush(fp);
00084 }
00085 
00086 /* print_gen
00087  *
00088  *   printout for chromosome: best, worst, mean, average
00089  */
00090 void
00091 print_gen(FILE *fp, Pool *pool, int generation)
00092 {
00093     int         lowest;
00094 
00095     /* Get index to lowest ranking gene in poplulation. */
00096     /* Use 2nd to last since last is buffer. */
00097     lowest = pool->size > 1 ? pool->size - 2 : 0;
00098 
00099     fprintf(fp,
00100             "%5d | Best: %g  Worst: %g  Mean: %g  Avg: %g\n",
00101             generation,
00102             pool->data[0].worth,
00103             pool->data[lowest].worth,
00104             pool->data[pool->size / 2].worth,
00105             avg_pool(pool));
00106 
00107     fflush(fp);
00108 }
00109 
00110 
00111 void
00112 print_edge_table(FILE *fp, Edge *edge_table, int num_gene)
00113 {
00114     int         i,
00115                 j;
00116 
00117     fprintf(fp, "\nEDGE TABLE\n");
00118 
00119     for (i = 1; i <= num_gene; i++)
00120     {
00121         fprintf(fp, "%d :", i);
00122         for (j = 0; j < edge_table[i].unused_edges; j++)
00123             fprintf(fp, " %d", edge_table[i].edge_list[j]);
00124         fprintf(fp, "\n");
00125     }
00126 
00127     fprintf(fp, "\n");
00128 
00129     fflush(fp);
00130 }
00131 
00132 #endif   /* GEQO_DEBUG */