1 /*-------------------------------------------------------------------------*/
2 /* Copyright 2010-2014 Armin Biere Johannes Kepler University Linz Austria */
3 /*-------------------------------------------------------------------------*/
7 /*-------------------------------------------------------------------------*/
18 #include <sys/resource.h>
22 /*-------------------------------------------------------------------------*/
36 /*-------------------------------------------------------------------------*/
38 #define REMOVED INT_MAX
39 #define NOTALIT ((INT_MAX >> RMSHFT))
40 #define MAXVAR ((INT_MAX >> RMSHFT) - 2)
43 #define POW2GLUE (1 << GLUESHFT)
44 #define MAXGLUE (POW2GLUE - 1)
45 #define GLUEMASK (POW2GLUE - 1)
46 #define MAXREDLIDX ((1 << (31 - GLUESHFT)) - 2)
47 #define MAXIRRLIDX ((1 << (31 - RMSHFT)) - 2)
53 #define FUNQUADS (1<<(FUNVAR - 6))
54 #define FALSECNF (1ll<<32)
58 #define EXPMIN (0x0000 ## 0000)
59 #define EXPZRO (0x1000 ## 0000)
60 #define EXPMAX (0x7fff ## ffff)
61 #define MNTBIT (0x0000 ## 0001 ## 0000 ## 0000 ## ull)
62 #define MNTMAX (0x0000 ## 0001 ## ffff ## ffff ## ull)
63 #define FLTMIN (0x0000 ## 0000 ## 0000 ## 0000 ## ll)
64 #define FLTMAX (0x7fff ## ffff ## ffff ## ffff ## ll)
66 #define LGL_SCORE_AVG 4
67 #define LGL_SCORE_EVSIDS 5
68 #define LGL_SCORE_VSIDS256 6
69 #define LGL_SCORE_FAVG 7
72 #define MAXSCOREXP (1<<30)
74 #define MAXSCOREXP (1<<9)
77 #define DEFSCOREXP 500
84 /*------------------------------------------------------------------------*/
86 /*------------------------------------------------------------------------*/
88 #define MAPLOGLEVEL(LEVEL) (LEVEL)
90 #define LOG(LEVEL,FMT,ARGS...) \
92 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
93 lglogstart (lgl, MAPLOGLEVEL(LEVEL), FMT, ##ARGS); \
97 #define LOGCLS(LEVEL,CLS,FMT,ARGS...) \
100 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
101 lglogstart (lgl, MAPLOGLEVEL(LEVEL), FMT, ##ARGS); \
102 for (P = (CLS); *P; P++) fprintf (lgl->out, " %d", *P); \
106 #define LOGMCLS(LEVEL,CLS,FMT,ARGS...) \
109 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
110 lglogstart (lgl, MAPLOGLEVEL(LEVEL), FMT, ##ARGS); \
111 for (P = (CLS); *P; P++) fprintf (lgl->out, " %d", lglm2i (lgl, *P)); \
115 #define LOGRESOLVENT(LEVEL,FMT,ARGS...) \
118 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
119 lglogstart (lgl, MAPLOGLEVEL(LEVEL), FMT, ##ARGS); \
120 for (P = lgl->resolvent.start; P < lgl->resolvent.top; P++) \
121 fprintf (lgl->out, " %d", *P); \
125 #define LOGREASON(LEVEL,LIT,REASON0,REASON1,FMT,ARGS...) \
127 int TAG, TMP, RED, G; \
128 const int * C, * P; \
129 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
130 lglogstart (lgl, MAPLOGLEVEL(LEVEL), FMT, ##ARGS); \
131 TMP = (REASON0 >> RMSHFT); \
132 RED = (REASON0 & REDCS); \
133 TAG = (REASON0 & MASKCS); \
134 if (TAG == DECISION) fputs (" decision", lgl->out); \
135 else if (TAG == UNITCS) fprintf (lgl->out, " unit %d", LIT); \
136 else if (TAG == BINCS) { \
138 " %s binary clause %d %d", lglred2str (RED), LIT, TMP); \
139 } else if (TAG == TRNCS) { \
140 fprintf (lgl->out, " %s ternary clause %d %d %d", \
141 lglred2str (RED), LIT, TMP, REASON1); \
143 assert (TAG == LRGCS); \
144 C = lglidx2lits (lgl, RED, REASON1); \
145 for (P = C; *P; P++) \
147 fprintf (lgl->out, " size %ld", (long)(P - C)); \
149 G = (REASON1 & GLUEMASK); \
150 fprintf (lgl->out, " glue %d redundant", G); \
151 } else fputs (" irredundant", lgl->out); \
152 fputs (" clause", lgl->out); \
153 for (P = C; *P; P++) { \
154 fprintf (lgl->out, " %d", *P); \
160 #define LOGDSCHED(LEVEL,LIT,FMT,ARGS...) \
163 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
164 POS = *lgldpos (lgl, LIT); \
165 lglogstart (lgl, MAPLOGLEVEL(LEVEL), "dsched[%d] = %d ", POS, LIT); \
166 printf (FMT, ##ARGS); \
167 printf (" score %s", lglscr2str (lgl, lglqvar (lgl, LIT)->score)); \
171 #define LOGESCHED(LEVEL,LIT,FMT,ARGS...) \
175 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
176 POS = *lglepos (lgl, LIT); \
177 EV = lglevar (lgl, LIT); \
178 lglogstart (lgl, MAPLOGLEVEL(LEVEL), "esched[%d] = %d ", POS, LIT); \
179 fprintf (lgl->out, FMT, ##ARGS); \
180 fprintf (lgl->out, " score"); \
181 fprintf (lgl->out, " occ %d %d", EV->occ[0], EV->occ[1]); \
185 #define LOGEQN(LEVEL,EQN,FMT,ARGS...) \
187 const int * P, * START; \
188 if (MAPLOGLEVEL(LEVEL) > lgl->opts->log.val) break; \
189 lglogstart (lgl, MAPLOGLEVEL(LEVEL), FMT, ##ARGS); \
190 START = lgl->gauss->xors.start + (EQN); \
191 assert (START < lgl->gauss->xors.top); \
192 for (P = START; *P > 1; P++) fprintf (lgl->out, " %d", *P); \
193 fprintf (lgl->out, " = %d", *P); \
197 /*------------------------------------------------------------------------*/
198 #else /* end of then start of else part of 'ifndef NLGLOG' */
199 /*------------------------------------------------------------------------*/
201 #define LOG(ARGS...) do { } while (0)
202 #define LOGCLS(ARGS...) do { } while (0)
203 #define LOGMCLS(ARGS...) do { } while (0)
204 #define LOGRESOLVENT(ARGS...) do { } while (0)
205 #define LOGREASON(ARGS...) do { } while (0)
206 #define LOGDSCHED(ARGS...) do { } while (0)
207 #define LOGESCHED(ARGS...) do { } while (0)
208 #define LOGEQN(ARGS...) do { } while (0)
210 /*------------------------------------------------------------------------*/
211 #endif /* end of else part of 'ifndef NLGLOG' */
212 /*------------------------------------------------------------------------*/
214 #define ABORTIF(COND,FMT,ARGS...) \
216 if (!(COND)) break; \
217 fprintf (stderr, "*** API usage error of '%s' in '%s'", \
218 __FILE__, __FUNCTION__); \
219 if (lgl && lgl->tid >= 0) fprintf (stderr, " (tid %d)", lgl->tid); \
220 fputs (": ", stderr); \
221 fprintf (stderr, FMT, ##ARGS); \
222 fputc ('\n', stderr); \
228 // Useful for using our 'sleeponabort' and other hooks 'on abort' ...
231 #define ASSERT(COND) \
235 "liblgl.a: %s:%d: %s: Lingeling Assertion `%s' failed.", \
236 __FUNCTION__, __LINE__, __FILE__, # COND); \
237 if (lgl && lgl->tid >= 0) fprintf (stderr, " (tid %d)", lgl->tid); \
238 fputc ('\n', stderr); \
244 #define ASSERT(COND) do { } while (0)
247 #define COVER(COND) \
249 if (!(COND)) break; \
251 "liblgl.a: %s:%d: %s: Coverage target `%s' reached.", \
252 __FUNCTION__, __LINE__, __FILE__, # COND); \
253 if (lgl && lgl->tid >= 0) fprintf (stderr, " (tid %d)", lgl->tid); \
254 fputc ('\n', stderr); \
256 abort (); /* TODO: why not 'lglabort' */ \
261 ABORTIF (!lgl, "uninitialized manager"); \
264 #define REQINITNOTFORKED() \
267 ABORTIF (lgl->forked, "forked manager"); \
270 #define REQUIRE(STATE) \
273 ABORTIF(!(lgl->state & (STATE)), "!(%s)", #STATE); \
276 #define TRANS(STATE) \
278 assert (lgl->state != STATE); \
279 LOG (1, "transition to state " #STATE); \
280 lgl->state = STATE; \
283 /*------------------------------------------------------------------------*/
285 #if !defined(NDEBUG) || !defined(NLGLOG)
289 /*------------------------------------------------------------------------*/
291 #define TRAPI(MSG,ARGS...) \
293 if (!lgl->apitrace) break; \
294 lgltrapi (lgl, MSG, ##ARGS); \
297 #define LGLCHKACT(ACT) \
298 do { assert (NOTALIT <= (ACT) && (ACT) < REMOVED - 1); } while (0)
300 /*------------------------------------------------------------------------*/
302 #define OPT(SHRT,LNG,VAL,MIN,MAX,DESCRP) \
304 Opt * opt = &lgl->opts->LNG; \
307 opt->dflt = opt->val = VAL; \
308 assert (MIN <= VAL); \
310 assert (VAL <= MAX); \
312 opt->descrp = DESCRP; \
313 lglgetenv (lgl, opt, #LNG); \
316 /*------------------------------------------------------------------------*/
319 do { (P) = lglnew (lgl, (N) * sizeof *(P)); } while (0)
322 do { lgldel (lgl, (P), (N) * sizeof *(P)); (P) = 0; } while (0)
325 do { (P) = lglrsz (lgl, (P), (O)*sizeof*(P), (N)*sizeof*(P)); } while (0)
328 do { memset ((P), 0, (N) * sizeof *(P)); } while (0)
331 do { memset ((P), 0, sizeof *(P)); } while (0)
334 do { memset (&(P), 0, sizeof (P)); } while (0)
336 /*------------------------------------------------------------------------*/
338 #define SWAP(TYPE,A,B) \
339 do { TYPE TMP = (A); (A) = (B); (B) = TMP; } while (0)
343 #define CMPSWAP(TYPE,CMP,P,Q) \
344 do { if (CMP (&(P), &(Q)) > 0) SWAP (TYPE, P, Q); } while(0)
346 #define QPART(TYPE,CMP,A,L,R) \
353 while (CMP (&(A)[++I], &PIVOT) < 0) \
355 while (CMP (&PIVOT, &(A)[--J]) < 0) \
356 if (J == (L)) break; \
358 SWAP (TYPE, (A)[I], (A)[J]); \
360 SWAP (TYPE, (A)[I], (A)[R]); \
363 #define QSORT(TYPE,CMP,A,N) \
365 int L = 0, R = (N) - 1, M, LL, RR, I; \
366 assert (lglmtstk (&lgl->sortstk)); \
367 if (R - L <= ISORTLIM) break; \
370 SWAP (TYPE, (A)[M], (A)[R - 1]); \
371 CMPSWAP (TYPE, CMP, (A)[L], (A)[R - 1]); \
372 CMPSWAP (TYPE, CMP, (A)[L], (A)[R]); \
373 CMPSWAP (TYPE, CMP, (A)[R - 1], (A)[R]); \
374 QPART (TYPE, CMP, (A), L + 1, R - 1); \
375 if (I - L < R - I) { LL = I + 1; RR = R; R = I - 1; } \
376 else { LL = L; RR = I - 1; L = I + 1; } \
377 if (R - L > ISORTLIM) { \
378 assert (RR - LL > ISORTLIM); \
379 lglpushstk (lgl, &lgl->sortstk, LL); \
380 lglpushstk (lgl, &lgl->sortstk, RR); \
381 } else if (RR - LL > ISORTLIM) L = LL, R = RR; \
382 else if (!lglmtstk (&lgl->sortstk)) { \
383 R = lglpopstk (&lgl->sortstk); \
384 L = lglpopstk (&lgl->sortstk); \
389 #define ISORT(TYPE,CMP,A,N) \
392 int L = 0, R = (N) - 1, I, J; \
393 for (I = R; I > L; I--) \
394 CMPSWAP (TYPE, CMP, (A)[I - 1], (A)[I]); \
395 for (I = L + 2; I <= R; I++) { \
398 while (CMP (&PIVOT, &(A)[J - 1]) < 0) { \
399 (A)[J] = (A)[J - 1]; \
407 #define CHKSORT(CMP,A,N) do { } while(0)
409 #define CHKSORT(CMP,A,N) \
412 for (I = 0; I < (N) - 1; I++) \
413 assert (CMP (&(A)[I], &(A)[I + 1]) <= 0); \
417 #define SORT(TYPE,A,N,CMP) \
421 QSORT (TYPE, CMP, AA, NN); \
422 ISORT (TYPE, CMP, AA, NN); \
423 CHKSORT (CMP, AA, NN); \
426 /*------------------------------------------------------------------------*/
428 #define LGLPOPWTK(WTK,WRAG,LIT,OTHER,RED,REMOVED) \
430 assert (!lglmtwtk (WTK)); \
432 (WRAG) = (WTK)->top->wrag; \
433 (LIT) = (WTK)->top->lit; \
434 (OTHER) = (WTK)->top->other; \
435 (RED) = (WTK)->top->red ? REDCS : 0; \
436 (REMOVED) = (WTK)->top->removed; \
439 /*------------------------------------------------------------------------*/
441 #define CLONE(FIELD,SIZE) \
443 NEW (lgl->FIELD, (SIZE)); \
444 memcpy (lgl->FIELD, orig->FIELD, (SIZE) * sizeof *(lgl->FIELD)); \
447 #define CLONESTK(NAME) \
449 size_t COUNT = orig->NAME.top - orig->NAME.start; \
450 size_t SIZE = orig->NAME.end - orig->NAME.start; \
451 size_t BYTES = SIZE * sizeof *lgl->NAME.start; \
452 NEW (lgl->NAME.start, SIZE); \
453 memcpy (lgl->NAME.start, orig->NAME.start, BYTES); \
454 lgl->NAME.top = lgl->NAME.start + COUNT; \
455 lgl->NAME.end = lgl->NAME.start + SIZE; \
458 /*------------------------------------------------------------------------*/
460 #define INCSTEPS(NAME) \
461 ((lgl->stats->steps++), (lgl->stats->NAME++))
463 #define ADDSTEPS(NAME,INC) \
464 ((lgl->stats->steps += INC), (lgl->stats->NAME += INC))
466 /*------------------------------------------------------------------------*/
468 #define LGLUPDPEN(NAME,SUCCESS) \
470 assert (!lgl->limits->NAME.del.rem); \
471 if ((SUCCESS) && lgl->limits->NAME.pen) \
472 lgl->limits->NAME.pen--; \
473 if (!(SUCCESS) && lgl->limits->NAME.pen < lgl->opts->penmax.val) \
474 lgl->limits->NAME.pen++; \
475 if ((SUCCESS) && lgl->limits->NAME.del.cur) \
476 lgl->limits->NAME.del.cur /= 2; \
477 if (!(SUCCESS) && lgl->limits->NAME.del.cur < lgl->opts->delmax.val) \
478 lgl->limits->NAME.del.cur++; \
479 lgl->limits->NAME.del.rem = lgl->limits->NAME.del.cur; \
482 /*-------------------------------------------------------------------------*/
484 #define LGLL long long
486 /*-------------------------------------------------------------------------*/
514 UNSATISFIED = (1<<7),
527 typedef enum GTag { ANDTAG, ITETAG, XORTAG } GTag;
529 /*------------------------------------------------------------------------*/
533 const char * lng, * descrp;
534 int val, min, max, dflt;
537 typedef struct Opts {
588 Opt bumpseenaftermin;
589 Opt bumpseenbeforemin;
759 Opt prbsimpleliftdepth;
879 #define FIRSTOPT(lgl) (&(lgl)->opts->beforefirst + 1)
880 #define LASTOPT(lgl) (&(lgl)->opts->afterlast - 1)
882 /*------------------------------------------------------------------------*/
885 typedef uint64_t Mnt;
888 typedef uint64_t Fun[FUNQUADS];
889 typedef signed char Val;
892 /*------------------------------------------------------------------------*/
898 /*------------------------------------------------------------------------*/
900 typedef struct Conf { int lit, rsn[2]; } Conf;
901 typedef struct Ctk { struct Ctr * start, * top, * end; } Ctk;
902 typedef struct DFOPF { int observed, pushed, flag; } DFOPF;
903 typedef struct DFPR { int discovered, finished, parent, root; } DFPR;
904 typedef struct EVar { int occ[2], pos, score; } EVar;
905 typedef struct Ftk { Flt * start, * top, * end; } Ftk;
906 typedef struct HTS { int offset, count; } HTS;
907 typedef struct ITEC { int other, other2; } ITEC;
908 typedef struct Lim { int64_t confs, decs, props; } Lim;
909 typedef struct PASL { int psm, act, size, lidx; } PASL;
910 typedef struct PSz { int pos, size; } PSz;
911 typedef struct Qnd { int prev, next; struct Qln * line; } Qnd;
912 typedef struct RNG { unsigned z, w; } RNG;
913 typedef struct Stk { int * start, * top, * end; } Stk;
914 typedef struct Tmrs { double phase[MAXPHN]; int idx[MAXPHN], nest; } Tmrs;
915 typedef struct Trv { void * state; void (*trav)(void *, int); } Trv;
916 typedef struct TVar { signed int val : 30; unsigned mark : 2; } TVar;
917 typedef struct Wtk { struct Work * start, * top, * end; } Wtk;
919 /*------------------------------------------------------------------------*/
922 signed int decision : 31;
926 typedef struct DVar { HTS hts[2]; } DVar;
928 typedef struct QVar { Scr score; int pos; } QVar;
932 unsigned lrglue:1, irr:1;
936 typedef struct ID { int level, lit, rsn[2]; } ID;
938 typedef struct Impls { ID * start, * top, * end; } Impls;
940 typedef struct AVar {
943 unsigned simp:1, wasfalse:1;
945 unsigned equiv:1, lcamark:4;
946 signed int phase:2, bias:2, fase:2;
947 unsigned inred:2, poisoned:1, assumed:2, failed:2, gate:1;
948 unsigned donotelm:1, donotblk:1, donotcgrcls:1, donotlft:1, donoternres:1;
949 unsigned donotbasicprobe:1, donotsimpleprobe:1, donotreelook:1, mega:2;
951 signed int locsval:2;
957 unsigned equiv:1,melted:1,blocking:2,eliminated:1,tmpfrozen:1,imported:1;
958 unsigned assumed:2,failed:2,internal:1,defined:1;
959 signed int val:2, oldval:2;
963 typedef struct Work {
965 signed int lit : 30, other : 30;
966 unsigned red : 1, removed : 1;
970 int discovered, finished;
971 union { int lit, sign; };
981 signed int size : 29;
984 struct { int * cls, origlhs; };
985 struct { int cond, pos, neg; };
989 /*------------------------------------------------------------------------*/
991 typedef struct Stats {
992 int64_t steps, trims;
993 int defrags, iterations, acts, reported, repcntdown, gcs, decomps;
995 struct { int64_t count, steps; struct { int max, min; } mincut; } force;
996 struct { int clauses, vars; } rescored;
998 struct {int64_t scaled, orig; } intsum;
999 struct { int count, saturating, agile, reuse; } skipped;
1000 struct { int count; int64_t sum; } kept; } restarts;
1001 struct { int count, reset, geom, gul, arith, arith2, memlim; } reduced;
1002 int64_t prgss, irrprgss, enlwchs, pshwchs, height, dense, sparse;
1003 int64_t confs, decisions, randecs, randecsflipped, flipped, fliphases;
1004 int64_t uips, decflipped;
1005 struct { struct { int cur, max; int64_t add; } clauses, lits; } irr;
1006 struct { int64_t sat, mosat, simp, deref, fixed, freeze, lkhd;
1007 int64_t melt, add, assume, cassume, failed, repr; } calls;
1008 struct { int64_t search, hits; } poison;
1009 struct { int64_t search, simp, lkhd; } props, visits, travs;
1010 struct { size_t current, max; } bytes;
1011 struct { int bin, trn, lrg; } red;
1012 struct { int cnt, simple, trn, lrg, sub; } hbr;
1013 struct { int current, sum; } fixed, equiv;
1014 struct { int count, bin, trn; int64_t steps; } trnr;
1015 struct { int count, clauses, lits, pure; int64_t res, steps; } blk;
1016 struct { int count, eq, units; int64_t esteps, csteps;
1017 struct { int all, and, xor, ite; } matched;
1018 struct { int all, and, xor, ite; } simplified;
1019 struct { int64_t all, and, xor, ite; } extracted; } cgr;
1021 struct { int count, failed, eqs; int64_t probed, steps; } simple;
1022 struct { int count, failed, lifted;
1023 int64_t probed, steps, lastate;
1024 struct { int trnr, lrg, count; } ate; } basic;
1025 struct { int count, failed, lifted; int64_t probed, steps; } treelook;
1027 struct { int count, eqs, units, impls; int64_t probed0, probed1; } lift;
1028 struct { int count, red, failed; int64_t lits, bins, steps; } trd;
1029 struct { int removed, red; } bindup;
1030 struct { int count, rounds;
1031 struct { int trds, failed, sccs; int64_t sumsccsizes; } stamp;
1032 struct { int lits, bin, trn, lrg; } failed;
1033 struct { int bin, trn, lrg, red; } tauts;
1034 struct { int bin, trn, lrg; } units;
1035 struct { int trn, lrg, red; } hbrs;
1036 struct { int trn, lrg, red; } str;
1037 int64_t steps; } unhd;
1039 int count, elmd, large, sub, str, blkd, rounds;
1040 struct { int elm, tried, failed; } small;
1041 int64_t resolutions, copies, subchks, strchks, ipos, steps; } elm;
1043 int sub2, sub3, subl, str2, str3, str3self, strl, strlself;
1044 struct { int64_t lits, clauses, occs; } tried;
1048 struct { struct { int irr, red; } dyn; } sub, str;
1049 int64_t driving, restarting; } otfs;
1050 struct { int64_t nonmin, learned; } lits;
1052 int64_t learned, glue, realglue, nonmaxglue, maxglue, scglue; }
1056 int64_t added, reduced, resolved, forcing, conflicts, saved;
1058 struct { int64_t sum; int count; } glues;
1059 struct { int count; int64_t set, pos, neg; } phase;
1060 struct { int count; struct { int confs, irr, vars; } limhit; } simp;
1061 struct { int count; int64_t steps; } luby, inout;
1062 struct { int count, gcs, units, equivs, trneqs;
1063 struct { int max; int64_t sum; } arity;
1064 struct { int64_t extr, elim; } steps;
1065 int64_t extracted; } gauss;
1066 struct { int count, eliminated, ate, abce, failed, lifted;
1067 int64_t steps, probed;
1068 struct { int64_t search, hits, cols, ins, rsz; } cache; } cce;
1069 struct { int count, failed, lifted; int64_t decisions, steps; } cliff;
1071 int count, units, expam1, resched;
1072 int64_t steps, eliminated, resolved, subsumed;
1073 struct { struct { int64_t sum, cnt; } found, used; } am1, am2; } card;
1074 struct { int64_t bin, trn, lrg; } moved;
1075 struct { int count, inc; } rephase;
1076 struct { int count; int64_t added, skipped, steps; } bca;
1077 struct { int count; int64_t added, removed; } bva;
1081 struct { int64_t actual, tried, calls; } consumed;
1084 struct { struct { int64_t orig, red; } sum; } deco;
1085 struct { int64_t min, bin, size, deco; } mincls;
1086 int64_t drupped, druplig;
1088 int64_t count, units, bin, trn, steps, elim, res;
1089 struct { int64_t bound, len, model; } limhit; } rdp;
1090 struct { int64_t count, tried, cands, sub; } subl;
1091 struct { int count; int64_t flips, mems; int min; } locs;
1092 struct { int count; } tabr;
1093 struct { int count, failed, lifted, eqs, rounds; } mega;
1096 /*------------------------------------------------------------------------*/
1098 typedef struct Times {
1099 double all, dcp, elm, trd, gc, dfg, red, blk, ana, unhd, dec, lkhd;
1100 double rsts, lft, trn, cgr, phs, srch, prep, inpr, bump, mcls, gauss;
1101 double card, cce, cliff, ctw, force, bca, rdp, locs, bkwd, bva, tabr;
1103 struct { double all, simple, basic, treelook; } prb;
1106 /*------------------------------------------------------------------------*/
1108 typedef struct Del { int cur, rem; } Del;
1110 typedef struct Limits {
1111 int flipint, lkhdpen;
1112 int64_t randec, dfg;
1115 struct { int64_t add; int start; } clauses;
1116 struct { int start; } vars;
1118 struct { int clauses, vars; } tabr;
1119 struct { int inner, outer, extra; } reduce;
1120 struct { struct { int64_t otfs, confs; } vars; } rescore;
1121 struct { int pen; Del del; int64_t esteps, csteps; } cgr;
1122 struct { int pen; Del del; int64_t steps, irrprgss; } elm, blk, cliff;
1123 struct { int pen; Del del; int64_t steps; }
1124 rdp, trd, unhd, trnr, lft, cce, card;
1125 struct { int pen; Del del; struct { int64_t extr, elim; } steps; } gauss;
1126 struct { int64_t confs; } rephase;
1127 struct { int64_t confs; int wasmaxdelta, maxdelta, luby, inout; } restart;
1128 struct { int64_t steps;
1129 struct { int pen; Del del; } simple, basic, treelook; } prb;
1130 struct { int64_t vars, confs; int pen, cinc; } simp;
1131 struct { int64_t steps, confs; } sync;
1132 struct { int64_t steps; } term;
1133 struct { int64_t fixed; } gc;
1134 struct { Del del; int64_t steps; } bca;
1135 struct { int64_t steps, time; } trep;
1136 struct { int64_t confs, inc; int vars; } locs;
1139 /*------------------------------------------------------------------------*/
1141 typedef struct Cbs {
1142 struct { int (*fun)(void*); void * state; int done; } term;
1144 struct { void (*fun)(void*,int); void * state; } produce, consumed;
1145 struct { void(*fun)(void*,int**,int**); void*state; } consume;
1148 struct { void (*fun)(void*,int*,int); void * state; } produce;
1149 struct { void(*fun)(void*,int**,int*); void*state; } consume;
1150 struct { void (*fun)(void*,int); void * state; } consumed;
1153 struct { int * (*fun)(void*); void * state; } lock;
1154 struct { void (*fun)(void*,int,int); void * state; } unlock;
1156 struct { void(*lock)(void*); void (*unlock)(void*); void*state; } msglock;
1157 double (*getime)(void);
1158 void (*onabort)(void *); void * abortstate;
1161 typedef struct Cgr {
1162 struct { int units, eq, all, and, xor, ite, org; } extracted;
1163 struct { int all, and, xor, ite, org; } simplified;
1164 struct { int all, and, xor, ite, org; } matched;
1165 Stk * goccs, units; Gat * gates; int szgates;
1168 typedef struct Cliff { Stk lift, lits; } Cliff;
1170 typedef struct BCA { Stk covered; } BCA;
1172 typedef struct Dis { struct { Stk bin, trn; } red, irr; } Dis;
1174 typedef struct Elm {
1176 int pivot, negcls, necls, neglidx, round, oldelmd;
1177 Stk lits, next, clv, csigs, sizes, occs, noccs, mark, m2i;
1180 typedef struct RDP {
1181 int * count, eliminated;
1186 typedef struct Card {
1187 Stk atmost1, atmost2, cards, elim, * occs, units, expam1;
1188 char * eliminated, * lit2used, * marked;
1189 signed char * count;
1193 typedef struct FltStr { int current; char str[MAXFLTSTR][100]; } FltStr;
1195 typedef struct SPE { signed int count : 31; unsigned mark : 1, sum; } SPE;
1197 typedef struct SPrb {
1198 Stk units, impls, eqs, counted, marked;
1202 typedef struct Gauss {
1203 Stk xors, order, * occs;
1204 signed char * eliminated;
1208 typedef struct CCE {
1209 Stk cla, extend, clauses;
1210 int * rem, bin, trn;
1213 typedef struct Tlk { Stk stk, seen; TVar * tvars; LKHD * lkhd; } Tlk;
1215 typedef struct Mem {
1217 lglalloc alloc; lglrealloc realloc; lgldealloc dealloc;
1220 typedef struct Wchs { Stk stk; int start[MAXLDFW], free; } Wchs;
1222 typedef struct Wrk {
1224 int count, head, size, posonly, fifo, * pos;
1227 /*------------------------------------------------------------------------*/
1232 int probing, flipping, notflipped, tid, tids, bias, phaseneg;
1233 int nvars, szvars, maxext, szext, maxdef, szdef, changed, mt, repcntdown;
1234 int szdrail, bnext, next, next2, flushed, level, alevel, wait;
1235 int unassigned, lrgluereasons, failed, assumed, cassumed, ncassumed;
1237 Scr scinc, scincf, maxscore;
1239 char lifting, cceing, gaussing, cliffing, bcaing, forcerephead;
1240 char cgrclosing, searching, simp, allphaseset, flushphases, occs;
1241 char unhiding, basicprobing, simpleprobing, treelooking, setuponce;
1242 char eliminating, donotsched, blocking, ternresing, lkhd, allfrozen;
1243 char blkall, blkrem, blkrtc, elmall, elmrem, elmrtc, decomposing;
1244 char frozen, dense, notfullyconnected, forcegc, allowforce;
1245 char ccertc, elmstuck, blkstuck;
1250 unsigned long long flips;
1255 // the state above this line is copied during 'clone' with 'memcpy'
1276 Stk clause, eclause, extend, irr, trail, frames;
1277 Stk dsched, eassume, assume, cassume, fassume, learned;
1283 Elm * elm; Cgr * cgr; SPrb * sprb; Tlk * tlk; Gauss * gauss;
1284 CCE * cce; Cliff * cliff; BCA * bca; Card * card; RDP * rdp;
1286 union { Stk lcaseen, sortstk, resolvent; };
1287 Stk poisoned, seen, esched, minstk;
1294 FILE * out, * apitrace;
1301 #if !defined(NLGLPICOSAT)
1302 struct { PicoSAT * solver; int res; char chk; } picosat;
1304 #if !defined(NLGLDRUPLIG)
1309 /*-------------------------------------------------------------------------*/
1311 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
1313 static const char lglfloorldtab[256] =
1315 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1316 -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
1317 LT(4), LT(5), LT(5), LT(6), LT(6), LT(6), LT(6),
1318 LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
1321 static const uint64_t lglbasevar2funtab[6] = {
1322 0xaaaaaaaaaaaaaaaaull, 0xccccccccccccccccull, 0xf0f0f0f0f0f0f0f0ull,
1323 0xff00ff00ff00ff00ull, 0xffff0000ffff0000ull, 0xffffffff00000000ull,
1326 /*-------------------------------------------------------------------------*/
1328 static int lglfloorld (int n) {
1330 if (n < (1<<8)) return lglfloorldtab[n];
1331 if (n < (1<<16)) return 8 + lglfloorldtab[n>>8];
1332 if (n < (1<<24)) return 16 + lglfloorldtab[n>>16];
1333 return 24 + lglfloorldtab[n>>24];
1336 static int lglispow2 (int n) {
1337 assert (0 <= n && n <= INT_MAX);
1338 return !(n & (n - 1));
1341 static int lglceilld (int n) {
1342 int res = lglfloorld (n);
1343 if (!lglispow2 (n)) res++;
1347 static int lglceilsqrt32 (int x) {
1348 int l = 0, m, r, mm, rr;
1352 if (x <= 0) return 0;
1353 r = 46340; rr = r*r;
1354 if (x >= rr) return r;
1357 assert (ll < x && x < rr);
1358 if (r - l == 1) return r;
1361 if (mm == x) return m;
1367 } else r = m, rr = mm;
1371 static int lglceilsqrt64 (int x) {
1372 int64_t l = 0, m, r, mm, rr;
1376 if (x <= 0) return 0;
1377 r = 3037000499ll; rr = r*r;
1378 if (x >= rr) return r;
1381 assert (ll < x && x < rr);
1382 if (r - l == 1) return r;
1385 if (mm == x) return m;
1391 } else r = m, rr = mm;
1395 static void lglchkflt (Flt a) {
1398 assert (FLTMAX >= (uint64_t) a);
1404 static Exp lglexp (Flt a) {
1405 Exp res = a >> FLTPRC;
1406 assert (0 <= res && res <= EXPMAX);
1411 static Mnt lglmnt (Flt a) {
1412 Mnt res = a & MNTMAX;
1414 assert (res <= MNTMAX);
1418 static Flt lglflt (Exp e, Mnt m) {
1420 if (!m) return FLTMIN;
1422 while (!(m & MNTBIT)) {
1424 if (e > INT_MIN) e--;
1428 while (m > MNTMAX) {
1430 if (e > INT_MIN) e++;
1434 if (e < -EXPZRO) return FLTMIN;
1435 if (e > EXPMAX - EXPZRO) return FLTMAX;
1437 assert (0 <= e && e <= EXPMAX);
1438 assert (m <= MNTMAX);
1439 assert (m & MNTBIT);
1441 res |= ((Flt)e) << FLTPRC;
1446 static Flt lglrat (unsigned n, unsigned d) {
1449 if (!n) return FLTMIN;
1450 if (!d) return FLTMAX;
1453 while (!(m & (1ull << 63))) m <<= 1, e--;
1455 return lglflt (e, m);
1460 double lglflt2dbl (Flt a) {
1461 return lglmnt (a) * pow (2.0, lglexp (a));
1466 static const char * lgll2str (LGL * lgl, Flt a) {
1467 assert (lgl->fltstr);
1468 lgl->fltstr->current++;
1469 if (lgl->fltstr->current == MAXFLTSTR) lgl->fltstr->current = 0;
1470 sprintf (lgl->fltstr->str[lgl->fltstr->current], "%lld", (LGLL) a);
1471 return lgl->fltstr->str[lgl->fltstr->current];
1475 static const char * lglflt2str (LGL * lgl, Flt a) {
1477 assert (lgl->fltstr);
1478 if (a == FLTMIN) return "0";
1479 if (a == FLTMAX) return "inf";
1484 lgl->fltstr->current++;
1485 if (lgl->fltstr->current == MAXFLTSTR) lgl->fltstr->current = 0;
1486 sprintf (lgl->fltstr->str[lgl->fltstr->current], "%.6fd%+03.0f", d, e);
1487 return lgl->fltstr->str[lgl->fltstr->current];
1490 static Flt lgladdflt (Flt a, Flt b) {
1495 if (a == FLTMAX) return FLTMAX;
1496 if (b == FLTMAX) return FLTMAX;
1497 if (a == FLTMIN) return b;
1498 if (b == FLTMIN) return a;
1501 if (e < f) g = e, e = f, f = g, o = a, a = b, b = o;
1505 return lglflt (e, m);
1508 static Flt lglmulflt (Flt a, Flt b) {
1513 if (a == FLTMAX) return FLTMAX;
1514 if (b == FLTMAX) return FLTMAX;
1515 if (a == FLTMIN) return FLTMIN;
1516 if (b == FLTMIN) return FLTMIN;
1517 ea = lglexp (a); eb = lglexp (b);
1518 if (ea > 0 && eb > 0 && (INT_MAX - ea < eb)) return FLTMAX;
1520 if (e > EXPMAX - EXPZRO - 32) return FLTMAX;
1522 ma = lglmnt (a); mb = lglmnt (b);
1525 assert (3ull << 62);
1527 return lglflt (e, m);
1531 static Flt lglshflt (Flt a, int s) {
1534 if (a == FLTMAX) return FLTMAX;
1535 if (a == FLTMIN) return FLTMIN;
1538 if (e < INT_MIN + s) return FLTMIN;
1541 return lglflt (e, m);
1545 /*------------------------------------------------------------------------*/
1548 static const char * lglscr2str (LGL * lgl, Scr scr) {
1549 if (lgl->opts->score.val == LGL_SCORE_EVSIDS ||
1550 lgl->opts->score.val == LGL_SCORE_AVG) return lglflt2str (lgl, scr);
1551 else return lgll2str (lgl, scr);
1554 static Scr lgladdscr (Scr a, Scr b) { return lgladdflt (a, b); }
1555 static Scr lglmulscr (Scr a, Scr b) { return lglmulflt (a, b); }
1557 #else /* !NDBLSCR */
1559 static const char * lgldbl2str (LGL * lgl, double d) {
1560 assert (lgl->fltstr);
1561 lgl->fltstr->current++;
1562 if (lgl->fltstr->current == MAXFLTSTR) lgl->fltstr->current = 0;
1563 sprintf (lgl->fltstr->str[lgl->fltstr->current], "%g", d);
1564 return lgl->fltstr->str[lgl->fltstr->current];
1567 static const char * lglscr2str (LGL * lgl, Scr scr) {
1568 return lgldbl2str (lgl, scr);
1571 static Scr lgladdscr (Scr a, Scr b) { return a + b; }
1572 static Scr lglmulscr (Scr a, Scr b) { return a * b; }
1575 /*------------------------------------------------------------------------*/
1577 static void lglwrn (LGL * lgl, const char * msg, ...) {
1579 fprintf (lgl->out, "*** warning in '%s': ", __FILE__);
1581 vfprintf (lgl->out, msg, ap);
1583 fputc ('\n', lgl->out);
1587 static void lgldie (LGL * lgl, const char * msg, ...) {
1589 fprintf (lgl->out, "*** internal error in '%s': ", __FILE__);
1591 vfprintf (lgl->out, msg, ap);
1593 fputc ('\n', lgl->out);
1598 static void lglabort (LGL * lgl) {
1600 if (lgl->opts && lgl->opts->sleeponabort.val) {
1602 "liblgl.a: Process %d will sleep for %d seconds "
1603 " before continuing with 'lglabort' procedure.\n",
1604 getpid (), lgl->opts->sleeponabort.val);
1605 sleep (lgl->opts->sleeponabort.val);
1607 if (lgl->cbs && lgl->cbs->onabort)
1608 lgl->cbs->onabort (lgl->cbs->abortstate);
1609 if (lgl->opts && lgl->opts->exitonabort.val) exit (1);
1613 static const char * lglprefix (LGL * lgl) {
1614 return lgl && lgl->prefix ? lgl->prefix : "c (LGL HAS NO PREFIX YET) ";
1617 static int lglmsgstart (LGL * lgl, int level) {
1619 if (lgl->opts->log.val <= 0)
1621 if (lgl->opts->verbose.val < level) return 0;
1622 if (lgl->cbs && lgl->cbs->msglock.lock)
1623 lgl->cbs->msglock.lock (lgl->cbs->msglock.state);
1624 fputs (lglprefix (lgl), lgl->out);
1625 if (lgl->tid >= 0) fprintf (lgl->out, "%d ", lgl->tid);
1629 static void lglmsgend (LGL * lgl) {
1630 fputc ('\n', lgl->out);
1632 if (lgl->cbs && lgl->cbs->msglock.unlock)
1633 lgl->cbs->msglock.unlock (lgl->cbs->msglock.state);
1636 static void lglprt (LGL * lgl, int level, const char * msg, ...) {
1639 if (lgl->opts->log.val <= 0)
1641 if (lgl->opts->verbose.val < level) return;
1642 lglmsgstart (lgl, level);
1644 vfprintf (lgl->out, msg, ap);
1650 static void lglogstart (LGL * lgl, int level, const char * msg, ...) {
1652 assert (lgl->opts->log.val >= level);
1653 if (lgl->cbs && lgl->cbs->msglock.lock)
1654 lgl->cbs->msglock.lock (lgl->cbs->msglock.state);
1655 fputs (lglprefix (lgl), lgl->out);
1656 if (lgl->tid >= 0) fprintf (lgl->out, "%d ", lgl->tid);
1657 fprintf (lgl->out, "LOG%d %d ", level, lgl->level);
1659 vfprintf (lgl->out, msg, ap);
1663 #define lglogend lglmsgend
1666 /*------------------------------------------------------------------------*/
1668 void lglsetid (LGL * lgl, int tid, int tids) {
1669 REQINITNOTFORKED ();
1670 ABORTIF (tid < 0, "negative id");
1671 ABORTIF (tid >= tids, "id exceed number of ids");
1676 /*------------------------------------------------------------------------*/
1678 static void lglinc (LGL * lgl, size_t bytes) {
1679 lgl->stats->bytes.current += bytes;
1680 if (lgl->stats->bytes.max < lgl->stats->bytes.current) {
1681 lgl->stats->bytes.max = lgl->stats->bytes.current;
1682 LOG (5, "maximum allocated %ld bytes", lgl->stats->bytes.max);
1686 static void lgldec (LGL * lgl, size_t bytes) {
1687 assert (lgl->stats->bytes.current >= bytes);
1688 lgl->stats->bytes.current -= bytes;
1691 static void * lglnew (LGL * lgl, size_t bytes) {
1693 if (!bytes) return 0;
1694 if (lgl->mem->alloc) res = lgl->mem->alloc (lgl->mem->state, bytes);
1695 else res = malloc (bytes);
1696 if (!res) lgldie (lgl, "out of memory allocating %ld bytes", bytes);
1698 LOG (5, "allocating %p with %ld bytes", res, bytes);
1699 lglinc (lgl, bytes);
1700 if (res) memset (res, 0, bytes);
1704 static void lgldel (LGL * lgl, void * ptr, size_t bytes) {
1705 if (!ptr) { assert (!bytes); return; }
1706 lgldec (lgl, bytes);
1707 LOG (5, "freeing %p with %ld bytes", ptr, bytes);
1708 if (lgl->mem->dealloc) lgl->mem->dealloc (lgl->mem->state, ptr, bytes);
1712 static void * lglrsz (LGL * lgl, void * ptr, size_t old, size_t new) {
1714 assert (!ptr == !old);
1715 if (!ptr) return lglnew (lgl, new);
1716 if (!new) { lgldel (lgl, ptr, old); return 0; }
1717 if (old == new) return ptr;
1719 if (lgl->mem->realloc)
1720 res = lgl->mem->realloc (lgl->mem->state, ptr, old, new);
1721 else res = realloc (ptr, new);
1723 lgldie (lgl, "out of memory reallocating %ld to %ld bytes", old, new);
1725 LOG (5, "reallocating %p to %p from %ld to %ld bytes", ptr, res, old, new);
1727 if (new > old) memset (res + old, 0, new - old);
1731 /*------------------------------------------------------------------------*/
1733 static char * lglstrdup (LGL * lgl, const char * str) {
1735 NEW (res, strlen (str) + 1);
1736 return strcpy (res, str);
1739 static void lgldelstr (LGL * lgl, char * str) {
1740 DEL (str, strlen (str) + 1);
1743 /*------------------------------------------------------------------------*/
1745 static void lglinitcbs (LGL * lgl) {
1746 if (!lgl->cbs) NEW (lgl->cbs, 1);
1749 void lglonabort (LGL * lgl, void * abortstate, void (*onabort)(void*)) {
1750 REQINITNOTFORKED ();
1752 lgl->cbs->abortstate = abortstate;
1753 lgl->cbs->onabort = onabort;
1756 void lglseterm (LGL * lgl, int (*fun)(void*), void * state) {
1757 REQINITNOTFORKED ();
1759 lgl->cbs->term.fun = fun;
1760 lgl->cbs->term.state = state;
1763 void lglsetproduceunit (LGL * lgl, void (*fun) (void*, int), void * state) {
1764 REQINITNOTFORKED ();
1766 lgl->cbs->units.produce.fun = fun;
1767 lgl->cbs->units.produce.state = state;
1770 void lglsetconsumeunits (LGL * lgl,
1771 void (*fun) (void*, int **, int **),
1773 REQINITNOTFORKED ();
1775 lgl->cbs->units.consume.fun = fun;
1776 lgl->cbs->units.consume.state = state;
1779 void lglsetconsumedunits (LGL * lgl,
1780 void (*fun) (void*, int), void * state) {
1781 REQINITNOTFORKED ();
1783 lgl->cbs->units.consumed.fun = fun;
1784 lgl->cbs->units.consumed.state = state;
1787 void lglsetproducecls (LGL * lgl,
1788 void (*fun) (void*, int *, int), void * state) {
1789 REQINITNOTFORKED ();
1791 lgl->cbs->cls.produce.fun = fun;
1792 lgl->cbs->cls.produce.state = state;
1795 void lglsetconsumecls (LGL * lgl,
1796 void (*fun) (void*, int **, int *),
1798 REQINITNOTFORKED ();
1800 lgl->cbs->cls.consume.fun = fun;
1801 lgl->cbs->cls.consume.state = state;
1804 void lglsetconsumedcls (LGL * lgl,
1805 void (*fun) (void*, int), void * state) {
1806 REQINITNOTFORKED ();
1808 lgl->cbs->cls.consumed.fun = fun;
1809 lgl->cbs->cls.consumed.state = state;
1812 void lglsetlockeq (LGL * lgl, int * (*fun)(void*), void * state) {
1813 REQINITNOTFORKED ();
1815 lgl->cbs->eqs.lock.fun = fun;
1816 lgl->cbs->eqs.lock.state = state;
1819 void lglsetunlockeq (LGL * lgl, void (*fun)(void*,int,int), void * state) {
1820 REQINITNOTFORKED ();
1822 lgl->cbs->eqs.unlock.fun = fun;
1823 lgl->cbs->eqs.unlock.state = state;
1826 void lglsetmsglock (LGL * lgl,
1827 void (*lock)(void*), void (*unlock)(void*),
1829 REQINITNOTFORKED ();
1831 lgl->cbs->msglock.lock = lock;
1832 lgl->cbs->msglock.unlock = unlock;
1833 lgl->cbs->msglock.state = state;
1836 void lglsetime (LGL * lgl, double (*time)(void)) {
1837 REQINITNOTFORKED ();
1839 lgl->cbs->getime = time;
1842 /*------------------------------------------------------------------------*/
1844 static int lglfullstk (Stk * s) { return s->top == s->end; }
1845 static int lglmtstk (Stk * s) { return s->top == s->start; }
1846 static size_t lglcntstk (Stk * s) { return s->top - s->start; }
1847 static size_t lglszstk (Stk * s) { return s->end - s->start; }
1849 static int lglpeek (Stk * s, int pos) {
1850 assert (0 <= pos && pos < lglszstk (s));
1851 return s->start[pos];
1854 static void lglpoke (Stk * s, int pos, int val) {
1855 assert (0 <= pos && pos <= lglszstk (s));
1856 s->start[pos] = val;
1859 static void lglenlstk (LGL * lgl, Stk * s) {
1860 size_t old_size = lglszstk (s);
1861 size_t new_size = old_size ? 2 * old_size : 1;
1862 size_t count = lglcntstk (s);
1863 RSZ (s->start, old_size, new_size);
1864 s->top = s->start + count;
1865 s->end = s->start + new_size;
1868 static void lglrelstk (LGL * lgl, Stk * s) {
1869 DEL (s->start, lglszstk (s));
1873 static void lglshrstk (LGL * lgl, Stk * s, int new_size) {
1874 size_t old_size, count = lglcntstk (s);
1875 assert (new_size >= 0);
1876 assert (count <= new_size);
1878 old_size = lglszstk (s);
1879 RSZ (s->start, old_size, new_size);
1880 s->top = s->start + count;
1881 s->end = s->start + new_size;
1882 } else lglrelstk (lgl, s);
1885 static void lglfitstk (LGL * lgl, Stk * s) {
1886 lglshrstk (lgl, s, lglcntstk (s));
1889 static void lglpushstk (LGL * lgl, Stk * s, int elem) {
1890 if (lglfullstk (s)) lglenlstk (lgl, s);
1894 static void lglrmstk (Stk * s, int elem) {
1896 for (p = s->start; p < s->top; p++)
1897 if (*p == elem) break;
1898 assert (p < s->top);
1905 static int lglpopstk (Stk * s) { assert (!lglmtstk (s)); return *--s->top; }
1907 static int lgltopstk (Stk * s) { assert (!lglmtstk (s)); return s->top[-1]; }
1909 static void lglrststk (Stk * s, int newsz) {
1910 assert (0 <= newsz && newsz <= lglcntstk (s));
1911 s->top = s->start + newsz;
1914 static void lglclnstk (Stk * s) { lglrststk (s, 0); }
1916 /*------------------------------------------------------------------------*/
1918 static void lgltrapi (LGL * lgl, const char * msg, ...) {
1920 assert (lgl->apitrace);
1922 vfprintf (lgl->apitrace, msg, ap);
1924 fputc ('\n', lgl->apitrace);
1927 static void lglopenapitrace (LGL * lgl, const char * name) {
1931 len = strlen (name);
1932 if (len >= 3 && !strcmp (name + len - 3, ".gz")) {
1935 sprintf (cmd, "gzip -c > %s", name);
1936 file = popen (cmd, "w");
1938 if (file) lgl->closeapitrace = 2;
1940 file = fopen (name, "w");
1941 if (file) lgl->closeapitrace = 1;
1943 if (file) lgl->apitrace = file;
1944 else lglwrn (lgl, "can not write API trace to '%s'", name);
1948 void lglwtrapi (LGL * lgl, FILE * apitrace) {
1950 ABORTIF (lgl->apitrace, "can only write one API trace");
1951 lgl->apitrace = apitrace;
1955 /*------------------------------------------------------------------------*/
1956 #if !defined(NLGLPICOSAT) && !defined(NDEBUG)
1958 static void lglpicosatinit (LGL * lgl) {
1959 if (lgl->picosat.solver) return;
1960 lgl->picosat.solver = picosat_init ();
1961 picosat_set_prefix (lgl->picosat.solver, "c PST ");
1962 lgl->picosat.chk = 1;
1963 picosat_add (lgl->picosat.solver, 1);
1964 picosat_add (lgl->picosat.solver, 0);
1965 LOG (1, "PicoSAT initialized");
1969 /*------------------------------------------------------------------------*/
1971 static unsigned lglrand (LGL * lgl) {
1973 lgl->rng.z = 36969 * (lgl->rng.z & 65535) + (lgl->rng.z >> 16);
1974 lgl->rng.w = 18000 * (lgl->rng.w & 65535) + (lgl->rng.w >> 16);
1975 res = (lgl->rng.z << 16) + lgl->rng.w;
1976 LOG (5, "rng %u", res);
1980 /*------------------------------------------------------------------------*/
1982 static int lglmtftk (Ftk * ftk) { return ftk->top == ftk->start; }
1984 static int lglfullftk (Ftk * ftk) { return ftk->top == ftk->end; }
1986 static int lglsizeftk (Ftk * ftk) { return ftk->end - ftk->start; }
1988 static int lglcntftk (Ftk * ftk) { return ftk->top - ftk->start; }
1990 static void lglrelftk (LGL * lgl, Ftk * ftk) {
1991 DEL (ftk->start, lglsizeftk (ftk));
1992 memset (ftk, 0, sizeof *ftk);
1995 static void lglenlftk (LGL * lgl, Ftk * ftk) {
1996 int oldsize = lglsizeftk (ftk);
1997 int newsize = oldsize ? 2*oldsize : 1;
1998 int count = lglcntftk (ftk);
1999 RSZ (ftk->start, oldsize, newsize);
2000 ftk->top = ftk->start + count;
2001 ftk->end = ftk->start + newsize;
2004 static void lglpushftk (LGL * lgl, Ftk * ftk, Flt f) {
2005 if (lglfullftk (ftk)) lglenlftk (lgl, ftk);
2009 static Flt lgltopftk (Ftk * ftk) {
2010 assert (!lglmtftk (ftk));
2011 return ftk->top[-1];
2014 static Flt lglpopftk (Ftk * ftk) {
2015 assert (!lglmtftk (ftk));
2019 /*------------------------------------------------------------------------*/
2021 static int lglfullctk (Ctk * ctk) { return ctk->top == ctk->end; }
2023 static int lglsizectk (Ctk * ctk) { return ctk->end - ctk->start; }
2025 static int lglcntctk (Ctk * ctk) { return ctk->top - ctk->start; }
2027 static void lglrelctk (LGL * lgl, Ctk * ctk) {
2028 DEL (ctk->start, lglsizectk (ctk));
2029 memset (ctk, 0, sizeof *ctk);
2032 static void lglenlctk (LGL * lgl, Ctk * ctk) {
2033 int oldsize = lglsizectk (ctk);
2034 int newsize = oldsize ? 2*oldsize : 1;
2035 int count = lglcntctk (ctk);
2036 RSZ (ctk->start, oldsize, newsize);
2037 ctk->top = ctk->start + count;
2038 ctk->end = ctk->start + newsize;
2041 static void lglpushcontrol (LGL * lgl, int decision) {
2042 Ctk * ctk = &lgl->control;
2044 if (lglfullctk (ctk)) lglenlctk (lgl, ctk);
2046 ctr->decision = decision;
2050 static void lglpopcontrol (LGL * lgl) {
2051 assert (lgl->control.top > lgl->control.start);
2055 static void lglrstcontrol (LGL * lgl, int count) {
2056 while (lglcntctk (&lgl->control) > count)
2057 lglpopcontrol (lgl);
2060 static int lglevelused (LGL * lgl, int level) {
2061 Ctk * ctk = &lgl->control;
2063 assert (0 < level && level < lglsizectk (ctk));
2064 ctr = ctk->start + level;
2068 static void lgluselevel (LGL * lgl, int level) {
2069 Ctk * ctk = &lgl->control;
2071 assert (0 < level && level < lglsizectk (ctk));
2072 ctr = ctk->start + level;
2076 static void lglunuselevel (LGL * lgl, int level) {
2077 Ctk * ctk = &lgl->control;
2080 assert (level < lglcntctk (ctk));
2082 ctr = ctk->start + level;
2087 /*------------------------------------------------------------------------*/
2089 static void lglgetenv (LGL * lgl, Opt * opt, const char * lname) {
2090 const char * q, * valstr;
2091 char uname[40], * p;
2093 assert (strlen (lname) + 3 + 1 < sizeof (uname));
2094 uname[0] = 'L'; uname[1] = 'G'; uname[2] = 'L';
2096 for (q = lname; *q; q++) {
2097 assert (p < uname + sizeof uname);
2098 *p++ = toupper (*q);
2100 assert (p < uname + sizeof uname);
2102 valstr = getenv (uname);
2103 if (!valstr) return;
2105 newval = atoi (valstr);
2106 if (newval < opt->min) newval = opt->min;
2107 if (newval > opt->max) newval = opt->max;
2108 if (newval == oldval) return;
2110 TRAPI ("option %s %d", lname, newval);
2112 if (lgl->clone) lglsetopt (lgl->clone, lname, newval);
2115 static void lglchkenv (LGL * lgl) {
2116 extern char ** environ;
2117 char * src, *eos, * dst;
2118 char ** p, * s, * d;
2120 for (p = environ; (src = *p); p++) {
2121 if (src[0] != 'L' || src[1] != 'G' || src[2] != 'L') continue;
2122 for (eos = src; *eos && *eos != '='; eos++)
2124 len = eos - (src + 3);
2127 for (s = src + 3; s < eos; s++) *d++ = tolower (*s);
2129 if (!lglhasopt (lgl, dst) && strcmp (dst, "apitrace"))
2130 lglwrn (lgl, "invalid 'LGL...' environment '%s'", src);
2135 #define SETPLAIN(NAME) \
2137 if (val) lgl->opts->NAME.val = 0; \
2138 else lgl->opts->NAME.val = lgl->opts->NAME.dflt; \
2141 #define SETDRUP SETPLAIN
2143 static void lglsetdrup (LGL * lgl, int val) {
2146 SETDRUP (decompose);
2154 lglprt (lgl, 1, "[drup] drup solving switched %s", val ? "on" : "off");
2157 #define SETDRUPLIG SETPLAIN
2159 static void lglsetdruplig (LGL * lgl, int val) {
2162 SETDRUPLIG (decompose);
2165 SETDRUPLIG (cgrclsr);
2169 SETDRUPLIG (smallve);
2171 "[druplig] druplig checking switched %s",
2172 val ? "on" : "off");
2175 static void lglsetplain (LGL * lgl, int val) {
2183 SETPLAIN (decompose);
2192 SETPLAIN (transred);
2194 lglprt (lgl, 1, "[plain] plain solving switched %s", val ? "on" : "off");
2197 #define SETWAIT(NAME) \
2199 if (val) lgl->opts->NAME.val = lgl->opts->NAME.dflt; \
2200 else lgl->opts->NAME.val = 0; \
2203 static void lglsetwait (LGL * lgl, int val) {
2206 SETWAIT (blockwait);
2208 SETWAIT (cgrclsrwait);
2209 SETWAIT (cliffwait);
2210 SETWAIT (elmblkwait);
2211 SETWAIT (gausswait);
2213 SETWAIT (smallvewait);
2214 SETWAIT (ternreswait);
2215 SETWAIT (transredwait);
2216 SETWAIT (unhidewait);
2217 lglprt (lgl, 1, "[wait] waiting %s", val ? "enabled" : "disabled");
2220 static LGL * lglnewlgl (void * mem,
2223 lgldealloc dealloc) {
2224 LGL * lgl = alloc ? alloc (mem, sizeof *lgl) : malloc (sizeof *lgl);
2225 ABORTIF (!lgl, "out of memory allocating main solver object");
2228 lgl->mem = alloc ? alloc (mem, sizeof *lgl->mem) : malloc (sizeof *lgl->mem);
2229 ABORTIF (!lgl->mem, "out of memory allocating memory manager object");
2231 lgl->mem->state = mem;
2232 lgl->mem->alloc = alloc;
2233 lgl->mem->realloc = realloc;
2234 lgl->mem->dealloc = dealloc;
2236 lgl->opts = alloc ? alloc (mem, sizeof (Opts)) : malloc (sizeof (Opts));
2237 ABORTIF (!lgl->opts, "out of memory allocating option manager object");
2240 lgl->stats = alloc ? alloc (mem, sizeof (Stats)) : malloc (sizeof (Stats));
2241 ABORTIF (!lgl->stats, "out of memory allocating statistic counters");
2242 CLRPTR (lgl->stats);
2244 lglinc (lgl, sizeof *lgl);
2245 lglinc (lgl, sizeof *lgl->mem);
2246 lglinc (lgl, sizeof *lgl->opts);
2247 lglinc (lgl, sizeof *lgl->stats);
2252 static void lglinitscores (LGL * lgl) {
2253 Scr oldscincf, oldmaxscore = lgl->maxscore;
2254 if (lgl->opts->score.val != LGL_SCORE_EVSIDS) {
2255 lgl->maxscore = (1ll << 60);
2256 if (oldmaxscore != lgl->maxscore)
2258 "[init-scores] fixed maxium score %s",
2259 lglscr2str (lgl, lgl->maxscore));
2261 oldscincf = lgl->scincf;
2263 lgl->scincf = lglrat (1000 + lgl->opts->scincinc.val, 1000);
2264 lgl->maxscore = lglflt (lgl->opts->maxscorexp.val, 1);
2266 lgl->scincf = (1000.0 + lgl->opts->scincinc.val) / 1000.0;
2267 lgl->maxscore = scalbln (1.0, lgl->opts->maxscorexp.val);
2269 if (oldscincf != lgl->scincf)
2271 "[init-scores] score increment factor %s (--scincinc=%d)",
2272 lglscr2str (lgl, lgl->scincf), lgl->opts->scincinc.val);
2274 if (oldmaxscore != lgl->maxscore)
2276 "[init-scores] maxium score limit %s (--maxscorexp=%d)",
2277 lglscr2str (lgl, lgl->maxscore), lgl->opts->maxscorexp.val);
2281 LGL * lglminit (void * mem,
2284 lgldealloc dealloc) {
2285 const int K = 1000, M = K*K, I = INT_MAX;
2286 const int MG = MAXGLUE, MG0 = MG*10;
2287 const char * apitracename;
2292 ABORTIF (!alloc+!realloc+!dealloc != 0 && !alloc+!realloc+!dealloc != 3,
2293 "inconsistent set of external memory handlers");
2295 assert (sizeof (long) == sizeof (void*));
2297 assert (REMOVED > ((MAXVAR << RMSHFT) | MASKCS | REDCS));
2298 assert (REMOVED > MAXREDLIDX);
2299 assert (REMOVED > MAXIRRLIDX);
2301 assert (MAXREDLIDX == MAXIRRLIDX);
2302 assert (GLUESHFT == RMSHFT);
2304 assert (INT_MAX > ((MAXREDLIDX << GLUESHFT) | GLUEMASK));
2305 assert (INT_MAX > ((MAXIRRLIDX << RMSHFT) | MASKCS | REDCS));
2307 assert (MAXGLUE < POW2GLUE);
2309 lgl = lglnewlgl (mem, alloc, realloc, dealloc);
2312 lglpushcontrol (lgl, 0);
2313 assert (lglcntctk (&lgl->control) == lgl->level + 1);
2316 lgl->prefix = lglstrdup (lgl, "c ");
2318 apitracename = getenv ("LGLAPITRACE");
2319 if (apitracename) lglopenapitrace (lgl, apitracename);
2321 OPT(0,abstime,0,0,1,"print absolute time when reporting");
2322 OPT(0,actavgmax,3*MG0/4,0,MG0,"glue average max limit for dyn acts");
2323 OPT(0,actdblarithlim,3,0,MG,"glue lim for dbl arith increase");
2324 OPT(0,actgeomlim,2,0,MG,"glue limit for geometric increase");
2325 OPT(0,actgsdul,7,0,MG0,"glue useless standard deviation limit");
2326 OPT(0,acts,2,0,2,"activity based reduction: 0=no,1=enable,2=dyn");
2327 OPT(0,actstdmax,3*MG0/4,0,MG0,"glue std dev max limit for dyn acts");
2328 OPT(0,actstdmin,10,0,MG0,"glue std dev min limit for dyn acts");
2329 OPT(0,actvlim,200*K,0,I,"activity based reduction variable limit");
2330 OPT(0,agile,1,0,2,"agility based restart skipping, 1=std, 2=sinus");
2331 OPT(0,agilelim,30,0,100,"agility limit for restarts");
2332 OPT(0,agilesinint,100*K,1,I,"agility limit sinus interval");
2333 OPT(0,bate,1,0,1,"basic ATE removal during probing");
2334 OPT(0,batewait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2335 OPT(0,bca,1,0,2,"enable blocked clause addition (1=week,2=strong)");
2336 OPT(0,bcamaxeff,10*M,0,I,"BCA maximum number of steps");
2337 OPT(0,bcaminuse,100,0,I,"min number of literals required to be usable");
2338 OPT(0,bcawait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2339 OPT(0,bva,0,0,1,"enable bounded variable addition (BVA)");
2340 OPT(0,bias,2,-1,2,"decision order initial bias (0=no,2=cw)");
2341 OPT(0,binlocsdel,10,0,1000,"delay local seach after learning binary clause");
2342 OPT(0,binsimpdel,2,0,1000,"delay simp after learning binary clause");
2343 OPT(0,bkwdscale,2,1,1000,"backward steps scaled vs elimination steps");
2344 OPT(0,blkboost,10,1,10000,"initial BCE boost");
2345 OPT(0,blkboostvlim,1000000,0,I,"init BCE boost variable limit");
2346 OPT(0,blkclslim,1*M,3,I,"max blocked clause size");
2347 OPT(0,blklarge,1,0,1,"BCE of large clauses");
2348 OPT(0,blkmaxeff,800*M,-1,I,"max effort in BCE (-1=unlimited)");
2349 OPT(0,blkmineff,50*M,0,I,"min effort in BCE");
2350 OPT(0,blkocclim1,100*K,1,I,"one-sided max occ of BCE");
2351 OPT(0,blkocclim,1*M,3,I,"max occ in BCE");
2352 OPT(0,blkocclim2,10*K,2,I,"two-sided max occ of BCE");
2353 OPT(0,blkreleff,100,0,K,"rel effort in BCE");
2354 OPT(0,blkrtc,0,0,1,"run BCE until completion");
2355 OPT(0,blksched2b2,0,0,1,"BCE schedule 2x2 first");
2356 OPT(0,blkschedmin,0,0,1,"BCE schedule based on minimum of occurrences");
2357 OPT(0,blkschedprod,0,0,1,"BCE schedule based on product too");
2358 OPT(0,blkschedpure,1,0,1,"BCE schedule pure literals first");
2359 OPT(0,blkschedsum,1,0,1,"BCE schedule based on sum of occurrences too");
2360 OPT(0,blksmall,1,0,1,"BCE of small clauses");
2361 OPT(0,blksuccesslim,10*K,0,I,"BCE success limit");
2362 OPT(0,blksuccessrat,1000,1,I,"BCE success ratio");
2363 OPT(0,block,1,0,1,"blocked clause elimination (BCE)");
2364 OPT(0,blockwait,1,0,1,"wait for BVE");
2365 OPT(0,boost,1,0,1,"enable boosting of preprocessors");
2366 OPT(0,bumpbcplits,0,0,1,"bump unseen but propagated literals");
2367 OPT(0,bumpclslits,0,0,1,"bump literals in minimized clause");
2368 OPT(0,bumpseenaftermin,0,0,1,"bump seen after minimization");
2369 OPT(0,bumpseenbeforemin,1,0,1,"bump seen before minimization");
2370 OPT(0,bumpseenlits,1,0,1,"bump seen literals");
2371 OPT(0,bumpseenminsize,3,0,I,"minimum 1st UIP clause for bumping seen");
2372 OPT(0,card,1,0,1,"cardinality constraint reasoning");
2373 OPT(0,cardcut,2,0,2,"1=gomoroy-cuts,2=strengthen");
2374 OPT(0,cardexpam1,3,2,I,"min length of exported at-most-one constraint");
2375 OPT(0,cardglue,0,-1,MAXGLUE,"use lrg red cls too (-1=irr,0=moved,...)");
2376 OPT(0,cardignused,0,0,1,"ignored already used literals in extraction");
2377 OPT(0,cardmaxeff,300*M,-1,I,"max effort for cardmineff reasoning");
2378 OPT(0,cardmaxlen,1000,0,I,"maximal length of cardinality constraints");
2379 OPT(0,cardmineff,2*M,0,I,"min effort for cardmineff reasoning");
2380 OPT(0,cardminlen,3,0,I,"minimal length of (initial) card constraints");
2381 OPT(0,cardocclim1,300,0,I,"one-sided cardinality constraints occ limit");
2382 OPT(0,cardocclim2,15,0,I,"two-sided cardinality constraints occ limit");
2383 OPT(0,cardreleff,5,0,10*K,"rel effort for cardinality reasoning");
2384 OPT(0,cardreschedint,10,1,I,"reschedule variable for card reasoning");
2385 OPT(0,carduse,2,0,3,"use clauses (1=oneside,2=bothsidetoo,3=anyside)");
2386 OPT(0,cardwait,0,0,2,"wait for BCE (1) and/or BVE (2)");
2387 OPT(0,cce2wait,1,0,I,"wait for ATE to finish before doing ABCE");
2388 OPT(0,cce,3,0,3,"covered clause elimination (1=ate,2=abce,3=acce)");
2389 OPT(0,cceboost,10,1,1000,"initial CCE boost");
2390 OPT(0,cceboostvlim,1000000,0,I,"initial CCE boost variable limit");
2391 OPT(0,cce3wait,2,0,I,"wait for ABCE to finish before doing ACCE");
2392 OPT(0,ccemaxeff,I,-1,I,"max effort in covered clause elimination");
2393 OPT(0,ccemineff,30*M,0,I,"min effort in covered clause elimination");
2394 OPT(0,cceonlyifstuck,0,0,1,"ABCE+ACCE only if elm+blk stuck");
2395 OPT(0,ccereleff,20,0,K,"rel effort in covered clause elimination");
2396 OPT(0,ccertc,0,0,1,"run CCE until completition");
2397 OPT(0,ccesuccesslim,10*K,0,I,"CCE success limit");
2398 OPT(0,ccesuccessrat,1000,1,I,"CCE success ratio");
2399 OPT(0,ccewait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2400 OPT(0,cgrclsr,1,0,1,"gate extraction and congruence closure");
2401 OPT(0,cgrclsrwait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2402 OPT(0,cgreleff,1,0,10*K,"rel effort in congruence closure");
2403 OPT(0,cgrextand,1,0,1,"extract and gates");
2404 OPT(0,cgrexteq,1,0,1,"extract equivalences");
2405 OPT(0,cgrextite,1,0,1,"extract ite gates");
2406 OPT(0,cgrextunits,1,0,1,"extract units");
2407 OPT(0,cgrextxor,1,0,1,"extract xor gates");
2408 OPT(0,cgrmaxeff,8*M,-1,I,"max effort in congruence closure");
2409 OPT(0,cgrmaxority,20,2,30,"maximum xor arity to be extracted");
2410 OPT(0,cgrmineff,200*K,0,I,"min effort in congruence closure");
2411 OPT(0,cintinc,20*K,10,M,"inprocessing conflict interval increment");
2412 OPT(0,cintincdiv,1,0,3,"cintinc reduce policy: 0=no,1=div1,2=div2,3=heur");
2413 OPT(0,cintmaxhard,10*M,-1,I,"hard max conflict interval limit");
2414 OPT(0,cintmaxsoft,1*M,-1,I,"soft max conflict interval limit");
2415 OPT(0,cliff,1,0,1,"cliffing");
2416 OPT(0,cliffmaxeff,100*M,-1,I,"max effort in cliffing");
2417 OPT(0,cliffmineff,10*M,0,I,"min effort in cliffing");
2418 OPT(0,cliffreleff,8,0,10*K,"rel effort in cliffing");
2419 OPT(0,cliffwait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2420 OPT(0,clim,-1,-1,I,"conflict limit");
2421 OPT(0,compact,0,0,2,"compactify after 'lglsat/lglsimp' (1=UNS,2=SAT)");
2422 OPT(0,deco,1,0,2,"learn decision-only clauses too (2=all-decisions)");
2423 OPT(0,decolim,30,0,I,"decision-only clauses glue limit");
2424 OPT(0,decompose,1,0,1,"enable decompose");
2425 OPT(0,defragfree,50,10,K,"defragmentation free watches limit");
2426 OPT(0,defragint,10*M,100,I,"defragmentation pushed watches interval");
2427 OPT(0,delmax,10,0,10,"maximum delay");
2428 OPT(0,dlim,-1,-1,I,"decision limit");
2429 OPT(0,drup,0,0,1,"print DRUP proof");
2431 OPT(0,druplig,0,0,1,"check proof through Druplig internally");
2433 OPT(0,druplig,1,1,1,"check proof through Druplig internally");
2435 OPT(0,elim,1,0,1,"bounded variable eliminiation (BVE)");
2436 OPT(0,elmaxeff,800*M,-1,I,"max effort in BVE (-1=unlimited)");
2437 OPT(0,elmblk,1,0,1,"enable BCE during BVE");
2438 OPT(0,elmblkwait,1,0,1,"wait for BVE to be completed once");
2439 OPT(0,elmboost,40,1,1000,"initial elimination boost");
2440 OPT(0,elmclslim,1*M,3,I,"max antecendent size in elimination");
2441 OPT(0,elmfull,0,0,1,"no elimination limits");
2442 OPT(0,elmineff,20*M,0,I,"min effort in BVE");
2443 OPT(0,elmlitslim,200,0,I,"one side literals limit for elimination");
2444 OPT(0,elmocclim1,1000,1,I,"one-sided max occ of BVE");
2445 OPT(0,elmocclim,1*M,3,I,"max occurrences in BVE");
2446 OPT(0,elmocclim2,100,2,I,"two-sided max occ of BVE");
2447 OPT(0,elmreleff,200,0,10*K,"rel effort in BVE");
2448 OPT(0,elmroundlim,3,1,I,"variable elimination rounds limit");
2449 OPT(0,elmrtc,0,0,1,"run BVE until completion");
2450 OPT(0,elmsched2b2,0,0,1,"BVE schedule 2x2 first");
2451 OPT(0,elmschediff,0,0,1,"BVE schedule based on diff of occurrences too");
2452 OPT(0,elmschedmin,0,0,1,"BVE schedule based on minimum of occurrences");
2453 OPT(0,elmschedprod,0,0,1,"BVE schedule based on product too");
2454 OPT(0,elmschedpure,1,0,1,"BVE schedule pure literals first");
2455 OPT(0,elmschedsum,1,0,1,"BVE schedule based on sum of occurrences too");
2456 OPT(0,elmsuccesslim,1000,0,I,"BVE success limit");
2457 OPT(0,elmsuccessrat,1000,1,I,"BVE success ratio");
2458 OPT(0,exitonabort,0,0,1,"exit instead abort after internal error");
2459 OPT(0,factmax,100000,1,I,"maximum factor");
2460 OPT(0,factor,3,0,3,"{cls,occ}lim factors (0=const1,1=ld,2=lin,3=sqr)");
2461 OPT(0,flipdur,10,1,I,"flipping duration in number of conflicts");
2462 OPT(0,flipint,10,0,I,"flipping interval in number top level decision");
2463 OPT(0,flipldmod,4,0,30,"flipping phase log2 of mod");
2464 OPT(0,fliplevels,6,0,30,"flipping decision levels");
2465 OPT(0,flipping,1,0,1,"enable point flipping");
2466 OPT(0,fliptop,1,0,1,"flipping only at the top level");
2467 OPT(0,flipvlim,100*K,0,I,"no flipping beyond this number vars");
2468 OPT(0,force,0,0,I,"reorder variables with force algorithm");
2469 OPT(0,gauss,1,0,1,"enable gaussian elimination");
2470 OPT(0,gaussexptrn,1,0,1,"export trn cls from gaussian elimination");
2471 OPT(0,gaussextrall,1,0,1,"extract all xors (with duplicates)");
2472 OPT(0,gaussmaxeff,50*M,-1,I,"max effort in gaussian elimination");
2473 OPT(0,gaussmaxor,20,2,64,"maximum xor size in gaussian elimination");
2474 OPT(0,gaussmineff,2*M,0,I,"min effort in gaussian elimination");
2475 OPT(0,gaussreleff,2,0,10*K,"rel effort in gaussian elimination");
2476 OPT(0,gausswait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2477 OPT(0,gluekeep,3,0,I,"keep clauses with this original glue");
2478 OPT(0,gluescale,4,1,4,"glue scaling: 1=linear,2=sqrt,3=ld,4=hybrid");
2479 OPT(0,import,1,0,1,"import external indices and map them");
2480 OPT(0,incredcint,1,1,I,"incremental reduce conflict interval");
2481 OPT(0,incredconfslim,0,0,100,"incremental reduce conflict limit");
2482 OPT(0,incsavevisits,0,0,1,"incremental start new visits counter");
2483 OPT(0,inprocessing,1,0,1,"enable inprocessing");
2484 OPT(0,irrlim,1,0,1,"use irredundant clauses as limit for simps");
2485 OPT(0,itlocsdel,100,0,100*K,"local search delay after iteration");
2486 OPT(0,itsimpdel,20,0,100*K,"simplification delay after iteration");
2487 OPT(0,jwhred,1,0,1,"compute JWH score based on redundant clauses too");
2488 OPT(0,keepmaxglue,1,0,1,"keep maximum glue clauses");
2489 OPT(0,lftmaxeff,20*M,-1,I,"max effort in lifting");
2490 OPT(0,lftmineff,500*K,0,I,"min effort in lifting");
2491 OPT(0,lftreleff,6,0,10*K,"rel effort in lifting");
2492 OPT(0,lftroundlim,5,0,I,"lifting round limit");
2493 OPT(0,lhbr,1,0,1, "enable lazy hyber binary reasoning");
2494 OPT(0,lift,1,0,1,"enable double lookahead lifting");
2495 OPT(0,liftlrg,3,0,I,"consider large clauses with this many unassigned");
2496 OPT(0,liftwait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2497 OPT(0,lkhd,2,-1,3, "-1=LOCS,0=LIS,1=JWH,2=TREELOOK,3=LENSUM");
2498 OPT(0,lkhdmisifelmrtc,0,0,1,"MIS if elimination ran to completion");
2499 OPT(0,locs,0,-1,I,"use local search (-1=always otherwise how often)");
2500 OPT(0,locsclim,1*M,0,(I>>8),"clause limit for local search");
2501 OPT(0,locsboost,2,0,100,"initial local search boost");
2502 OPT(0,locscint,10*K,1,I,"conflict interval for LOCS");
2503 OPT(0,locsdec,2,0,2,"bump 1=mostflipped 2=minlits");
2504 OPT(0,locset,2,0,2,"initialize local search phases (1=prev,2=cur)");
2505 OPT(0,locsexport,1,0,1,"export phases from local search");
2506 OPT(0,locsmaxeff,100000,0,I,"max effort in local search");
2507 OPT(0,locsmineff,1000,0,I,"min effort in local search");
2508 OPT(0,locsred,0,0,4,"apply local search on redundant clauses too");
2509 OPT(0,locsreleff,5,0,100,"rel effort in local search");
2510 OPT(0,locsrtc,0,0,1,"run local search until completion");
2511 OPT(0,locsvared,100,0,1000,"max variable reduction for LOCS");
2512 OPT(0,locswait,2,0,2,"wait for BCE(1) and/or BVE(2)");
2513 OPT(0,maxglue,I,0,I,"min glue which is considered as MAXGLUE");
2514 OPT(0,maxscorexp,DEFSCOREXP,7,MAXSCOREXP,"maximum score exponent");
2515 OPT(0,mega,0,0,1,"mega probing through preprocessor look-ahead");
2516 OPT(0,megaint,4,1,I,"mega probing interval");
2517 OPT(0,megawait,2,0,2,"mega probing waiting for BCE / BVE");
2518 OPT(0,memlim,-1,-1,I,"memory limit in MB (-1=no limit)");
2519 OPT(0,minimize,2,0,2,"minimize learned clauses (1=local,2=recursive)");
2520 OPT(0,minlocalgluelim,30,0,I,"glue limit for using local minimization");
2521 OPT(0,minrecgluelim,20,0,I,"glue limit for using recursive minimization");
2522 OPT(0,mocint,1000,1,I,"multiple objectives conflict limit interval");
2523 OPT(0,move,2,0,3,"move redundant cls (1=only-binary,2=ternary,3=all)");
2524 OPT(0,otfs,1,0,1,"enable on-the-fly subsumption");
2525 OPT(0,otfsbump,0,0,2,"bump literals during OTFS (1=conflict,2=drive)");
2526 OPT(0,otfsconf,0,0,1,"count on-the-fly restart as conflict");
2527 OPT(0,penmax,4,0,16,"maximum penalty");
2528 OPT(0,phase,0,-1,1,"default phase (-1=neg,0=JeroslowWang,1=pos)");
2529 OPT(0,phaseflip,0,0,1,"flip Jeroslow Wang phase");
2530 OPT(0,phasegluebit,0,0,I,"Glue-Bit phase selection on these levels");
2531 OPT(0,phaseneginit,0,0,I,"initial zero phase conflict interval");
2532 OPT(0,plain,0,0,1,"plain mode disables all preprocessing");
2533 OPT(0,plim,-1,-1,I,"propagation limit (thousands)");
2534 OPT(0,prbasic,1,0,2,"enable basic probing procedure (1=roots-only)");
2535 OPT(0,prbasicmaxeff,100*M,-1,I,"max effort in basic probing");
2536 OPT(0,prbasicmineff,M,0,I,"min effort in basic probing");
2537 OPT(0,prbasicreleff,10,0,10*K,"rel effort in basic probing");
2538 OPT(0,prbasicroundlim,9,1,I,"basic probing round limit");
2539 OPT(0,prbasicrtc,0,0,1,"run basic probing until completion");
2540 OPT(0,prbrtc,0,0,1,"run all probing until completion");
2541 OPT(0,prbsimple,2,0,3,"simple probing (1=shallow,2=deep,3=touchall)");
2542 OPT(0,prbsimpleboost,10,1,1000,"initial simple probing boost");
2543 OPT(0,prbsimpleliftdepth,2,1,4,"simple probing lifting depth");
2544 OPT(0,prbsimplemaxeff,200*M,-1,I,"max effort in simple probing");
2545 OPT(0,prbsimplemineff,2*M,0,I,"min effort in simple probing");
2546 OPT(0,prbsimplereleff,40,0,10*K,"rel effort in simple probing");
2547 OPT(0,prbsimplertc,0,0,1,"run simple probing until completion");
2548 OPT(0,probe,1,0,1,"enable probing");
2549 OPT(0,psm,3,0,3,"use PSM metric (1=afteract,2=afterglue,3=first");
2550 OPT(0,pure,1,0,1,"enable pure literal elimination during BCE");
2551 OPT(0,randec,0,0,1,"enable random decisions");
2552 OPT(0,randecflipint,0,0,I,"random decision flip phase interval");
2553 OPT(0,randecint,1000,2,I/2,"random decision interval");
2554 OPT(0,rdp,0,0,3,"random DP (2=redbin,3=redtrn");
2555 OPT(0,rdpclslim,3,0,I,"random DP resolvent size limit");
2556 OPT(0,rdplim,100,0,200,"limit #resolvents in percent original clauses");
2557 OPT(0,rdpmaxeff,10*M,-1,I,"max effort in RDP");
2558 OPT(0,rdpmineff,10*K,0,I,"min effort in RDP");
2559 OPT(0,rdpmodelm,0,0,1,"use model elimination in RDP");
2560 OPT(0,rdpreleff,2,0,10*K,"rel effort in RDP");
2561 OPT(0,rdpwait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2562 OPT(0,redfixed,0,0,1,"keep a fixed size of learned clauses");
2563 OPT(0,redinoutinc,100,1,1000,"reduce inner/outer relative increment");
2564 OPT(0,redlbound,0,0,1,"relative and absolute bounds on learned clauses");
2565 OPT(0,redlexpfac,10,0,1000,"exponential reduce limit increment factor");
2566 OPT(0,redlinc,1000,1,10*M,"reduce limit increment");
2567 OPT(0,redlinit,4*K,1,100*M,"initial reduce limit");
2568 OPT(0,redlmaxabs,1000000,10,I/2,"maximum absolute reduce limit");
2569 OPT(0,redlmaxinc,200,1,100*K,"rel max reduce limit increment");
2570 OPT(0,redlmaxrel,300,10,10000,"maximum relative reduce limit");
2571 OPT(0,redlminabs,500,10,1000000,"minimum absolute reduce limit");
2572 OPT(0,redlmininc,10,1,100*K,"rel min reduce limit increment");
2573 OPT(0,redlminrel,10,10,1000,"minimum relative reduce limit");
2574 OPT(0,redloutinc,10000,0,1000000,"outer arithmetic reduce increment");
2575 OPT(0,redoutclim,5000,0,I,"clause limit for outer reduce schedule");
2576 OPT(0,redoutvlim,1000,0,I,"variable limit for outer reduce schedule");
2577 OPT(0,reduce,2,0,4,"clause reduction (1=noouter,2=luby,3=inout,4=arith)");
2578 OPT(0,rephase,1,0,2,"enable flushing and recomputation of phases (2=full)");
2579 OPT(0,rephaseinc,10000,1,I,"rephasing increment");
2580 OPT(0,restart,2,0,3,"enable restarting (0=no,1=fixed,2=luby,3=inout)");
2581 OPT(0,restartinit,0,0,I,"initial restart interval");
2582 OPT(0,restartint,5,1,I,"restart interval");
2583 OPT(0,restartintscale,0,-1,1,"scale restart interval");
2584 OPT(0,reusetrail,1,0,1,"reuse trail");
2585 OPT(0,rmincpen,4,0,32,"logarithm of watcher removal penalty");
2586 OPT(0,rstinoutinc,110,1,1000,"restart inner/outer relative increment");
2587 OPT(0,saturating,70,0,1000,"saturating level (no restart)");
2588 OPT(0,scincinc,200,0,10*K,"score increment increment in per mille");
2589 OPT(0,score,5,0,6,"0=static,1=inc,2=vmtf,3=sum,4=avg,5=evsids,6=vsids256");
2590 OPT(0,seed,0,0,I,"random number generator seed");
2591 OPT(0,simpdelay,0,0,I,"initial simplification delay");
2592 OPT(0,simpen,0,0,24,"logarithmic initial simplification penalty");
2593 OPT(0,simpidiv,3,1,100,"simplification inter delay divisor");
2594 OPT(0,simpinterdelay,2000,0,I,"inprocessing simplification delay");
2595 OPT(0,simpiscale,100,1,10000,"relative simplification inter delay scale");
2596 OPT(0,simplify,2,0,2,"enable simplification");
2597 OPT(0,simprtc,5,1,100,"min var reduction for simplification RTC");
2598 OPT(0,simpvarchg,100,1,1000, "simp remaining vars percentage change lim");
2599 OPT(0,simpvarlim,100,0,I, "simp remaining vars min limit");
2600 OPT(0,sizemaxpen,5,0,20,"maximum logarithmic size penalty");
2601 OPT(0,sizepen,1*M,1,I,"number of clauses size penalty starting point");
2602 OPT(0,sleeponabort,0,0,I,"sleep this seconds before abort/exit");
2603 OPT(0,smallirr,90,0,100,"max percentage irr lits for BCE and VE");
2604 OPT(0,smallve,1,0,1,"enable small number variables elimination");
2605 OPT(0,smallvevars,FUNVAR,4,FUNVAR, "variables small variable elimination");
2606 OPT(0,smallvewait,0,0,1,"wait with small variable elimination");
2607 OPT(0,sortlits,0,0,1,"sort lits of cls during garbage collection");
2608 OPT(0,subl,9,0,10*K,"try to subsume this many recent learned clauses");
2609 OPT(0,synclsall,1,0,1,"always synchronize all unconsumed clauses");
2610 OPT(0,synclsglue,8,0,I,"clause synchronization glue limit");
2611 OPT(0,synclsint,100,0,1000,"clause synchronization confs interval");
2612 OPT(0,synclslen,40,0,I,"clause synchronization length limit");
2613 OPT(0,syncunint,111111,0,M,"unit synchronization steps interval");
2614 OPT(0,tabr,3,0,4,"tabula rasa (1=red,2=phases,3=cinc,4=scores");
2615 OPT(0,tabrcfactor,2,1,I,"tabula rasa clause factor");
2616 OPT(0,tabrkeep,3,1,4,"1=none,2=bin,3=bin+trn,4=bin+trn+glue0");
2617 OPT(0,tabrvfactor,4,1,I,"tabula rasa variable factor");
2618 OPT(0,termint,122222,0,M,"termination check interval");
2619 OPT(0,ternres,1,0,1,"generate ternary resolvents");
2620 OPT(0,ternresboost,5,1,100,"initial ternary reslution boost");
2621 OPT(0,ternresrtc,0,0,1,"run ternary resolvents until completion");
2622 OPT(0,ternreswait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2623 OPT(0,transred,1,0,1,"enable transitive reduction");
2624 OPT(0,transredwait,2,0,2,"wait for BCE (1) and/or BVE (2)");
2625 OPT(0,trdmaxeff,2*M,-1,I,"max effort in transitive reduction");
2626 OPT(0,trdmineff,100*K,0,I,"min effort in transitive reduction");
2627 OPT(0,trdreleff,10,0,10*K,"rel effort in transitive reduction");
2628 OPT(0,treelook,1,0,2,"enable tree-based look-ahead (2=scheduleprobing)");
2629 OPT(0,treelookboost,20,1,100000,"tree-based look-head boost factor");
2630 OPT(0,treelookfull,0,0,1,"do not limit tree-based look-head");
2631 OPT(0,treelooklrg,1,0,1,"use large clauses during tree-look");
2632 OPT(0,treelookmaxeff,50*M,-1,I,"max effort in tree-look based probing");
2633 OPT(0,treelookmineff,300*K,0,I,"min effort in tree-look based probing");
2634 OPT(0,treelookreleff,1,0,10*K,"rel effort in tree-look based probing");
2635 OPT(0,treelookrtc,0,0,1,"run tree-based look-ahead until completion");
2636 OPT(0,trep,0,0,1,"enable time based interval reporting");
2637 OPT(0,trepint,55555,1,I,"interval for time based reporting");
2638 OPT(0,trnreleff,10,0,K,"rel effort in ternary resolutions");
2639 OPT(0,trnrmaxeff,200*M,-1,I,"max effort in ternary resolutions");
2640 OPT(0,trnrmineff,4*M,0,I,"min effort in ternary resolutions");
2641 OPT(0,unhdatrn,2,0,2,"unhide redundant ternary clauses (1=move,2=force)");
2642 OPT(0,unhdextstamp,1,0,1,"used extended stamping features");
2643 OPT(0,unhdhbr,0,0,1,"enable unhiding hyper binary resolution");
2644 OPT(0,unhdlnpr,3,0,I,"unhide no progress round limit");
2645 OPT(0,unhdmaxeff,20*M,-1,I,"max effort in unhiding");
2646 OPT(0,unhdmineff,100*K,0,I,"min effort in unhiding");
2647 OPT(0,unhdreleff,2,0,10*K,"rel effort in unhiding");
2648 OPT(0,unhdroundlim,20,0,100,"unhide round limit");
2649 OPT(0,unhide,1,0,1,"enable unhiding");
2650 OPT(0,unhidewait,0,0,2,"wait for BCE (1) and/or BVE (2)");
2651 OPT(0,wait,1,0,1,"enable or disable all waiting");
2652 OPT(0,waitmax,4,-1,I,"max simps to wait (-1=nomax)");
2653 OPT(0,witness,1,0,1,"print witness");
2655 OPT('c',check,0,0,3,"check level");
2656 OPT('l',log,-1,-1,5,"log level");
2657 OPT('v',verbose,0,-1,4,"verbosity level");
2659 if (lgl->opts->plain.val) lglsetplain (lgl, 1);
2660 if (lgl->opts->drup.val) lglsetdrup (lgl, 1);
2661 if (lgl->opts->druplig.val) lglsetdruplig (lgl, 1);
2662 if (!lgl->opts->wait.val) lglsetwait (lgl, 0);
2664 if (abs (lgl->opts->bias.val) <= 1) lgl->bias = lgl->opts->bias.val;
2667 NEW (lgl->times, 1);
2668 NEW (lgl->timers, 1);
2669 NEW (lgl->limits, 1);
2670 NEW (lgl->fltstr, 1);
2671 NEW (lgl->red, MAXGLUE+1);
2673 for (i = 0; i < MAXLDFW; i++) lgl->wchs->start[i] = INT_MAX;
2674 lglpushstk (lgl, &lgl->wchs->stk, INT_MAX);
2675 lglpushstk (lgl, &lgl->wchs->stk, INT_MAX);
2678 lgl->scinc = lglflt (0, 1);
2688 static void lglcopyclonenfork (LGL * dst, LGL * src) {
2689 memcpy (dst->opts, src->opts, sizeof *src->opts);
2690 dst->out = src->out;
2691 if (dst->prefix) lgldelstr (dst, dst->prefix);
2692 dst->prefix = lglstrdup (dst, src->prefix);
2695 if (src->cbs->onabort) {
2696 dst->cbs->abortstate = src->cbs->abortstate;
2697 dst->cbs->onabort = src->cbs->onabort;
2699 if (src->cbs->getime) dst->cbs->getime = src->cbs->getime;
2703 static void lglcompact (LGL *);
2705 LGL * lglmclone (LGL * orig,
2709 lgldealloc dealloc) {
2710 size_t max_bytes, current_bytes;
2714 if (!orig) return 0;
2717 lgl = lglnewlgl (mem, alloc, realloc, dealloc);
2718 memcpy (lgl, orig, ((char*)&orig->mem) - (char*) orig);
2719 max_bytes = lgl->stats->bytes.max;
2720 current_bytes = lgl->stats->bytes.current;
2721 memcpy (lgl->stats, orig->stats, sizeof *orig->stats);
2722 lgl->stats->bytes.current = current_bytes;
2723 lgl->stats->bytes.max = max_bytes;
2725 lglcopyclonenfork (lgl, orig);
2729 CLONE (timers, 1); assert (!lgl->timers->nest);
2731 CLONE (ext, orig->szext);
2732 CLONE (i2e, orig->szvars);
2733 CLONE (doms, 2*orig->szvars);
2734 CLONE (dvars, orig->szvars);
2735 CLONE (qvars, orig->szvars);
2736 CLONE (avars, orig->szvars);
2737 CLONE (vals, orig->szvars);
2738 CLONE (jwh, 2*orig->szvars);
2739 CLONE (drail, orig->szdrail);
2741 NEW (lgl->red, MAXGLUE+1);
2742 for (glue = 0; glue <= MAXGLUE; glue++) CLONESTK (red[glue]);
2745 memcpy (lgl->wchs, orig->wchs, sizeof *orig->wchs);
2746 CLONESTK (wchs->stk);
2767 for (p = (char*)&orig->elm; p < (char*)(&orig->repr+1); p++) assert (!*p);
2770 assert (lgl->stats->bytes.current == orig->stats->bytes.current);
2771 assert (lgl->stats->bytes.max <= orig->stats->bytes.max);
2772 lgl->stats->bytes.max = orig->stats->bytes.max;
2776 LGL * lglclone (LGL * lgl) {
2778 return lglmclone (lgl,
2785 void lglchkclone (LGL * lgl) {
2786 REQINITNOTFORKED ();
2789 if (!lgl->opts->druplig.val) {
2790 if (lgl->clone) lglrelease (lgl->clone);
2791 lgl->clone = lglclone (lgl);
2796 LGL * lglinit (void) { return lglminit (0, 0, 0, 0); }
2798 static int lglmaxoptnamelen (LGL * lgl) {
2801 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++)
2802 if ((len = strlen (o->lng)) > res)
2807 void lglusage (LGL * lgl) {
2811 REQINITNOTFORKED ();
2812 len = lglmaxoptnamelen (lgl);
2813 sprintf (fmt, "--%%-%ds", len);
2814 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++) {
2815 if (o->shrt) fprintf (lgl->out, "-%c|", o->shrt);
2816 else fprintf (lgl->out, " ");
2817 fprintf (lgl->out, fmt, o->lng);
2818 fprintf (lgl->out, " %s [%d]\n", o->descrp, o->val);
2822 static int lglignopt (const char * name) {
2823 if (!strcmp (name, "abstime")) return 1;
2824 if (!strcmp (name, "check")) return 1;
2825 if (!strcmp (name, "drup")) return 1;
2826 if (!strcmp (name, "exitonabort")) return 1;
2827 if (!strcmp (name, "log")) return 1;
2828 if (!strcmp (name, "sleeponabort")) return 1;
2829 if (!strcmp (name, "verbose")) return 1;
2830 if (!strcmp (name, "witness")) return 1;
2834 void lglopts (LGL * lgl, const char * prefix, int ignsome) {
2836 REQINITNOTFORKED ();
2837 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++) {
2838 if (ignsome && lglignopt (o->lng)) continue;
2839 fprintf (lgl->out, "%s--%s=%d\n", prefix, o->lng, o->val);
2843 void lglrgopts (LGL * lgl) {
2845 REQINITNOTFORKED ();
2846 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++)
2847 fprintf (lgl->out, "%s %d %d %d\n", o->lng, o->val, o->min, o->max);
2850 void lglpcs (LGL * lgl, int mixed) {
2851 int i, printi, printl;
2854 REQINITNOTFORKED ();
2855 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++) {
2856 if (lglignopt (o->lng)) continue;
2857 range = o->max; range -= o->min;
2858 if (range >= 7 && mixed < 0) continue;
2859 printi = printl = 0;
2860 printf ("%s ", o->lng);
2862 printf ("{%d", o->min);
2863 for (i = o->min + 1; i <= o->max; i++) printf (",%d", i);
2865 } else if (!mixed) {
2866 printf ("[%d,%d]", o->min, o->max);
2868 printl = (o->min > 0 && range >= 100);
2869 } else if (o->dflt == o->min || o->dflt == o->max) {
2870 printf ("{%d,%d,%d,%d,%d}",
2872 (int)(o->min + (1*range + 3)/4),
2873 (int)(o->min + (2*range + 3)/4),
2874 (int)(o->min + (3*range + 3)/4),
2876 } else if (o->dflt == o->min + 1) {
2877 printf ("{%d,%d,%d,%d}",
2880 (int)(o->dflt + (o->max - (int64_t) o->dflt)/2),
2882 } else if (o->dflt + 1 == o->max) {
2883 printf ("{%d,%d,%d,%d}",
2885 (int)(o->min + (o->dflt - (int64_t) o->min)/2),
2889 assert (o->dflt - o->min >= 2);
2890 assert (o->max - o->dflt >= 2);
2891 printf ("{%d,%d,%d,%d,%d}",
2893 (int)(o->min + (o->dflt - (int64_t) o->min)/2),
2895 (int)(o->dflt + (o->max - (int64_t) o->min)/2),
2898 printf ("[%d]", o->dflt);
2899 if (printi) printf ("i");
2900 if (printl) printf ("l");
2901 printf (" # %s\n",o->descrp);
2905 int lglhasopt (LGL * lgl, const char * opt) {
2907 REQINITNOTFORKED ();
2908 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++) {
2909 if (!opt[1] && o->shrt == opt[0]) return 1;
2910 if (!strcmp (o->lng, opt)) return 1;
2915 void * lglfirstopt (LGL * lgl) { return FIRSTOPT (lgl); }
2917 void * lglnextopt (LGL * lgl,
2919 const char **nameptr,
2920 int *valptr, int *minptr, int *maxptr) {
2921 Opt * opt = current, * res = opt + 1;
2922 if (res > LASTOPT (lgl)) return 0;
2923 if (nameptr) *nameptr = opt->lng;
2924 if (valptr) *valptr = opt->val;
2925 if (minptr) *minptr = opt->min;
2926 if (maxptr) *maxptr = opt->max;
2930 void lglsetopt (LGL * lgl, const char * opt, int val) {
2933 REQINITNOTFORKED ();
2934 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++) {
2935 if (!opt[1] && o->shrt == opt[0]) break;
2936 if (!strcmp (o->lng, opt)) break;
2938 if (o > LASTOPT (lgl)) return;
2939 if (val < o->min) val = o->min;
2940 if (o->max < val) val = o->max;
2943 if (o == &lgl->opts->flipping && !oldval)
2944 lgl->flipping = lgl->notflipped = 0;
2945 if (o == &lgl->opts->plain) {
2946 if (val > 0 && !oldval) lglsetplain (lgl, 1);
2947 if (!val && oldval) lglsetplain (lgl, 0);
2949 if (o == &lgl->opts->drup) {
2950 if (val > 0 && !oldval) lglsetdrup (lgl, 1);
2951 if (!val && oldval) lglsetdrup (lgl, 0);
2953 if (o == &lgl->opts->druplig) {
2954 if (val > 0 && !oldval) lglsetdruplig (lgl, 1);
2955 if (!val && oldval) lglsetdruplig (lgl, 0);
2957 if (o == &lgl->opts->wait) {
2958 if (val > 0 && !oldval) lglsetwait (lgl, 1);
2959 if (!val && oldval) lglsetwait (lgl, 0);
2961 if (o == &lgl->opts->phase && val != oldval) lgl->flushphases = 1;
2962 if (lgl->state == UNUSED) TRANS (OPTSET);
2963 TRAPI ("option %s %d", opt, val);
2966 static int lglws (int ch) {
2967 return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r';
2970 int lglreadopts (LGL * lgl, FILE * file) {
2971 int res, ch, val, nvalbuf, noptbuf;
2972 char optbuf[40], valbuf[40];
2976 while (lglws (ch = getc (file)))
2978 if (ch == EOF) break;
2980 optbuf[noptbuf++] = ch;
2981 while ((ch = getc (file)) != EOF && !lglws (ch)) {
2982 if (noptbuf + 1 >= sizeof optbuf) { ch = EOF; break; }
2983 optbuf[noptbuf++] = ch;
2985 if (ch == EOF) break;
2986 assert (noptbuf < sizeof optbuf);
2987 optbuf[noptbuf++] = 0;
2988 assert (lglws (ch));
2989 while (lglws (ch = getc (file)))
2991 if (ch == EOF) break;
2993 valbuf[nvalbuf++] = ch;
2994 while ((ch = getc (file)) != EOF && !lglws (ch)) {
2995 if (nvalbuf + 1 >= sizeof valbuf) break;
2996 valbuf[nvalbuf++] = ch;
2998 assert (nvalbuf < sizeof valbuf);
2999 valbuf[nvalbuf++] = 0;
3001 val = atoi (valbuf);
3002 lglprt (lgl, 1, "read option --%s=%d", opt, val);
3003 lglsetopt (lgl, opt, val);
3009 void lglsetout (LGL * lgl, FILE * out) { lgl->out = out; }
3011 FILE * lglgetout (LGL * lgl) { return lgl->out; }
3013 void lglsetprefix (LGL * lgl, const char * prefix) {
3014 lgldelstr (lgl, lgl->prefix);
3015 lgl->prefix = lglstrdup (lgl, prefix);
3018 const char * lglgetprefix (LGL * lgl) { return lgl->prefix; }
3020 static Opt * lgligetopt (LGL * lgl, const char * opt) {
3022 REQINITNOTFORKED ();
3023 for (o = FIRSTOPT (lgl); o <= LASTOPT (lgl); o++) {
3024 if (!opt[1] && o->shrt == opt[0]) return o;
3025 if (!strcmp (o->lng, opt)) return o;
3030 int lglgetopt (LGL * lgl, const char * opt) {
3031 Opt * o = lgligetopt (lgl, opt);
3032 return o ? o->val : 0;
3035 int lglgetoptminmax (LGL * lgl, const char * opt,
3036 int * min_ptr, int * max_ptr) {
3037 Opt * o = lgligetopt (lgl, opt);
3039 if (min_ptr) *min_ptr = o->min;
3040 if (max_ptr) *max_ptr = o->max;
3044 /*------------------------------------------------------------------------*/
3046 static void lglrszvars (LGL * lgl, int new_size) {
3047 int old_size = lgl->szvars;
3048 assert (lgl->nvars <= new_size);
3049 RSZ (lgl->vals, old_size, new_size);
3050 RSZ (lgl->i2e, old_size, new_size);
3051 RSZ (lgl->doms, 2*old_size, 2*new_size);
3052 RSZ (lgl->dvars, old_size, new_size);
3053 RSZ (lgl->avars, old_size, new_size);
3054 RSZ (lgl->qvars, old_size, new_size);
3055 RSZ (lgl->jwh, 2*old_size, 2*new_size);
3056 lgl->szvars = new_size;
3059 static void lglenlvars (LGL * lgl) {
3060 size_t old_size, new_size;
3061 old_size = lgl->szvars;
3062 new_size = old_size ? 2 * old_size : 4;
3063 LOG (3, "enlarging internal variables from %ld to %ld", old_size, new_size);
3064 lglrszvars (lgl, new_size);
3067 static void lglredvars (LGL * lgl) {
3068 size_t old_size, new_size;
3069 old_size = lgl->szvars;
3070 new_size = lgl->nvars;
3071 if (new_size == old_size) return;
3072 LOG (3, "reducing variables from %ld to %ld", old_size, new_size);
3073 lglrszvars (lgl, new_size);
3076 static int lglmax (int a, int b) { return a > b ? a : b; }
3078 static int lglmin (int a, int b) { return a < b ? a : b; }
3080 /*------------------------------------------------------------------------*/
3082 static DVar * lgldvar (LGL * lgl, int lit) {
3083 assert (2 <= abs (lit) && abs (lit) < lgl->nvars);
3084 return lgl->dvars + abs (lit);
3087 /*------------------------------------------------------------------------*/
3089 static AVar * lglavar (LGL * lgl, int lit) {
3090 assert (2 <= abs (lit) && abs (lit) < lgl->nvars);
3091 return lgl->avars + abs (lit);
3094 static Val lglval (LGL * lgl, int lit) {
3095 int idx = abs (lit);
3097 ASSERT (2 <= idx && idx < lgl->nvars);
3098 res = lgl->vals[idx];
3099 if (lit < 0) res = -res;
3103 static int lgltrail (LGL * lgl, int lit) { return lglavar (lgl, lit)->trail; }
3105 static TD * lgltd (LGL * lgl, int lit) {
3106 int pos = lgltrail (lgl, lit);
3107 assert (0 <= pos && pos < lgl->szdrail);
3108 return lgl->drail + pos;
3111 static int lglevel (LGL * lgl, int lit) { return lgltd (lgl, lit)->level; }
3113 static int lglisfree (LGL * lgl, int lit) {
3114 return lglavar (lgl, lit)->type == FREEVAR;
3117 /*------------------------------------------------------------------------*/
3119 static QVar * lglqvar (LGL * lgl, int lit) {
3120 assert (2 <= abs (lit) && abs (lit) < lgl->nvars);
3121 return lgl->qvars + abs (lit);
3124 static int * lgldpos (LGL * lgl, int lit) {
3127 qv = lglqvar (lgl, lit);
3132 static int lglscrcmp (Scr a, Scr b) {
3133 if (a < b) return -1;
3134 if (a > b) return 1;
3138 static int lgldcmp (LGL * lgl, int l, int k) {
3139 QVar * pv = lglqvar (lgl, l);
3140 QVar * qv = lglqvar (lgl, k);
3142 if ((res = lglscrcmp (pv->score, qv->score))) return res;
3143 res = lgl->bias * (l - k);
3148 static void lglchkdsched (LGL * lgl) {
3149 int * p, parent, child, ppos, cpos, size, i, tmp;
3150 Stk * s = &lgl->dsched;
3151 size = lglcntstk (s);
3153 for (ppos = 0; ppos < size; ppos++) {
3155 tmp = *lgldpos (lgl, parent);
3156 assert (ppos == tmp);
3157 for (i = 0; i <= 1; i++) {
3158 cpos = 2*ppos + 1 + i;
3159 if (cpos >= size) continue;
3161 tmp = *lgldpos (lgl, child);
3162 assert (cpos == tmp);
3163 assert (lgldcmp (lgl, parent, child) >= 0);
3169 static void lgldup (LGL * lgl, int lit) {
3170 int child = lit, parent, cpos, ppos, * p, * cposptr, * pposptr;
3171 Stk * s = &lgl->dsched;
3173 cposptr = lgldpos (lgl, child);
3177 ppos = (cpos - 1)/2;
3179 if (lgldcmp (lgl, parent, lit) >= 0) break;
3180 pposptr = lgldpos (lgl, parent);
3181 assert (*pposptr == ppos);
3184 LOGDSCHED (5, parent, "down from %d", ppos);
3187 if (*cposptr == cpos) return;
3193 LOGDSCHED (5, lit, "up from %d", ppos);
3195 if (lgl->opts->check.val >= 2) lglchkdsched (lgl);
3199 static void lglddown (LGL * lgl, int lit) {
3200 int parent = lit, child, right, ppos, cpos;
3201 int * p, * pposptr, * cposptr, size;
3202 Stk * s = &lgl->dsched;
3203 size = lglcntstk (s);
3205 pposptr = lgldpos (lgl, parent);
3210 if (cpos >= size) break;
3212 if (cpos + 1 < size) {
3213 right = p[cpos + 1];
3214 if (lgldcmp (lgl, child, right) < 0) cpos++, child = right;
3216 if (lgldcmp (lgl, child, lit) <= 0) break;
3217 cposptr = lgldpos (lgl, child);
3218 assert (*cposptr = cpos);
3221 LOGDSCHED (5, child, "up from %d", cpos);
3224 if (*pposptr == ppos) return;
3230 LOGDSCHED (5, lit, "down from %d", cpos);
3232 if (lgl->opts->check.val >= 2) lglchkdsched (lgl);
3236 static void lgldsched (LGL * lgl, int lit) {
3237 int * p = lgldpos (lgl, lit);
3238 Stk * s = &lgl->dsched;
3241 lglpushstk (lgl, s, lit);
3243 lglddown (lgl, lit);
3244 LOGDSCHED (4, lit, "pushed");
3247 static int lgltopdsched (LGL * lgl) {
3248 assert (!lglmtstk (&lgl->dsched));
3249 return lgl->dsched.start[0];
3252 static int lglpopdsched (LGL * lgl) {
3253 Stk * s = &lgl->dsched;
3254 int res, last, cnt, * p;
3256 assert (!lglmtstk (s));
3258 LOGDSCHED (4, res, "popped");
3259 qv = lglqvar (lgl, res);
3262 last = lglpopstk (s);
3263 cnt = lglcntstk (s);
3264 if (!cnt) { assert (last == res); return res; }
3265 p = lgldpos (lgl, last);
3269 lglddown (lgl, last);
3273 static void lgldreschedule (LGL * lgl) {
3274 Stk * s = &lgl->dsched;
3275 int idx, i, pos, cnt = lglcntstk (s);
3277 LOG (1, "rescheduling %d variables", cnt);
3278 for (idx = 2; idx < lgl->nvars; idx++) lglqvar (lgl, idx)->pos = -1;
3281 for (i = 0; i < cnt; i++) {
3283 assert (s->start + pos == s->top);
3285 if (abs (idx) <= 1) continue;
3286 qv = lglqvar (lgl, idx);
3287 if (!lglisfree (lgl, idx)) { qv->pos = -1; continue; }
3288 assert (qv->pos == -1);
3289 s->start[pos] = idx;
3293 lglddown (lgl, idx);
3295 LOG (1, "new schedule with %d variables", lglcntstk (s));
3298 if (lgl->opts->check.val >= 1) lglchkdsched (lgl);
3304 static void lglrescorevars (LGL * lgl) {
3305 Scr oldscinc, oldscore, newscore, oldmaxscore = 0, newmaxscore = 0;
3309 lgl->stats->rescored.vars++;
3310 for (idx = 2; idx < lgl->nvars; idx++) {
3311 qv = lglqvar (lgl, idx);
3312 oldscore = qv->score;
3313 if (oldscore > oldmaxscore) oldmaxscore = oldscore;
3315 if (lgl->opts->score.val == LGL_SCORE_EVSIDS ||
3316 lgl->opts->score.val == LGL_SCORE_AVG)
3317 newscore = lglshflt (oldscore, lgl->opts->maxscorexp.val);
3318 else newscore = (oldscore >> 32);
3320 newscore = oldscore / lgl->maxscore;
3322 qv->score = newscore;
3323 if (qv->score > newmaxscore) newmaxscore = qv->score;
3324 LOG (3, "rescored variable %d from %s to %s",
3325 idx, lglscr2str (lgl, oldscore), lglscr2str (lgl, qv->score));
3327 lgldreschedule (lgl);
3328 newotfs = lgl->stats->otfs.driving + lgl->stats->otfs.restarting;
3329 assert (newotfs >= lgl->limits->rescore.vars.otfs);
3330 assert (lgl->stats->confs >= lgl->limits->rescore.vars.confs);
3332 "[rescored-vars-%d] after %lld conflicts and %lld OTFS",
3333 lgl->stats->rescored.vars,
3334 lgl->stats->confs - lgl->limits->rescore.vars.confs,
3335 newotfs - lgl->limits->rescore.vars.otfs);
3336 lgl->limits->rescore.vars.confs = lgl->stats->confs;
3337 lgl->limits->rescore.vars.otfs = newotfs;
3339 "[rescored-vars-%d] old maximum score %s",
3340 lgl->stats->rescored.vars, lglscr2str (lgl, oldmaxscore));
3342 "[rescored-vars-%d] new maximum score %s",
3343 lgl->stats->rescored.vars, lglscr2str (lgl, newmaxscore));
3344 if (lgl->opts->score.val == LGL_SCORE_EVSIDS) {
3345 oldscinc = lgl->scinc;
3347 lgl->scinc = lglshflt (oldscinc, lgl->opts->maxscorexp.val);
3349 lgl->scinc = oldscinc / lgl->maxscore;
3351 assert (lgl->scinc > 0);
3353 "[rescored-vars-%d] old score increment %s",
3354 lgl->stats->rescored.vars, lglscr2str (lgl, oldscinc));
3356 "[rescored-vars-%d] new score increment %s",
3357 lgl->stats->rescored.vars, lglscr2str (lgl, lgl->scinc));
3361 static void lglbumpscinc (LGL * lgl) {
3363 if (lgl->opts->score.val == LGL_SCORE_VSIDS256) {
3364 if (!(lgl->stats->confs & 255)) {
3366 for (idx = 2; idx < lgl->nvars; idx++) {
3367 QVar * qv = lglqvar (lgl, idx);
3369 if (qv->pos < 0) continue;
3370 lglddown (lgl, idx);
3373 } else if (lgl->opts->score.val == LGL_SCORE_EVSIDS) {
3374 oldscinc = lgl->scinc;
3375 lgl->scinc = lglmulscr (oldscinc, lgl->scincf);
3376 LOG (3, "bumped variable score increment from %s to %s",
3377 lglscr2str (lgl, oldscinc), lglscr2str (lgl, lgl->scinc));
3378 if (lgl->scinc < lgl->maxscore) return;
3379 LOG (2, "variable max score %s hit", lglscr2str (lgl, lgl->maxscore));
3380 lglrescorevars (lgl);
3384 /*------------------------------------------------------------------------*/
3386 static int lglnewvar (LGL * lgl) {
3391 assert (!lgl->dense);
3392 if (lgl->nvars == lgl->szvars) lglenlvars (lgl);
3393 if (lgl->nvars) res = lgl->nvars++;
3394 else res = 2, lgl->nvars = 3;
3395 assert (res < lgl->szvars);
3396 if (res > MAXVAR) lgldie (lgl, "more than %d variables", MAXVAR - 1);
3397 assert (res <= MAXVAR);
3398 assert (((res << RMSHFT) >> RMSHFT) == res);
3399 assert (((-res << RMSHFT) >> RMSHFT) == -res);
3400 LOG (3, "new internal variable %d", res);
3401 dv = lgl->dvars + res;
3403 av = lgl->avars + res;
3405 qv = lgl->qvars + res;
3408 lgldsched (lgl, res);
3410 lgl->allphaseset = 0;
3414 static int lglsgn (int lit) { return (lit < 0) ? -1 : 1; }
3416 static Ext * lglelit2ext (LGL * lgl, int elit) {
3417 int idx = abs (elit);
3418 assert (0 < idx), assert (idx <= lgl->maxext);
3419 return lgl->ext + idx;
3423 static Ext * lgldlit2ext (LGL * lgl, int dlit) {
3424 int idx = abs (dlit);
3425 assert (0 < idx), assert (idx <= lgl->maxdef);
3426 return lgl->def + idx;
3430 static int lglerepr (LGL * lgl, int elit) {
3433 assert (0 < abs (elit)), assert (abs (elit) <= lgl->maxext);
3436 ext = lglelit2ext (lgl, res);
3437 if (!ext->equiv) break;
3439 if (res < 0) next = -next;
3444 ext = lglelit2ext (lgl, tmp);
3445 if (!ext->equiv) { assert (tmp == res); break; }
3447 ext->repr = (tmp < 0) ? -res : res;
3448 if (tmp < 0) next = -next;
3454 static void lgladjext (LGL * lgl, int eidx) {
3456 assert (eidx >= lgl->szext);
3457 assert (eidx > lgl->maxext);
3458 assert (lgl->szext >= lgl->maxext);
3460 new = old ? 2*old : 2;
3461 while (eidx >= new) new *= 2;
3462 assert (eidx < new), assert (new >= lgl->szext);
3463 LOG (3, "enlarging external variables from %ld to %ld", old, new);
3464 RSZ (lgl->ext, old, new);
3469 static void lgladjdef (LGL * lgl, int didx) {
3472 assert (didx >= lgl->szdef);
3473 assert (didx > lgl->maxdef);
3474 assert (lgl->szdef > lgl->maxdef);
3476 new = old ? 2*old : 2;
3477 while (didx >= new) new *= 2;
3478 assert (didx < new), assert (new >= lgl->szdef);
3479 LOG (3, "enlarging defined variables from %ld to %ld", old, new);
3480 RSZ (lgl->def, old, new);
3485 static void lglmelter (LGL * lgl) {
3486 if (lgl->allfrozen) {
3488 "[melter] not all literals assumed to be frozen anymore");
3491 if (lgl->limits->elm.pen || lgl->limits->blk.pen || lgl->limits->cce.pen) {
3493 "[melter] reset penalties: %d elm, %d blk, %d cce",
3494 lgl->limits->elm.pen, lgl->limits->blk.pen, lgl->limits->cce.pen);
3495 lgl->limits->elm.pen = lgl->limits->blk.pen = lgl->limits->cce.pen = 0;
3497 lgl->frozen = lgl->allfrozen = 0;
3498 LOG (2, "melted solver");
3501 static int lglimportaux (LGL * lgl, int elit) {
3502 int res, repr, eidx = abs (elit);
3505 if (eidx >= lgl->szext) lgladjext (lgl, eidx);
3506 if (eidx > lgl->maxext) {
3510 repr = lglerepr (lgl, elit);
3511 ext = lglelit2ext (lgl, repr);
3512 assert (!ext->equiv);
3514 if (!ext->imported) {
3515 res = lglnewvar (lgl);
3516 assert (!ext->equiv);
3519 assert (eidx <= INT_MAX/2);
3520 lgl->i2e[res] = 2*eidx;
3521 LOG (3, "mapping external variable %d to %d", eidx, res);
3524 if (repr < 0) res = -res;
3525 LOG (2, "importing %d as %d", elit, res);
3529 static int lglimport (LGL * lgl, int elit) {
3531 if (!lgl->opts->import.val) {
3532 if (!lgl->maxext) (void) lglimportaux (lgl, 1);
3533 while (lgl->maxext < abs (elit))
3534 (void) lglimportaux (lgl, lgl->maxext + 1);
3536 return lglimportaux (lgl, elit);
3539 static Stk * lglidx2stk (LGL * lgl, int red, int lidx) {
3542 assert (red == 0 || red == REDCS);
3544 if (!red) s = &lgl->irr;
3546 glue = lidx & GLUEMASK;
3548 assert (lidx <= MAXREDLIDX);
3549 s = &lgl->red[glue];
3554 static int * lglidx2lits (LGL * lgl, int red, int lidx) {
3555 Stk * s = lglidx2stk (lgl, red, lidx);
3557 assert (red == 0 || red == REDCS);
3559 res = s->start + (red ? (lidx >> GLUESHFT) : lidx);
3561 if (red && (lidx & GLUEMASK) == MAXGLUE) assert (res < s->end);
3562 else assert (res < s->top);
3568 static const char * lglred2str (int red) {
3569 assert (!red || red == REDCS);
3570 return red ? "redundant" : "irredundant";
3574 static int lgliselim (LGL * lgl, int lit) {
3575 Tag tag = lglavar (lgl, lit)->type;
3576 return tag == ELIMVAR;
3580 static int lglisdef (LGL * lgl, int ilit) {
3581 int iidx = abs (ilit), tidx, res;
3582 assert (2 <= iidx), assert (iidx < lgl->nvars);
3583 tidx = lgl->i2e[iidx];
3589 static int lglexport (LGL * lgl, int ilit) {
3590 int iidx, tidx, eidx, def, res;
3592 assert (2 <= iidx), assert (iidx < lgl->nvars);
3593 tidx = lgl->i2e[iidx];
3598 if (def) eidx += lgl->maxext;
3600 if (ilit < 0) res = -res;
3604 static int * lglrsn (LGL * lgl, int lit) { return lgltd (lgl, lit)->rsn; }
3606 static int lglulit (int lit) { return 2*abs (lit) + (lit < 0); }
3608 static void lglsetdom (LGL * lgl, int lit, int dom) {
3609 assert (2 <= abs (lit) && abs (lit) < lgl->nvars);
3610 assert (2 <= abs (dom) && abs (dom) < lgl->nvars);
3611 ASSERT (lglval (lgl, lit) >= 0);
3612 ASSERT (lglval (lgl, dom) >= 0);
3613 lgl->doms[lglulit (lit)] = dom;
3614 LOG (3, "literal %d dominated by %d", lit, dom);
3617 static int lglgetdom (LGL * lgl, int lit) {
3619 assert (2 <= abs (lit) && abs (lit) < lgl->nvars);
3620 assert (lglval (lgl, lit) >= 0);
3621 res = lgl->doms[lglulit (lit)];
3625 static HTS * lglhts (LGL * lgl, int lit) {
3626 return lgldvar (lgl, lit)->hts + (lit < 0);
3629 static int * lglhts2wchs (LGL * lgl, HTS * hts) {
3630 int * res = lgl->wchs->stk.start + hts->offset;
3631 assert (res < lgl->wchs->stk.top);
3632 assert (res + hts->count < lgl->wchs->stk.top);
3633 assert (res + hts->count < lgl->wchs->stk.top);
3637 static void lglassign (LGL * lgl, int lit, int r0, int r1) {
3638 int * p, other, other2, * c, lidx, found;
3639 int idx, phase, glue, tag, dom, red, irr;
3640 AVar * av = lglavar (lgl, lit);
3642 LOGREASON (2, lit, r0, r1, "assign %d through", lit);
3643 av->trail = lglcntstk (&lgl->trail);
3644 if (av->trail >= lgl->szdrail) {
3645 int newszdrail = lgl->szdrail ? 2*lgl->szdrail : 1;
3646 RSZ (lgl->drail, lgl->szdrail, newszdrail);
3647 lgl->szdrail = newszdrail;
3649 td = lgltd (lgl, lit);
3651 dom = (tag == BINCS) ? lglgetdom (lgl, -(r0 >> RMSHFT)) : lit;
3652 lglsetdom (lgl, lit, dom);
3655 if (tag == BINCS || tag == TRNCS) {
3656 other = r0 >> RMSHFT;
3657 assert (lglval (lgl, other) < 0);
3660 assert (lglval (lgl, other2) < 0);
3662 } else if (tag == LRGCS) {
3665 c = lglidx2lits (lgl, red, lidx);
3667 for (p = c; (other = *p); p++)
3668 if (other == lit) found++;
3669 else assert (lglval (lgl, other) < 0);
3670 assert (found == 1);
3671 } else assert (tag == DECISION || tag == UNITCS);
3673 assert (!lglval (lgl, lit));
3674 assert (lgl->unassigned > 0);
3675 assert (!lgliselim (lgl, lit));
3678 phase = lglsgn (lit);
3679 lgl->vals[idx] = phase;
3680 if (!lgl->simp && !lgl->flipping && !lgl->phaseneg) {
3681 lgl->flips -= lgl->flips/100000ull;
3682 if (av->phase != phase) lgl->flips += 10000ull;
3686 if (phase < 0) av->wasfalse = 1; else av->wasfalse = 0;
3688 td->level = lgl->level;
3691 if (av->type == EQUIVAR) {
3692 assert (lgl->stats->equiv.current > 0);
3693 lgl->stats->equiv.current--;
3694 assert (lgl->stats->equiv.sum > 0);
3695 lgl->stats->equiv.sum--;
3697 assert (av->type == FREEVAR);
3698 av->type = FIXEDVAR;
3700 lgl->stats->fixed.sum++;
3701 lgl->stats->fixed.current++;
3702 lgl->stats->prgss++;
3703 lgl->stats->irrprgss++;
3704 td->rsn[0] = UNITCS | (lit << RMSHFT);
3706 if (lgl->cbs && lgl->cbs->units.produce.fun) {
3707 LOG (2, "trying to export internal unit %d external %d\n",
3708 lgl->tid, lit, lglexport (lgl, lit));
3709 lgl->stats->sync.units.produced++;
3710 lgl->cbs->units.produce.fun (lgl->cbs->units.produce.state,
3711 lglexport (lgl, lit));
3712 LOG (2, "exporting internal unit %d external %d\n",
3713 lgl->tid, lit, lglexport (lgl, lit));
3718 if (lgl->level == 1) {
3719 assert (tag != UNITCS);
3720 if (tag == DECISION) irr = 1;
3721 else if ((irr = !(red = (r0 & REDCS)))) {
3723 other = r0 >> RMSHFT;
3724 irr = lgltd (lgl, other)->irr;
3725 } else if (tag == TRNCS) {
3726 other = r0 >> RMSHFT;
3727 if ((irr = lgltd (lgl, other)->irr)) {
3729 irr = lgltd (lgl, other2)->irr;
3732 assert (tag == LRGCS);
3734 c = lglidx2lits (lgl, red, lidx);
3736 for (p = c; irr && (other = *p); p++)
3737 if (other == lit) found++;
3738 else irr = lgltd (lgl, other)->irr;
3739 assert (!irr || found == 1);
3746 lglpushstk (lgl, &lgl->trail, lit);
3747 if (!lgl->failed && (av->assumed & (1u << (lit > 0)))) {
3748 LOG (2, "failed assumption %d", -lit);
3753 if ((r0 & REDCS) && (r0 & MASKCS) == LRGCS) {
3754 glue = r1 & GLUEMASK;
3755 lgl->stats->lir[glue].forcing++;
3756 assert (lgl->stats->lir[glue].forcing > 0);
3757 if (lgl->level && 0 < glue && glue < MAXGLUE) {
3758 lgl->lrgluereasons++;
3759 assert (lgl->lrgluereasons > 0);
3763 if (glue == MAXGLUE)
3764 assert ((r1 >> GLUESHFT) + 4 < lglcntstk (&lgl->red[MAXGLUE]));
3769 static void lglf2rce (LGL * lgl, int lit, int other, int red) {
3770 assert (lglval (lgl, other) < 0);
3771 assert (!red || red == REDCS);
3772 assert (!lgliselim (lgl, other));
3773 lglassign (lgl, lit, ((other << RMSHFT) | BINCS | red), 0);
3776 static void lglf3rce (LGL * lgl, int lit, int other, int other2, int red) {
3777 assert (lglval (lgl, other) < 0);
3778 assert (lglval (lgl, other2) < 0);
3779 assert (!lgliselim (lgl, other));
3780 assert (!lgliselim (lgl, other2));
3781 assert (!red || red == REDCS);
3782 lglassign (lgl, lit, ((other << RMSHFT) | TRNCS | red), other2);
3785 static void lglflrce (LGL * lgl, int lit, int red, int lidx) {
3787 int * p = lglidx2lits (lgl, red, lidx), other;
3788 while ((other = *p++)) {
3789 assert (!lgliselim (lgl, other));
3790 if (other != lit) assert (lglval (lgl, other) < 0);
3792 assert (red == 0 || red == REDCS);
3794 lglassign (lgl, lit, red | LRGCS, lidx);
3797 static int lgldscheduled (LGL * lgl, int lit) {
3798 return lglqvar (lgl, lit)->pos >= 0;
3801 static void lglunassign (LGL * lgl, int lit) {
3802 int idx = abs (lit), r0, r1, tag, lidx, glue;
3804 LOG (2, "unassign %d", lit);
3805 assert (lglval (lgl, lit) > 0);
3806 assert (lgl->vals[idx] == lglsgn (lit));
3809 assert (lgl->unassigned > 0);
3810 if (!lgldscheduled (lgl, lit)) lgldsched (lgl, idx);
3811 td = lgltd (lgl, idx);
3813 if (!(r0 & REDCS)) return;
3815 if (tag != LRGCS) return;
3817 glue = r1 & GLUEMASK;
3819 assert (lgl->lrgluereasons > 0);
3820 lgl->lrgluereasons--;
3822 if (glue < MAXGLUE) return;
3823 lidx = r1 >> GLUESHFT;
3824 LOG (2, "eagerly deleting maximum glue clause at %d", lidx);
3825 lglrststk (&lgl->red[glue], lidx);
3828 static Val lglifixed (LGL * lgl, int lit) {
3830 if (!(res = lglval (lgl, lit))) return 0;
3831 if (lglevel (lgl, lit) > 0) return 0;
3835 static void lglbacktrack (LGL * lgl, int level) {
3837 assert (level >= 0);
3838 assert (lgl->level > level);
3839 LOG (2, "backtracking to level %d", level);
3840 assert (level <= lgl->level);
3841 assert (abs (lgl->failed) != 1 || lgl->failed == -1);
3843 lgl->failed != -1 &&
3844 lglevel (lgl, lgl->failed) > level) {
3845 LOG (2, "resetting failed assumption %d", lgl->failed);
3848 while (!lglmtstk (&lgl->trail)) {
3849 lit = lgltopstk (&lgl->trail);
3850 assert (abs (lit) > 1);
3851 if (lglevel (lgl, lit) <= level) break;
3852 lglunassign (lgl, lit);
3856 assert (!lgl->lrgluereasons);
3857 while (!lglmtstk (&lgl->red[MAXGLUE])) {
3858 int tmp = lglpopstk (&lgl->red[MAXGLUE]);
3859 assert (tmp >= NOTALIT);
3863 if (lgl->alevel > level) {
3865 "resetting assumption decision level to %d from %d",