]> granicus.if.org Git - postgresql/blob - src/backend/optimizer/geqo/geqo_misc.c
Another pgindent run with lib typedefs added.
[postgresql] / src / backend / optimizer / geqo / geqo_misc.c
1 /*------------------------------------------------------------------------
2  *
3  * geqo_misc.c
4  *         misc. printout and debug stuff
5  *
6  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_misc.c,v 1.41 2004/08/29 04:12:33 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 /* contributed by:
15    =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
16    *  Martin Utesch                              * Institute of Automatic Control          *
17    =                                                     = University of Mining and Technology =
18    *  utesch@aut.tu-freiberg.de  * Freiberg, Germany                               *
19    =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
20  */
21
22 #include "postgres.h"
23
24 #include "optimizer/geqo_misc.h"
25 #include "nodes/print.h"
26
27
28 #ifdef GEQO_DEBUG
29
30
31 /*
32  * avg_pool
33  */
34 static double
35 avg_pool(Pool *pool)
36 {
37         int                     i;
38         double          cumulative = 0.0;
39
40         if (pool->size <= 0)
41                 elog(ERROR, "pool_size is zero");
42
43         /*
44          * Since the pool may contain multiple occurrences of DBL_MAX, divide
45          * by pool->size before summing, not after, to avoid overflow.  This
46          * loses a little in speed and accuracy, but this routine is only used
47          * for debug printouts, so we don't care that much.
48          */
49         for (i = 0; i < pool->size; i++)
50                 cumulative += pool->data[i].worth / pool->size;
51
52         return cumulative;
53 }
54
55 /* print_pool
56  */
57 void
58 print_pool(FILE *fp, Pool *pool, int start, int stop)
59 {
60         int                     i,
61                                 j;
62
63         /* be extra careful that start and stop are valid inputs */
64
65         if (start < 0)
66                 start = 0;
67         if (stop > pool->size)
68                 stop = pool->size;
69
70         if (start + stop > pool->size)
71         {
72                 start = 0;
73                 stop = pool->size;
74         }
75
76         for (i = start; i < stop; i++)
77         {
78                 fprintf(fp, "%d)\t", i);
79                 for (j = 0; j < pool->string_length; j++)
80                         fprintf(fp, "%d ", pool->data[i].string[j]);
81                 fprintf(fp, "%g\n", pool->data[i].worth);
82         }
83
84         fflush(fp);
85 }
86
87 /* print_gen
88  *
89  *       printout for chromosome: best, worst, mean, average
90  */
91 void
92 print_gen(FILE *fp, Pool *pool, int generation)
93 {
94         int                     lowest;
95
96         /* Get index to lowest ranking gene in poplulation. */
97         /* Use 2nd to last since last is buffer. */
98         lowest = pool->size > 1 ? pool->size - 2 : 0;
99
100         fprintf(fp,
101                         "%5d | Best: %g  Worst: %g  Mean: %g  Avg: %g\n",
102                         generation,
103                         pool->data[0].worth,
104                         pool->data[lowest].worth,
105                         pool->data[pool->size / 2].worth,
106                         avg_pool(pool));
107
108         fflush(fp);
109 }
110
111
112 void
113 print_edge_table(FILE *fp, Edge *edge_table, int num_gene)
114 {
115         int                     i,
116                                 j;
117
118         fprintf(fp, "\nEDGE TABLE\n");
119
120         for (i = 1; i <= num_gene; i++)
121         {
122                 fprintf(fp, "%d :", i);
123                 for (j = 0; j < edge_table[i].unused_edges; j++)
124                         fprintf(fp, " %d", edge_table[i].edge_list[j]);
125                 fprintf(fp, "\n");
126         }
127
128         fprintf(fp, "\n");
129
130         fflush(fp);
131 }
132
133 #endif   /* GEQO_DEBUG */