PostgreSQL Source Code git master
Loading...
Searching...
No Matches
geqo_misc.c
Go to the documentation of this file.
1/*------------------------------------------------------------------------
2 *
3 * geqo_misc.c
4 * misc. printout and debug stuff
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/backend/optimizer/geqo/geqo_misc.c
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#include "postgres.h"
24
25#include "optimizer/geqo_misc.h"
26
27
28#ifdef GEQO_DEBUG
29
30
31/*
32 * avg_pool
33 */
34static double
35avg_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 by
45 * pool->size before summing, not after, to avoid overflow. This loses a
46 * little in speed and accuracy, but this routine is only used for debug
47 * 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/*
56 * print_pool
57 */
58void
59print_pool(FILE *fp, Pool *pool, int start, int stop)
60{
61 int i,
62 j;
63
64 /* be extra careful that start and stop are valid inputs */
65
66 if (start < 0)
67 start = 0;
68 if (stop > pool->size)
69 stop = pool->size;
70
71 if (start + stop > pool->size)
72 {
73 start = 0;
74 stop = pool->size;
75 }
76
77 for (i = start; i < stop; i++)
78 {
79 fprintf(fp, "%d)\t", i);
80 for (j = 0; j < pool->string_length; j++)
81 fprintf(fp, "%d ", pool->data[i].string[j]);
82 fprintf(fp, "%g\n", pool->data[i].worth);
83 }
84
85 fflush(fp);
86}
87
88/*
89 * print_gen
90 *
91 * printout for chromosome: best, worst, mean, average
92 */
93void
94print_gen(FILE *fp, Pool *pool, int generation)
95{
96 int lowest;
97
98 /* Get index to lowest ranking gene in population. */
99 /* Use 2nd to last since last is buffer. */
100 lowest = pool->size > 1 ? pool->size - 2 : 0;
101
102 fprintf(fp,
103 "%5d | Best: %g Worst: %g Mean: %g Avg: %g\n",
104 generation,
105 pool->data[0].worth,
106 pool->data[lowest].worth,
107 pool->data[pool->size / 2].worth,
108 avg_pool(pool));
109
110 fflush(fp);
111}
112
113
114void
116{
117 int i,
118 j;
119
120 fprintf(fp, "\nEDGE TABLE\n");
121
122 for (i = 1; i <= num_gene; i++)
123 {
124 fprintf(fp, "%d :", i);
125 for (j = 0; j < edge_table[i].unused_edges; j++)
126 fprintf(fp, " %d", edge_table[i].edge_list[j]);
127 fprintf(fp, "\n");
128 }
129
130 fprintf(fp, "\n");
131
132 fflush(fp);
133}
134
135#endif /* GEQO_DEBUG */
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
return str start
int j
Definition isn.c:78
int i
Definition isn.c:77
static int fb(int x)
Cost worth
Definition geqo_gene.h:38
Gene * string
Definition geqo_gene.h:37
int string_length
Definition geqo_gene.h:45
int size
Definition geqo_gene.h:44
Chromosome * data
Definition geqo_gene.h:43