ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadical_report.cpp
Go to the documentation of this file.
1#include "global.h"
2
3#include "internal.hpp"
4
6
7namespace CaDiCaL {
8
9#ifndef CADICAL_QUIET
10
11/*------------------------------------------------------------------------*/
12
13// Provide nicely formatted progress report messages while running through
14// the 'report' function below. The code is so complex, because it should
15// be easy to add and remove reporting of certain statistics, while still
16// providing a nicely looking format with automatically aligned headers.
17
18/*------------------------------------------------------------------------*\
19
20The 'reports' are shown as 'c <char> ...' with '<char>' as follows:
21
22i propagated learned unit clause
23O backtracked after phases reset to original phase
24F backtracked after flipping phases
25# backtracked after randomly setting phases
26B backtracked after resetting to best phases
27W backtracked after local search improved phases
28b blocked clause elimination
29G before garbage collection
30C after garbage collection
31/ compacted internal literals and remapped external to internal
32c covered clause elimination
33d decomposed binary implication graph and substituted equivalent literals
342 removed duplicated binary clauses
35e bounded variable elimination round
36^ variable elimination bound increased
37I variable instantiation
38[ start of stable search phase
39] end of stable search phase
40{ start of unstable search phase
41} end of unstable search phase
42P preprocessing round (capital 'P')
43L local search round
44* start of solving without the need to restore clauses
45+ start of solving before restoring clauses
46r start of solving after restoring clauses
471 end of solving returns satisfiable
480 end of solving returns unsatisfiable
49? end of solving due to interrupt
50l lucky phase solving
51p failed literal probing round (lower case 'p')
52. before reducing redundant clauses
53f flushed redundant clauses
54- reduced redundant clauses
55~ start of resetting phases
56R restart
57s subsumed clause removal round
583 ternary resolution round
59t transition reduction of binary implication graph
60u vivified tier1 clauses
61v vivified tier2 clauses
62x vivified tier3 clauses
63w vivified irredundant clauses
64
65The order of the list follows the occurrences of 'report' in the source
66files, i.e., obtained from "grep 'report (' *.cpp". Note that some of the
67reports are only printed for higher verbosity level (for instance 'R').
68
69\*------------------------------------------------------------------------*/
70
71struct Report {
72
73 const char *header;
74 char buffer[32];
75 int pos;
76
77 Report (const char *h, int precision, int min, double value);
78 Report () {}
79
80 void print_header (char *line);
81};
82
83/*------------------------------------------------------------------------*/
84
85void Report::print_header (char *line) {
86 int len = strlen (header);
87 for (int i = -1, j = pos - (len + 1) / 2 - 3; i < len; i++, j++)
88 line[j] = i < 0 ? ' ' : header[i];
89}
90
91Report::Report (const char *h, int precision, int min, double value)
92 : header (h) {
93 char fmt[32];
94 if (precision < 0)
95 snprintf (fmt, sizeof fmt, "%%.%df", -precision - 1);
96 else
97 snprintf (fmt, sizeof fmt, "%%.%df", precision);
98 snprintf (buffer, sizeof buffer, fmt, value);
99 const int width = strlen (buffer);
100 if (precision < 0)
101 strcat (buffer, "%");
102 if (width >= min)
103 return;
104 if (precision < 0)
105 snprintf (fmt, sizeof fmt, "%%%d.%df%%%%", min, -precision - 1);
106 else
107 snprintf (fmt, sizeof fmt, "%%%d.%df", min, precision);
108 snprintf (buffer, sizeof buffer, fmt, value);
109}
110
111/*------------------------------------------------------------------------*/
112
113// The following statistics are printed in columns, whenever 'report' is
114// called. For instance 'reduce' with prefix '-' will call it. The other
115// more interesting report is due to learning a unit, called iteration, with
116// prefix 'i'. To add another statistics column, add a corresponding line
117// here. If you want to report something else add 'report (..)' functions.
118
119#define TIME opts.reportsolve ? solve_time () : time ()
120
121#define MB (current_resident_set_size () / (double) (1l << 20))
122
123#define REMAINING (percent (active (), stats.variables_original))
124
125#define TRAIL (percent (averages.current.trail.slow, max_var))
126
127#define TARGET (percent (target_assigned, max_var))
128
129#define BEST (percent (best_assigned, max_var))
130
131#define REPORTS \
132 /* HEADER, PRECISION, MIN, VALUE */ \
133 REPORT ("seconds", 2, 5, TIME) \
134 REPORT ("MB", 0, 2, MB) \
135 REPORT ("level", 0, 2, averages.current.level) \
136 REPORT ("reductions", 0, 1, stats.reductions) \
137 REPORT ("restarts", 0, 3, stats.restarts) \
138 REPORT ("rate", 0, 2, averages.current.decisions) \
139 REPORT ("conflicts", 0, 4, stats.conflicts) \
140 REPORT ("redundant", 0, 4, stats.current.redundant) \
141 REPORT ("trail", -1, 2, TRAIL) \
142 REPORT ("glue", 0, 1, averages.current.glue.slow) \
143 REPORT ("irredundant", 0, 4, stats.current.irredundant) \
144 REPORT ("variables", 0, 3, active ()) \
145 REPORT ("remaining", -1, 2, REMAINING)
146
147// Note, keep an empty line before this line (because of '\')!
148
149#if 0 // ADDITIONAL STATISTICS TO REPORT
150
151REPORT("best", -1, 2, BEST) \
152REPORT("target", -1, 2, TARGET) \
153REPORT("maxvar", 0, 2, external->max_var)
154
155#endif
156
157static const int num_reports = // as compile time constant
158#define REPORT(HEAD, PREC, MIN, EXPR) 1 +
159 REPORTS
160#undef REPORT
161 0;
162
163/*------------------------------------------------------------------------*/
164
165void Internal::report (char type, int verbose) {
166 if (!opts.report)
167 return;
168#ifdef LOGGING
169 if (!opts.log)
170#endif
171 if (opts.quiet || (verbose > opts.verbose))
172 return;
173 if (!reported) {
174 CADICAL_assert (!lim.report);
175 reported = true;
176 MSG ("%stime measured in %s time %s%s", tout.magenta_code (),
177 internal->opts.realtime ? "real" : "process",
178 internal->opts.reportsolve ? "in solving" : "since initialization",
179 tout.normal_code ());
180 }
181 Report reports[num_reports];
182 int n = 0;
183#define REPORT(HEAD, PREC, MIN, EXPR) \
184 CADICAL_assert (n < num_reports); \
185 reports[n++] = Report (HEAD, PREC, MIN, (double) (EXPR));
186 REPORTS
187#undef REPORT
188 if (!lim.report) {
189 print_prefix ();
190 fputc ('\n', stdout);
191 int pos = 4;
192 for (int i = 0; i < n; i++) {
193 int len = strlen (reports[i].buffer);
194 reports[i].pos = pos + (len + 1) / 2;
195 pos += len + 1;
196 }
197 const int max_line = pos + 20, nrows = 3;
198 char *line = new char[max_line];
199 for (int start = 0; start < nrows; start++) {
200 int i;
201 for (i = 0; i < max_line; i++)
202 line[i] = ' ';
203 for (i = start; i < n; i += nrows)
204 reports[i].print_header (line);
205 for (i = max_line - 1; line[i - 1] == ' '; i--)
206 ;
207 line[i] = 0;
208 print_prefix ();
209 tout.yellow ();
210 fputs (line, stdout);
211 tout.normal ();
212 fputc ('\n', stdout);
213 }
214 print_prefix ();
215 fputc ('\n', stdout);
216 delete[] line;
217 lim.report = 19;
218 } else
219 lim.report--;
220 print_prefix ();
221 switch (type) {
222 case '[':
223 case ']':
224 tout.magenta (true);
225 break;
226 case 's':
227 case 'b':
228 case 'c':
229 tout.green (false);
230 break;
231 case 'e':
232 tout.green (true);
233 break;
234 case 'p':
235 case '2':
236 case '3':
237 case 'u':
238 case 'v':
239 case 'w':
240 case 'x':
241 case 'f':
242 case '=':
243 tout.blue (false);
244 break;
245 case 't':
246 tout.cyan (false);
247 break;
248 case 'd':
249 tout.blue (true);
250 break;
251 case 'z':
252 case '!':
253 tout.cyan (true);
254 break;
255 case '-':
256 tout.normal ();
257 break;
258 case '/':
259 tout.yellow (true);
260 break;
261 case 'a':
262 case 'n':
263 tout.red (false);
264 break;
265 case '0':
266 case '1':
267 case '?':
268 case 'i':
269 tout.bold ();
270 break;
271 case 'L':
272 case 'P':
273 tout.bold ();
274 tout.underline ();
275 break;
276 default:
277 break;
278 }
279 fputc (type, stdout);
280 if (stable || type == ']')
281 tout.magenta ();
282 else if (type != 'L' && type != 'P')
283 tout.normal ();
284 for (int i = 0; i < n; i++) {
285 fputc (' ', stdout);
286 fputs (reports[i].buffer, stdout);
287 }
288 if (stable || type == 'L' || type == 'P' || type == ']')
289 tout.normal ();
290 fputc ('\n', stdout);
291 fflush (stdout);
292}
293
294#else // ifndef CADICAL_QUIET
295
296void Internal::report (char, int) {}
297
298#endif
299
300} // namespace CaDiCaL
301
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define CADICAL_assert(ignore)
Definition global.h:14
ABC_NAMESPACE_IMPL_START typedef signed char value
const char * magenta_code()
Definition terminal.hpp:71
const char * normal_code()
Definition terminal.hpp:80
void blue(bool bright=false)
Definition terminal.hpp:58
void magenta(bool bright=false)
Definition terminal.hpp:59
void red(bool bright=false)
Definition terminal.hpp:55
void cyan(bool bright=false)
Definition terminal.hpp:61
void green(bool bright=false)
Definition terminal.hpp:56
void yellow(bool bright=false)
Definition terminal.hpp:57
bool pos
Definition globals.c:30
type
CUBE COVER and CUBE typedefs ///.
Definition exor.h:90
#define MSG(...)
Definition message.hpp:49
Terminal tout(stdout)
Definition terminal.hpp:97
#define TARGET(IDX)
Definition phases.h:23
#define BEST(IDX)
Definition phases.h:17
#define REPORT(...)
Definition report.h:10
void report(char type, int verbose_level=0)
int strlen()
char * strcat()