ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Glucose2.cpp
Go to the documentation of this file.
1/***************************************************************************************[Solver.cc]
2 Glucose -- Copyright (c) 2013, Gilles Audemard, Laurent Simon
3 CRIL - Univ. Artois, France
4 LRI - Univ. Paris Sud, France
5
6Glucose sources are based on MiniSat (see below MiniSat copyrights). Permissions and copyrights of
7Glucose are exactly the same as Minisat on which it is based on. (see below).
8
9---------------
10
11Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
12Copyright (c) 2007-2010, Niklas Sorensson
13
14Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
15associated documentation files (the "Software"), to deal in the Software without restriction,
16including without limitation the rights to use, copy, modify, merge, publish, distribute,
17sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19
20The above copyright notice and this permission notice shall be included in all copies or
21substantial portions of the Software.
22
23THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
24NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
27OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28**************************************************************************************************/
29#include <math.h>
30
31#include "sat/glucose2/Sort.h"
33#include "sat/glucose2/System.h"
34#include "sat/glucose2/Solver.h"
35
37
39
40using namespace Gluco2;
41
42//=================================================================================================
43// Options:
44namespace Gluco2 {
45static const char* _cat = "CORE";
46static const char* _cr = "CORE -- RESTART";
47static const char* _cred = "CORE -- REDUCE";
48static const char* _cm = "CORE -- MINIMIZE";
49static const char* _certified = "CORE -- CERTIFIED UNSAT";
50
51
52
53
54static BoolOption opt_incremental (_cat,"incremental", "Use incremental SAT solving", false);
55static DoubleOption opt_K (_cr, "K", "The constant used to force restart", 0.8, DoubleRange(0, false, 1, false));
56static DoubleOption opt_R (_cr, "R", "The constant used to block restart", 1.4, DoubleRange(1, false, 5, false));
57static IntOption opt_size_lbd_queue (_cr, "szLBDQueue", "The size of moving average for LBD (restarts)", 50, IntRange(10, INT32_MAX));
58static IntOption opt_size_trail_queue (_cr, "szTrailQueue", "The size of moving average for trail (block restarts)", 5000, IntRange(10, INT32_MAX));
59
60static IntOption opt_first_reduce_db (_cred, "firstReduceDB", "The number of conflicts before the first reduce DB", 2000, IntRange(0, INT32_MAX));
61static IntOption opt_inc_reduce_db (_cred, "incReduceDB", "Increment for reduce DB", 300, IntRange(0, INT32_MAX));
62static IntOption opt_spec_inc_reduce_db (_cred, "specialIncReduceDB", "Special increment for reduce DB", 1000, IntRange(0, INT32_MAX));
63static IntOption opt_lb_lbd_frozen_clause (_cred, "minLBDFrozenClause", "Protect clauses if their LBD decrease and is lower than (for one turn)", 30, IntRange(0, INT32_MAX));
64
65static IntOption opt_lb_size_minimzing_clause (_cm, "minSizeMinimizingClause", "The min size required to minimize clause", 30, IntRange(3, INT32_MAX));
66static IntOption opt_lb_lbd_minimzing_clause (_cm, "minLBDMinimizingClause", "The min LBD required to minimize clause", 6, IntRange(3, INT32_MAX));
67
68
69static DoubleOption opt_var_decay (_cat, "var-decay", "The variable activity decay factor", 0.8, DoubleRange(0, false, 1, false));
70static DoubleOption opt_clause_decay (_cat, "cla-decay", "The clause activity decay factor", 0.999, DoubleRange(0, false, 1, false));
71static DoubleOption opt_random_var_freq (_cat, "rnd-freq", "The frequency with which the decision heuristic tries to choose a random variable", 0, DoubleRange(0, true, 1, true));
72static DoubleOption opt_random_seed (_cat, "rnd-seed", "Used by the random variable selection", 91648253, DoubleRange(0, false, HUGE_VAL, false));
73static IntOption opt_ccmin_mode (_cat, "ccmin-mode", "Controls conflict clause minimization (0=none, 1=basic, 2=deep)", 2, IntRange(0, 2));
74static IntOption opt_phase_saving (_cat, "phase-saving", "Controls the level of phase saving (0=none, 1=limited, 2=full)", 2, IntRange(0, 2));
75static BoolOption opt_rnd_init_act (_cat, "rnd-init", "Randomize the initial activity", false);
76/*
77static IntOption opt_restart_first (_cat, "rfirst", "The base restart interval", 100, IntRange(1, INT32_MAX));
78static DoubleOption opt_restart_inc (_cat, "rinc", "Restart interval increase factor", 2, DoubleRange(1, false, HUGE_VAL, false));
79*/
80static DoubleOption opt_garbage_frac (_cat, "gc-frac", "The fraction of wasted memory allowed before a garbage collection is triggered", 0.20, DoubleRange(0, false, HUGE_VAL, false));
81
82
83BoolOption opt_certified_ (_certified, "certified", "Certified UNSAT using DRUP format", false );
84StringOption opt_certified_file_ (_certified, "certified-output", "Certified UNSAT output file", "NULL");
85};
86
87//=================================================================================================
88// Constructor/Destructor:
89
90
92
93 // Parameters (user settable):
94 //
95 SolverType(0)
96 , pCnfFunc(NULL)
97 , nCallConfl(1000)
99 , pstop(NULL)
100 , nRuntimeLimit(0)
101
102 , verbosity (0)
103 , verbEveryConflicts(10000)
104 , showModel (0)
105 , K (opt_K)
106 , R (opt_R)
107 , sizeLBDQueue (opt_size_lbd_queue)
108 , sizeTrailQueue (opt_size_trail_queue)
109 , firstReduceDB (opt_first_reduce_db)
110 , incReduceDB (opt_inc_reduce_db)
111 , specialIncReduceDB (opt_spec_inc_reduce_db)
112 , lbLBDFrozenClause (opt_lb_lbd_frozen_clause)
113 , lbSizeMinimizingClause (opt_lb_size_minimzing_clause)
114 , lbLBDMinimizingClause (opt_lb_lbd_minimzing_clause)
115 , var_decay (opt_var_decay)
116 , clause_decay (opt_clause_decay)
117 , random_var_freq (opt_random_var_freq)
118 , random_seed (opt_random_seed)
119 , ccmin_mode (opt_ccmin_mode)
120 , phase_saving (opt_phase_saving)
121 , rnd_pol (false)
122 , rnd_init_act (opt_rnd_init_act)
123 , garbage_frac (opt_garbage_frac)
124 , certifiedOutput (NULL)
126 // Statistics: (formerly in 'SolverStats')
127 //
131 , curRestart(1)
132
133 , ok (true)
134 , cla_inc (1)
135 , var_inc (1)
138 , qhead (0)
139 , simpDB_assigns (-1)
140 , simpDB_props (0)
144
145 // Resource constraints:
146 //
147 , conflict_budget (-1)
148 , propagation_budget (-1)
150 , incremental(opt_incremental)
152
153 #ifdef CGLUCOSE_EXP
154 //, jheap (JustOrderLt(this))
155 , jheap (JustOrderLt2(this))
156 #endif
157{
158 MYFLAG=0;
159
160 // Initialize only first time. Useful for incremental solving, useless otherwise
161 lbdQueue.initSize(sizeLBDQueue);
162 trailQueue.initSize(sizeTrailQueue);
163 sumLBD = 0;
167
168
169 if(certifiedUNSAT) {
170 if(!strcmp(opt_certified_file_,"NULL")) {
171 certifiedOutput = fopen("/dev/stdout", "wb");
172 } else {
173 certifiedOutput = fopen(opt_certified_file_, "wb");
174 }
175 // fprintf(certifiedOutput,"o proof DRUP\n");
176 }
177
178 #ifdef CGLUCOSE_EXP
179 jhead= 0;
180 jftr = 0;
181 travId = 0;
182 travId_prev = 0;
183
184 // allocate space for clause interpretation
185 vec<Lit> tmp; tmp.growTo(3);
186 itpc = ca.alloc(tmp);
187 ca[itpc].shrink( ca[itpc].size() );
188
189 nSkipMark = 0;
190 #endif
191}
192
193
195{
196}
197
198
199/****************************************************************
200 Set the incremental mode
201****************************************************************/
202
203// This function set the incremental mode to true.
204// You can add special code for this mode here.
205
207 incremental = true;
208}
209
210// Number of variables without selectors
214
215
216//=================================================================================================
217// Minor methods:
218
219
220// Creates a new SAT variable in the solver. If 'decision' is cleared, variable will not be
221// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result).
222//
223Var Solver::newVar(bool sign, bool dvar)
224{
225 int v = nVars();
226 watches .init(mkLit(v, false));
227 watches .init(mkLit(v, true ));
228 watchesBin .init(mkLit(v, false));
229 watchesBin .init(mkLit(v, true ));
230 assigns .push(l_Undef);
231 vardata .push(mkVarData(CRef_Undef, 0));
232 //activity .push(0);
233 activity .push(rnd_init_act ? drand(random_seed) * 0.00001 : 0);
234 seen .push(0);
235 permDiff .push(0);
236 polarity .push(sign);
237 decision .push();
238 trail .capacity(v+1);
239
240
241 #ifdef CGLUCOSE_EXP
242 //jreason .capacity(v+1);
243 if( justUsage() ){
244 //jdata .push(mkJustData(false));
245 //jwatch .push(mkJustWatch());
246
247 jlevel .push(-1);
248 jnext .push(-1);
249
250 var2FanoutN.growTo( nVars()<<1, toLit(~0));
251 //var2FanoutP.growTo( nVars()<<1, toLit(~0));
252 var2Fanout0.growTo( nVars(), toLit(~0));
253 var2NodeData.growTo( nVars(), mkNodeData());
254 var2TravId .growTo( nVars(), 0);
255
256 setDecisionVar(v, dvar, false);
257 } else
258 setDecisionVar(v, dvar);
259 #else
260 setDecisionVar(v, dvar);
261 #endif
262
263 return v;
264}
265
266
267
269{
270 assert(decisionLevel() == 0);
271 if (!ok) return false;
272
273 if ( 0 ) {
274 for ( int i = 0; i < ps.size(); i++ )
275 printf( "%s%d ", (toInt(ps[i]) & 1) ? "-":"", toInt(ps[i]) >> 1 );
276 printf( "\n" );
277 }
278
279 // Check if clause is satisfied and remove false/duplicate literals:
280 sort(ps);
281
282 vec<Lit> oc;
283 oc.clear();
284
285 Lit p; int i, j, flag = 0;
286 if(certifiedUNSAT) {
287 for (i = j = 0, p = lit_Undef; i < ps.size(); i++) {
288 oc.push(ps[i]);
289 if (value(ps[i]) == l_True || ps[i] == ~p || value(ps[i]) == l_False)
290 flag = 1;
291 }
292 }
293
294 for (i = j = 0, p = lit_Undef; i < ps.size(); i++)
295 if (value(ps[i]) == l_True || ps[i] == ~p)
296 return true;
297 else if (value(ps[i]) != l_False && ps[i] != p)
298 ps[j++] = p = ps[i];
299 ps.shrink_(i - j);
300
301 if ( 0 ) {
302 for ( int i = 0; i < ps.size(); i++ )
303 printf( "%s%d ", (toInt(ps[i]) & 1) ? "-":"", toInt(ps[i]) >> 1 );
304 printf( "\n" );
305 }
306
307 if (flag && (certifiedUNSAT)) {
308 for (i = j = 0, p = lit_Undef; i < ps.size(); i++)
309 fprintf(certifiedOutput, "%i ", (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1));
310 fprintf(certifiedOutput, "0\n");
311
312 fprintf(certifiedOutput, "d ");
313 for (i = j = 0, p = lit_Undef; i < oc.size(); i++)
314 fprintf(certifiedOutput, "%i ", (var(oc[i]) + 1) * (-2 * sign(oc[i]) + 1));
315 fprintf(certifiedOutput, "0\n");
316 }
317
318 if (ps.size() == 0)
319 return ok = false;
320 else if (ps.size() == 1){
321 uncheckedEnqueue(ps[0]);
322 return ok = (propagate() == CRef_Undef);
323 }else{
324 CRef cr = ca.alloc(ps, false);
325 clauses.push(cr);
326 attachClause(cr);
327 }
328
329 return true;
330}
331
332
334 const Clause& c = ca[cr];
335
336 assert(c.size() > 1);
337 if(c.size()==2) {
338 watchesBin[~c[0]].push(Watcher(cr, c[1]));
339 watchesBin[~c[1]].push(Watcher(cr, c[0]));
340 } else {
341 watches[~c[0]].push(Watcher(cr, c[1]));
342 watches[~c[1]].push(Watcher(cr, c[0]));
343 }
344 if (c.learnt()) learnts_literals += c.size();
345 else clauses_literals += c.size(); }
346
347
348
349
350void Solver::detachClause(CRef cr, bool strict) {
351 const Clause& c = ca[cr];
352
353 assert(c.size() > 1);
354 if(c.size()==2) {
355 if (strict){
356 remove(watchesBin[~c[0]], Watcher(cr, c[1]));
357 remove(watchesBin[~c[1]], Watcher(cr, c[0]));
358 }else{
359 // Lazy detaching: (NOTE! Must clean all watcher lists before garbage collecting this clause)
360 watchesBin.smudge(~c[0]);
361 watchesBin.smudge(~c[1]);
362 }
363 } else {
364 if (strict){
365 remove(watches[~c[0]], Watcher(cr, c[1]));
366 remove(watches[~c[1]], Watcher(cr, c[0]));
367 }else{
368 // Lazy detaching: (NOTE! Must clean all watcher lists before garbage collecting this clause)
369 watches.smudge(~c[0]);
370 watches.smudge(~c[1]);
371 }
372 }
373 if (c.learnt()) learnts_literals -= c.size();
374 else clauses_literals -= c.size(); }
375
376
378
379 Clause& c = ca[cr];
380
381 if (certifiedUNSAT) {
382 fprintf(certifiedOutput, "d ");
383 for (int i = 0; i < c.size(); i++)
384 fprintf(certifiedOutput, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1));
385 fprintf(certifiedOutput, "0\n");
386 }
387
388 detachClause(cr);
389 // Don't leave pointers to free'd memory!
390 if (locked(c)) vardata[var(c[0])].reason = CRef_Undef;
391 c.mark(1);
392 ca.free_(cr);
393}
394
395
396bool Solver::satisfied(const Clause& c) const {
397 if(incremental) // Check clauses with many selectors is too time consuming
398 return (value(c[0]) == l_True) || (value(c[1]) == l_True);
399
400 // Default mode.
401 for (int i = 0; i < c.size(); i++)
402 if (value(c[i]) == l_True)
403 return true;
404 return false;
405}
406
407/************************************************************
408 * Compute LBD functions
409 *************************************************************/
410
411inline unsigned int Solver::computeLBD(const vec<Lit> & lits,int end) {
412 int nblevels = 0;
413 MYFLAG++;
414
415 if(incremental) { // ----------------- INCREMENTAL MODE
416 if(end==-1) end = lits.size();
417 unsigned int nbDone = 0;
418 for(int i=0;i<lits.size();i++) {
419 if(nbDone>=end) break;
420 if(isSelector(var(lits[i]))) continue;
421 nbDone++;
422 int l = level(var(lits[i]));
423 if (permDiff[l] != MYFLAG) {
424 permDiff[l] = MYFLAG;
425 nblevels++;
426 }
427 }
428 } else { // -------- DEFAULT MODE. NOT A LOT OF DIFFERENCES... BUT EASIER TO READ
429 for(int i=0;i<lits.size();i++) {
430 int l = level(var(lits[i]));
431 if (permDiff[l] != MYFLAG) {
432 permDiff[l] = MYFLAG;
433 nblevels++;
434 }
435 }
436 }
437
438 return nblevels;
439}
440
441inline unsigned int Solver::computeLBD(const Clause &c) {
442 int nblevels = 0;
443 MYFLAG++;
444
445 if(incremental) { // ----------------- INCREMENTAL MODE
446 int nbDone = 0;
447 for(int i=0;i<c.size();i++) {
448 if(nbDone>=c.sizeWithoutSelectors()) break;
449 if(isSelector(var(c[i]))) continue;
450 nbDone++;
451 int l = level(var(c[i]));
452 if (permDiff[l] != MYFLAG) {
453 permDiff[l] = MYFLAG;
454 nblevels++;
455 }
456 }
457 } else { // -------- DEFAULT MODE. NOT A LOT OF DIFFERENCES... BUT EASIER TO READ
458 for(int i=0;i<c.size();i++) {
459 int l = level(var(c[i]));
460 if (permDiff[l] != MYFLAG) {
461 permDiff[l] = MYFLAG;
462 nblevels++;
463 }
464 }
465 }
466 return nblevels;
467}
468
469
470/******************************************************************
471 * Minimisation with binary reolution
472 ******************************************************************/
474
475 // Find the LBD measure
476 unsigned int lbd = computeLBD(out_learnt);
477 Lit p = ~out_learnt[0];
478
479 if(lbd<=lbLBDMinimizingClause){
480 MYFLAG++;
481
482 for(int i = 1;i<out_learnt.size();i++) {
483 permDiff[var(out_learnt[i])] = MYFLAG;
484 }
485
486 vec<Watcher>& wbin = watchesBin[p];
487 int nb = 0;
488 for(int k = 0;k<wbin.size();k++) {
489 Lit imp = wbin[k].blocker;
490 if(permDiff[var(imp)]==MYFLAG && value(imp)==l_True) {
491 nb++;
492 permDiff[var(imp)]= MYFLAG-1;
493 }
494 }
495 int l = out_learnt.size()-1;
496 if(nb>0) {
498 for(int i = 1;i<out_learnt.size()-nb;i++) {
499 if(permDiff[var(out_learnt[i])]!=MYFLAG) {
500 Lit p = out_learnt[l];
501 out_learnt[l] = out_learnt[i];
502 out_learnt[i] = p;
503 l--;i--;
504 }
505 }
506
507 out_learnt.shrink_(nb);
508
509 }
510 }
511}
512
513// Revert to the state at given level (keeping all assignment at 'level' but not beyond).
514//
516 if (decisionLevel() > level){
517
518 #ifdef CGLUCOSE_EXP
519 if( 0 < justUsage() ){
520
521 for (int c = trail.size()-1; c >= trail_lim[level]; c--){
522 Var x = var(trail[c]);
523 assigns [x] = l_Undef;
524 if (phase_saving > 1 || ((phase_saving == 1) && c > trail_lim.last()))
525 polarity[x] = sign(trail[c]);
526 //gateClearJwatch(x, level);
527
528 var2NodeData[x].now = false;
529 }
530 for (int l = decisionLevel(); l > level; l -- ){
531 int q = jlevel[l], k;
532 jlevel[l] = -1;
533 while( -1 != q ){
534 k = jnext[q];
535 jnext[q] = -1;
536 Var v = var(trail[q]);
537 if( Solver::level(v) <= level ){
538 pushJustQueue(v,q);
539 }
540 q = k;
541 }
542 }
543 } else
544 #endif
545 for (int c = trail.size()-1; c >= trail_lim[level]; c--){
546 Var x = var(trail[c]);
547 assigns [x] = l_Undef;
548 if (phase_saving > 1 || ((phase_saving == 1) && c > trail_lim.last()))
549 polarity[x] = sign(trail[c]);
551 }
552
554
555 trail.shrink_(trail.size() - trail_lim[level]);
556 trail_lim.shrink_(trail_lim.size() - level);
557 }
558}
559
560
561//=================================================================================================
562// Major methods:
563
564
566{
567 Var next = var_Undef;
568
569 // Random decision:
570 if (drand(random_seed) < random_var_freq && !order_heap.empty()){
571 next = order_heap[irand(random_seed,order_heap.size())];
572 if (value(next) == l_Undef && decision[next])
573 rnd_decisions++; }
574
575 // Activity based decision:
576 while (next == var_Undef || value(next) != l_Undef || !decision[next])
577 if (order_heap.empty()){
578 next = var_Undef;
579 break;
580 }else
581 next = order_heap.removeMin();
582
583 return next == var_Undef ? lit_Undef : mkLit(next, rnd_pol ? drand(random_seed) < 0.5 : (polarity[next] != 0));
584}
585
586
587/*_________________________________________________________________________________________________
588|
589| analyze : (confl : Clause*) (out_learnt : vec<Lit>&) (out_btlevel : int&) -> [void]
590|
591| Description:
592| Analyze conflict and produce a reason clause.
593|
594| Pre-conditions:
595| * 'out_learnt' is assumed to be cleared.
596| * Current decision level must be greater than root level.
597|
598| Post-conditions:
599| * 'out_learnt[0]' is the asserting literal at level 'out_btlevel'.
600| * If out_learnt.size() > 1 then 'out_learnt[1]' has the greatest decision level of the
601| rest of literals. There may be others from the same level though.
602|
603|________________________________________________________________________________________________@*/
604void Solver::analyze(CRef confl, vec<Lit>& out_learnt,vec<Lit>&selectors, int& out_btlevel,unsigned int &lbd,unsigned int &szWithoutSelectors)
605{
606 //double clk = Abc_Clock();
607 heap_rescale = 0;
608
609 int pathC = 0;
610 Lit p = lit_Undef;
611
612 // Generate conflict clause:
613 //
614 out_learnt.push(); // (leave room for the asserting literal)
615 int index = trail.size() - 1;
616
617 analyze_toclear.shrink_( analyze_toclear.size() );
618 do{
619 assert(confl != CRef_Undef); // (otherwise should be UIP)
620
621 #ifdef CGLUCOSE_EXP
622 Clause& c = ca[ lit_Undef != p ? castCRef(p): getConfClause(confl) ];
623 #else
624 Clause& c = ca[confl];
625 #endif
626
627 // Special case for binary clauses
628 // The first one has to be SAT
629 if( p != lit_Undef && c.size()==2 && value(c[0])==l_False) {
630
631 assert(value(c[1])==l_True);
632 Lit tmp = c[0];
633 c[0] = c[1], c[1] = tmp;
634 }
635
636 if (c.learnt())
638
639#ifdef DYNAMICNBLEVEL
640 // DYNAMIC NBLEVEL trick (see competition'09 companion paper)
641 if(c.learnt() && c.lbd()>2) {
642 unsigned int nblevels = computeLBD(c);
643 if(nblevels+1<c.lbd() ) { // improve the LBD
644 if(c.lbd()<=lbLBDFrozenClause) {
645 c.setCanBeDel(false);
646 }
647 // seems to be interesting : keep it for the next round
648 c.setLBD(nblevels); // Update it
649 }
650 }
651#endif
652
653
654 for (int j = (p == lit_Undef) ? 0 : 1; j < c.size(); j++){
655 Lit q = c[j];
656 bool fBump = 0;
657
658 if (!seen[var(q)] && level(var(q)) > 0){
659 if(!isSelector(var(q))){
660 fBump = 1;
662 }
663 seen[var(q)] = 1;
664 if (level(var(q)) >= decisionLevel()) {
665 if( fBump )
666 analyze_toclear.push(q);
667 pathC++;
668 #ifdef UPDATEVARACTIVITY
669 // UPDATEVARACTIVITY trick (see competition'09 companion paper)
670 #ifdef CGLUCOSE_EXP
671 if(!isSelector(var(q)) && (reason(var(q))!= CRef_Undef)
672 && ! isGateCRef(reason(var(q))) && ca[reason(var(q))].learnt())
673 lastDecisionLevel.push(q);
674 #else
675 if(!isSelector(var(q)) && (reason(var(q))!= CRef_Undef) && ca[reason(var(q))].learnt())
676 lastDecisionLevel.push(q);
677 #endif
678 #endif
679
680 } else {
681 if(isSelector(var(q))) {
682 assert(value(q) == l_False);
683 selectors.push(q);
684 } else
685 out_learnt.push(q);
686 }
687 }
688 }
689
690 // Select next clause to look at:
691 while (!seen[var(trail[index--])]);
692 p = trail[index+1];
693 confl = reason(var(p));
694 seen[var(p)] = 0;
695 pathC--;
696
697 }while (pathC > 0);
698 out_learnt[0] = ~p;
699
700 // Simplify conflict clause:
701 //
702 int i, j;
703
704 for(i = 0;i<selectors.size();i++) out_learnt.push(selectors[i]);
705
706
707 #ifdef CGLUCOSE_EXP
708 for(i = 0;i<out_learnt.size();i++)
709 analyze_toclear.push(out_learnt[i]);
710 #else
711 out_learnt.copyTo_(analyze_toclear);
712 #endif
713 if (ccmin_mode == 2){
714 uint32_t abstract_level = 0;
715 for (i = 1; i < out_learnt.size(); i++)
716 abstract_level |= abstractLevel(var(out_learnt[i])); // (maintain an abstraction of levels involved in conflict)
717
718 for (i = j = 1; i < out_learnt.size(); i++)
719 if (reason(var(out_learnt[i])) == CRef_Undef || !litRedundant(out_learnt[i], abstract_level))
720 out_learnt[j++] = out_learnt[i];
721
722 }else if (ccmin_mode == 1){
723 for (i = j = 1; i < out_learnt.size(); i++){
724 Var x = var(out_learnt[i]);
725
726 if (reason(x) == CRef_Undef)
727 out_learnt[j++] = out_learnt[i];
728 else{
729 #ifdef CGLUCOSE_EXP
730 Clause& c = ca[castCRef(out_learnt[i])];
731 #else
732 Clause& c = ca[reason(var(out_learnt[i]))];
733 #endif
734 // Thanks to Siert Wieringa for this bug fix!
735 for (int k = ((c.size()==2) ? 0:1); k < c.size(); k++)
736 if (!seen[var(c[k])] && level(var(c[k])) > 0){
737 out_learnt[j++] = out_learnt[i];
738 break; }
739 }
740 }
741 }else
742 i = j = out_learnt.size();
743
744 max_literals += out_learnt.size();
745 out_learnt.shrink_(i - j);
746 tot_literals += out_learnt.size();
747
748
749 /* ***************************************
750 Minimisation with binary clauses of the asserting clause
751 First of all : we look for small clauses
752 Then, we reduce clauses with small LBD.
753 Otherwise, this can be useless
754 */
755 if(!incremental && out_learnt.size()<=lbSizeMinimizingClause) {
757 }
758 // Find correct backtrack level:
759 //
760 if (out_learnt.size() == 1)
761 out_btlevel = 0;
762 else{
763 int max_i = 1;
764 // Find the first literal assigned at the next-highest level:
765 for (int i = 2; i < out_learnt.size(); i++)
766 if (level(var(out_learnt[i])) > level(var(out_learnt[max_i])))
767 max_i = i;
768 // Swap-in this literal at index 1:
769 Lit p = out_learnt[max_i];
770 out_learnt[max_i] = out_learnt[1];
771 out_learnt[1] = p;
772 out_btlevel = level(var(p));
773 }
774
775
776 // Compute the size of the clause without selectors (incremental mode)
777 if(incremental) {
778 szWithoutSelectors = 0;
779 for(int i=0;i<out_learnt.size();i++) {
780 if(!isSelector(var((out_learnt[i])))) szWithoutSelectors++;
781 else if(i>0) break;
782 }
783 } else
784 szWithoutSelectors = out_learnt.size();
785
786 // Compute LBD
787 lbd = computeLBD(out_learnt,out_learnt.size()-selectors.size());
788
789
790#ifdef UPDATEVARACTIVITY
791 // UPDATEVARACTIVITY trick (see competition'09 companion paper)
792 if(lastDecisionLevel.size()>0) {
793 for(int i = 0;i<lastDecisionLevel.size();i++) {
794 Lit t = lastDecisionLevel[i];
795 //assert( ca[reason(var(t))].learnt() );
796 if(ca[reason(var(t))].lbd()<lbd)
798 }
799 lastDecisionLevel.shrink_( lastDecisionLevel.size() );
800 }
801#endif
802
803
804 if( justUsage() ){
805 if( heap_rescale )
806 {
807 for (j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0;
808
809 analyze_toclear.shrink_( analyze_toclear.size() );
810 for (j = 0; j < jheap.size(); j++){
811 Var x = jheap[j];
812 if( var2NodeData[x].now )
813 analyze_toclear.push(mkLit(x));
814 }
815 for (j = 0; j < analyze_toclear.size(); j++){
816 Var x = var(analyze_toclear[j]);
817// jdata[x].act_fanin = activity[getFaninVar0(x)] > activity[getFaninVar1(x)]? activity[getFaninVar0(x)]: activity[getFaninVar1(x)];
818// jheap.update(x);
820 jheap.update( JustKey( activity[getFaninVar1(x)], x, jheap.data_attr(x) ) );
821 else
822 jheap.update( JustKey( activity[getFaninVar0(x)], x, jheap.data_attr(x) ) );
823 }
824
825 } else {
826
827 for (j = 0; j < analyze_toclear.size(); j++)
828 {
829 seen[var(analyze_toclear[j])] = 0;
831 }
832 }
833 } else
834 for (j = 0; j < analyze_toclear.size(); j++) seen[var(analyze_toclear[j])] = 0; // ('seen[]' is now cleared)
835 for(j = 0 ; j<selectors.size() ; j++) seen[var(selectors[j])] = 0;
836}
837
838
839// Check if 'p' can be removed. 'abstract_levels' is used to abort early if the algorithm is
840// visiting literals at levels that cannot be removed later.
841bool Solver::litRedundant(Lit p, uint32_t abstract_levels)
842{
843 analyze_stack.shrink_( analyze_stack.size() ); analyze_stack.push(p);
844 int top = analyze_toclear.size();
845 while (analyze_stack.size() > 0){
847 #ifdef CGLUCOSE_EXP
848 Clause& c = ca[castCRef(analyze_stack.last())]; analyze_stack.pop();
849 #else
850 Clause& c = ca[reason(var(analyze_stack.last()))]; analyze_stack.pop();
851 #endif
852 if(c.size()==2 && value(c[0])==l_False) {
853 assert(value(c[1])==l_True);
854 Lit tmp = c[0];
855 c[0] = c[1], c[1] = tmp;
856 }
857
858 for (int i = 1; i < c.size(); i++){
859 Lit p = c[i];
860 if (!seen[var(p)] && level(var(p)) > 0){
861 if (reason(var(p)) != CRef_Undef && (abstractLevel(var(p)) & abstract_levels) != 0){
862 seen[var(p)] = 1;
863 analyze_stack.push(p);
864 analyze_toclear.push(p);
865 }else{
866 for (int j = top; j < analyze_toclear.size(); j++)
867 seen[var(analyze_toclear[j])] = 0;
868 analyze_toclear.shrink_(analyze_toclear.size() - top);
869 return false;
870 }
871 }
872 }
873 }
874
875 return true;
876}
877
878
879/*_________________________________________________________________________________________________
880|
881| analyzeFinal : (p : Lit) -> [void]
882|
883| Description:
884| Specialized analysis procedure to express the final conflict in terms of assumptions.
885| Calculates the (possibly empty) set of assumptions that led to the assignment of 'p', and
886| stores the result in 'out_conflict'.
887|________________________________________________________________________________________________@*/
888void Solver::analyzeFinal(Lit p, vec<Lit>& out_conflict)
889{
890 out_conflict.shrink_( out_conflict.size() );
891 out_conflict.push(p);
892
893 if (decisionLevel() == 0)
894 return;
895
896 seen[var(p)] = 1;
897
898 for (int i = trail.size()-1; i >= trail_lim[0]; i--){
899 Var x = var(trail[i]);
900 if (seen[x]){
901 if (reason(x) == CRef_Undef){
902 assert(level(x) > 0);
903 out_conflict.push(~trail[i]);
904 }else{
905 #ifdef CGLUCOSE_EXP
906 Clause& c = ca[castCRef(trail[i])];
907 #else
908 Clause& c = ca[reason(x)];
909 #endif
910 // for (int j = 1; j < c.size(); j++) Minisat (glucose 2.0) loop
911 // Bug in case of assumptions due to special data structures for Binary.
912 // Many thanks to Sam Bayless (sbayless@cs.ubc.ca) for discover this bug.
913 for (int j = ((c.size()==2) ? 0:1); j < c.size(); j++)
914 if (level(var(c[j])) > 0)
915 seen[var(c[j])] = 1;
916 }
917
918 seen[x] = 0;
919 }
920 }
921
922 seen[var(p)] = 0;
923}
924
926{
927 if( justUsage() && !isRoundWatch(var(p)) )
928 return;
929 assert(value(p) == l_Undef);
930 assigns[var(p)] = lbool(!sign(p));
931 vardata[var(p)] = mkVarData(from, decisionLevel());
932 trail.push_(p);
933}
934
935
936/*_________________________________________________________________________________________________
937|
938| propagate : [void] -> [Clause*]
939|
940| Description:
941| Propagates all enqueued facts. If a conflict arises, the conflicting clause is returned,
942| otherwise CRef_Undef.
943|
944| Post-conditions:
945| * the propagation queue is empty, even if there was a conflict.
946|________________________________________________________________________________________________@*/
948{
949 CRef confl = CRef_Undef;
950 int num_props = 0;
951 watches.cleanAll();
952 watchesBin.cleanAll();
953 while (qhead < trail.size()){
954 Lit p = trail[qhead++]; // 'p' is enqueued fact to propagate.
955 vec<Watcher>& ws = watches[p];
956 Watcher *i, *j, *end;
957 num_props++;
958
959 #ifdef CGLUCOSE_EXP
960 if( 2 <= justUsage() ){
961 CRef stats;
962 if( CRef_Undef != (stats = gatePropagate(p)) ){
963 confl = stats;
964 if( l_True == value(var(p)) ) return confl;
965 }
966 }
967 #endif
968
969 // First, Propagate binary clauses
970 vec<Watcher>& wbin = watchesBin[p];
971 for(int k = 0;k<wbin.size();k++) {
972 Lit imp = wbin[k].blocker;
973 if(value(imp) == l_False) {
974 return wbin[k].cref;
975 }
976 if(value(imp) == l_Undef) {
977 uncheckedEnqueue(imp,wbin[k].cref);
978 }
979 }
980
981
982
983 for (i = j = (Watcher*)ws, end = i + ws.size(); i != end;){
984 // Try to avoid inspecting the clause:
985 Lit blocker = i->blocker;
986 if (value(blocker) == l_True){
987 *j++ = *i++; continue; }
988
989 // Make sure the false literal is data[1]:
990 CRef cr = i->cref;
991 Clause& c = ca[cr];
992 Lit false_lit = ~p;
993 if (c[0] == false_lit)
994 c[0] = c[1], c[1] = false_lit;
995 assert(c[1] == false_lit);
996 i++;
997
998 // If 0th watch is true, then clause is already satisfied.
999 Lit first = c[0];
1000 Watcher w = Watcher(cr, first);
1001 if (first != blocker && value(first) == l_True){
1002 *j++ = w; continue; }
1003
1004 // Look for new watch:
1005 if(incremental) { // ----------------- INCREMENTAL MODE
1006 int choosenPos = -1;
1007 for (int k = 2; k < c.size(); k++) {
1008
1009 if (value(c[k]) != l_False){
1010 if(decisionLevel()>assumptions.size()) {
1011 choosenPos = k;
1012 break;
1013 } else {
1014 choosenPos = k;
1015
1016 if(value(c[k])==l_True || !isSelector(var(c[k]))) {
1017 break;
1018 }
1019 }
1020
1021 }
1022 }
1023 if(choosenPos!=-1) {
1024 c[1] = c[choosenPos]; c[choosenPos] = false_lit;
1025 watches[~c[1]].push(w);
1026 goto NextClause; }
1027 } else { // ----------------- DEFAULT MODE (NOT INCREMENTAL)
1028 for (int k = 2; k < c.size(); k++) {
1029
1030 if (value(c[k]) != l_False){
1031 c[1] = c[k]; c[k] = false_lit;
1032 watches[~c[1]].push(w);
1033 goto NextClause; }
1034 }
1035 }
1036
1037 // Did not find watch -- clause is unit under assignment:
1038 *j++ = w;
1039 if (value(first) == l_False){
1040 confl = cr;
1041 qhead = trail.size();
1042 // Copy the remaining watches:
1043 while (i < end)
1044 *j++ = *i++;
1045 }else {
1046 uncheckedEnqueue(first, cr);
1047
1048
1049 }
1050 NextClause:;
1051 }
1052 ws.shrink_(i - j);
1053 }
1054 propagations += num_props;
1055 simpDB_props -= num_props;
1056
1057 return confl;
1058}
1059
1060
1061
1062
1063
1064
1065/*_________________________________________________________________________________________________
1066|
1067| reduceDB : () -> [void]
1068|
1069| Description:
1070| Remove half of the learnt clauses, minus the clauses locked by the current assignment. Locked
1071| clauses are clauses that are reason to some assignment. Binary clauses are never removed.
1072|________________________________________________________________________________________________@*/
1073struct reduceDB_lt {
1074 ClauseAllocator& ca;
1076 bool operator () (CRef x, CRef y) {
1077
1078 // Main criteria... Like in MiniSat we keep all binary clauses
1079 if(ca[x].size()> 2 && ca[y].size()==2) return 1;
1080
1081 if(ca[y].size()> 2 && ca[x].size()==2) return 0;
1082 if(ca[x].size()==2 && ca[y].size()==2) return 0;
1083
1084 // Second one based on literal block distance
1085 if(ca[x].lbd()> ca[y].lbd()) return 1;
1086 if(ca[x].lbd()< ca[y].lbd()) return 0;
1087
1088 // Finally we can use old activity or size, we choose the last one
1089 return ca[x].activity() < ca[y].activity();
1090 //return x->size() < y->size();
1091 //return ca[x].size() > 2 && (ca[y].size() == 2 || ca[x].activity() < ca[y].activity()); }
1092 }
1093};
1094
1096{
1097 int i, j;
1098 nbReduceDB++;
1100
1101 // We have a lot of "good" clauses, it is difficult to compare them. Keep more !
1103 // Useless :-)
1104 if(ca[learnts.last()].lbd()<=5) nbclausesbeforereduce +=specialIncReduceDB;
1105
1106 // Don't delete binary or locked clauses. From the rest, delete clauses from the first half
1107 // Keep clauses which seem to be usefull (their lbd was reduce during this sequence)
1108
1109 int limit = learnts.size() / 2;
1110 for (i = j = 0; i < learnts.size(); i++){
1111 Clause& c = ca[learnts[i]];
1112 if (c.lbd()>2 && c.size() > 2 && c.canBeDel() && !locked(c) && (i < limit)) {
1115 }
1116 else {
1117 if(!c.canBeDel()) limit++; //we keep c, so we can delete an other clause
1118 c.setCanBeDel(true); // At the next step, c can be delete
1119 learnts[j++] = learnts[i];
1120 }
1121 }
1122 learnts.shrink_(i - j);
1123 checkGarbage();
1124}
1125
1126
1128{
1129 int i, j;
1130 for (i = j = 0; i < cs.size(); i++){
1131 Clause& c = ca[cs[i]];
1132 if (satisfied(c))
1133 removeClause(cs[i]);
1134 else
1135 cs[j++] = cs[i];
1136 }
1137 cs.shrink_(i - j);
1138}
1139
1140
1142{
1143 vec<Var> vs;
1144 for (Var v = 0; v < nVars(); v++)
1145 if (decision[v] && value(v) == l_Undef)
1146 vs.push(v);
1147 order_heap.build(vs);
1148}
1149
1150
1151/*_________________________________________________________________________________________________
1152|
1153| simplify : [void] -> [bool]
1154|
1155| Description:
1156| Simplify the clause database according to the current top-level assigment. Currently, the only
1157| thing done here is the removal of satisfied clauses, but more things can be put here.
1158|________________________________________________________________________________________________@*/
1160{
1161 assert(decisionLevel() == 0);
1162
1163 if (!ok || propagate() != CRef_Undef)
1164 return ok = false;
1165
1166 if (nAssigns() == simpDB_assigns || (simpDB_props > 0))
1167 return true;
1168
1169 // Remove satisfied clauses:
1171 if (remove_satisfied) // Can be turned off.
1173
1174 checkGarbage();
1175
1176 #ifdef CGLUCOSE_EXP
1177 if( !justUsage() )
1178 #endif
1180
1182 simpDB_props = clauses_literals + learnts_literals; // (shouldn't depend on stats really, but it will do for now)
1183
1184 return true;
1185}
1186
1187
1188/*_________________________________________________________________________________________________
1189|
1190| search : (nof_conflicts : int) (params : const SearchParams&) -> [lbool]
1191|
1192| Description:
1193| Search for a model the specified number of conflicts.
1194| NOTE! Use negative value for 'nof_conflicts' indicate infinity.
1195|
1196| Output:
1197| 'l_True' if a partial assigment that is consistent with respect to the clauseset is found. If
1198| all variables are decision variables, this means that the clause set is satisfiable. 'l_False'
1199| if the clause set is unsatisfiable. 'l_Undef' if the bound on number of conflicts is reached.
1200|________________________________________________________________________________________________@*/
1201lbool Solver::search(int nof_conflicts)
1202{
1203 assert(ok);
1204 int backtrack_level;
1205 int conflictC = 0;
1206 vec<Lit> learnt_clause,selectors;
1207 unsigned int nblevels,szWoutSelectors;
1208 bool blocked=false;
1209 starts++;
1210
1211 for (;;){
1212 CRef confl = propagate();
1213
1214 // exact conflict limit
1215 if ( !withinBudget() && confl != CRef_Undef ) {
1216 lbdQueue.fastclear();
1217 cancelUntil(0);
1218 return l_Undef; }
1219
1220 if (confl != CRef_Undef){
1221
1222 // CONFLICT
1223 conflicts++; conflictC++;conflictsRestarts++;
1224 if(conflicts%5000==0 && var_decay<0.95)
1225 var_decay += 0.01;
1226
1227 if (verbosity >= 1 && conflicts%verbEveryConflicts==0){
1228 printf("c | %8d %7d %5d | %7d %8d %8d | %5d %8d %6d %8d | %6.3f %% \n",
1229 (int)starts,(int)nbstopsrestarts, (int)(conflicts/starts),
1230 (int)dec_vars - (trail_lim.size() == 0 ? trail.size() : trail_lim[0]), nClauses(), (int)clauses_literals,
1231 (int)nbReduceDB, nLearnts(), (int)nbDL2,(int)nbRemovedClauses, progressEstimate()*100);
1232 }
1233 if (decisionLevel() == 0)
1234 return l_False;
1235
1236
1237 trailQueue.push(trail.size());
1238 // BLOCK RESTART (CP 2012 paper)
1239 if( conflictsRestarts>LOWER_BOUND_FOR_BLOCKING_RESTART && lbdQueue.isvalid() && trail.size()>R*trailQueue.getavg()) {
1240 lbdQueue.fastclear();
1242 if(!blocked) {lastblockatrestart=starts;nbstopsrestartssame++;blocked=true;}
1243 }
1244
1245 learnt_clause.shrink_( learnt_clause.size() );
1246 selectors .shrink_( selectors.size() );
1247 analyze(confl, learnt_clause, selectors,backtrack_level,nblevels,szWoutSelectors);
1248
1249 lbdQueue.push(nblevels);
1250 sumLBD += nblevels;
1251 cancelUntil(backtrack_level);
1252 if (certifiedUNSAT) {
1253 for (int i = 0; i < learnt_clause.size(); i++)
1254 fprintf(certifiedOutput, "%i " , (var(learnt_clause[i]) + 1) *
1255 (-2 * sign(learnt_clause[i]) + 1) );
1256 fprintf(certifiedOutput, "0\n");
1257 }
1258
1259 if (learnt_clause.size() == 1){
1260 uncheckedEnqueue(learnt_clause[0]);nbUn++;
1261 }else{
1262 CRef cr = ca.alloc(learnt_clause, true);
1263 ca[cr].setLBD(nblevels);
1264 ca[cr].setSizeWithoutSelectors(szWoutSelectors);
1265 if(nblevels<=2) nbDL2++; // stats
1266 if(ca[cr].size()==2) nbBin++; // stats
1267 learnts.push(cr);
1268 attachClause(cr);
1269
1270 claBumpActivity(ca[cr]);
1271 uncheckedEnqueue(learnt_clause[0], cr);
1272 }
1275
1276 }else{
1277 // Our dynamic restart, see the SAT09 competition compagnion paper
1278 if ( (conflictsRestarts && lbdQueue.isvalid() && lbdQueue.getavg()*K > sumLBD/conflictsRestarts) || (pstop && *pstop) ) {
1279 lbdQueue.fastclear();
1281 int bt = 0;
1282 if(incremental) { // DO NOT BACKTRACK UNTIL 0.. USELESS
1283 bt = (decisionLevel()<assumptions.size()) ? decisionLevel() : assumptions.size();
1284 }
1285 cancelUntil(bt);
1286 return l_Undef;
1287 }
1288
1289 // Simplify the set of problem clauses:
1290 if (decisionLevel() == 0 && !simplify()) {
1291 return l_False;
1292 }
1293 // Perform clause database reduction !
1295 {
1296 assert(learnts.size()>0);
1298 reduceDB();
1300 }
1301
1302 Lit next = lit_Undef;
1303 while (decisionLevel() < assumptions.size()){
1304 // Perform user provided assumption:
1306 if (value(p) == l_True){
1307 // Dummy decision level:
1309 } else if (value(p) == l_False){
1311 return l_False;
1312 } else {
1313 next = p;
1314 break;
1315 }
1316 }
1317
1318 #ifdef CGLUCOSE_EXP
1319 // pick from JustQueue
1320
1321 if (0 < justUsage())
1322 if ( next == lit_Undef ){
1323 int index = -1;
1324 decisions++;
1325 next = pickJustLit( index );
1326 if(next == lit_Undef)
1327 return l_True;
1328 //addJwatch(var(next), j_reason);
1329 jnext[index] = jlevel[decisionLevel()+1];
1330 jlevel[decisionLevel()+1] = index;
1331 }
1332 #endif
1333
1334 if (next == lit_Undef){
1335 // New variable decision:
1336 decisions++;
1337 next = pickBranchLit();
1338
1339 if (next == lit_Undef){
1340 // Model found:
1341 return l_True;
1342 }
1343 }
1344
1345 // Increase decision level and enqueue 'next'
1347 uncheckedEnqueue(next);
1348 }
1349 }
1350}
1351
1352
1353
1355{
1356 double progress = 0;
1357 double F = 1.0 / nVars();
1358
1359 for (int i = 0; i <= decisionLevel(); i++){
1360 int beg = i == 0 ? 0 : trail_lim[i - 1];
1361 int end = i == decisionLevel() ? trail.size() : trail_lim[i];
1362 progress += pow(F, i) * (end - beg);
1363 }
1364
1365 return progress / nVars();
1366}
1367
1369
1370 printf("c---------- Glucose Stats -------------------------\n");
1371 printf("c restarts : %ld\n", starts);
1372 printf("c nb ReduceDB : %ld\n", nbReduceDB);
1373 printf("c nb removed Clauses : %ld\n", nbRemovedClauses);
1374 printf("c nb learnts DL2 : %ld\n", nbDL2);
1375 printf("c nb learnts size 2 : %ld\n", nbBin);
1376 printf("c nb learnts size 1 : %ld\n", nbUn);
1377
1378 printf("c conflicts : %ld\n", conflicts);
1379 printf("c decisions : %ld\n", decisions);
1380 printf("c propagations : %ld\n", propagations);
1381
1382 printf("c SAT Calls : %d in %g seconds\n", nbSatCalls, totalTime4Sat);
1383 printf("c UNSAT Calls : %d in %g seconds\n", nbUnsatCalls, totalTime4Unsat);
1384 printf("c--------------------------------------------------\n");
1385
1386
1387}
1388
1389
1390// NOTE: assumptions passed in member-variable 'assumptions'.
1392{
1393
1394 #ifdef CGLUCOSE_EXP
1395 ResetJustData(false);
1396 #endif
1397
1399 printf("Can not use incremental and certified unsat in the same time\n");
1400 exit(-1);
1401 }
1402
1403 conflict.shrink_(conflict.size());
1404 if (!ok){
1406 return l_False;
1407 }
1408 double curTime = cpuTime();
1409
1410 solves++;
1411
1412 lbool status = l_Undef;
1413 if(!incremental && verbosity>=1) {
1414 printf("c ========================================[ MAGIC CONSTANTS ]==============================================\n");
1415 printf("c | Constants are supposed to work well together :-) |\n");
1416 printf("c | however, if you find better choices, please let us known... |\n");
1417 printf("c |-------------------------------------------------------------------------------------------------------|\n");
1418 printf("c | | | |\n");
1419 printf("c | - Restarts: | - Reduce Clause DB: | - Minimize Asserting: |\n");
1420 printf("c | * LBD Queue : %6d | * First : %6d | * size < %3d |\n",lbdQueue.maxSize(),nbclausesbeforereduce,lbSizeMinimizingClause);
1421 printf("c | * Trail Queue : %6d | * Inc : %6d | * lbd < %3d |\n",trailQueue.maxSize(),incReduceDB,lbLBDMinimizingClause);
1422 printf("c | * K : %6.2f | * Special : %6d | |\n",K,specialIncReduceDB);
1423 printf("c | * R : %6.2f | * Protected : (lbd)< %2d | |\n",R,lbLBDFrozenClause);
1424 printf("c | | | |\n");
1425printf("c ==================================[ Search Statistics (every %6d conflicts) ]=========================\n",verbEveryConflicts);
1426 printf("c | |\n");
1427
1428 printf("c | RESTARTS | ORIGINAL | LEARNT | Progress |\n");
1429 printf("c | NB Blocked Avg Cfc | Vars Clauses Literals | Red Learnts LBD2 Removed | | pol-inconsist\n");
1430 printf("c =========================================================================================================\n");
1431 }
1432
1433 // Search:
1434 int curr_restarts = 0;
1435 while (status == l_Undef){
1436 status = search(0); // the parameter is useless in glucose, kept to allow modifications
1437 if (!withinBudget() || terminate_search_early || (pstop && *pstop)) break;
1438 if (nRuntimeLimit && Abc_Clock() > nRuntimeLimit) break;
1439 curr_restarts++;
1440 }
1441
1442 if (!incremental && verbosity >= 1)
1443 printf("c =========================================================================================================\n");
1444
1445
1446 if (certifiedUNSAT){ // Want certified output
1447 if (status == l_False)
1448 fprintf(certifiedOutput, "0\n");
1449 fclose(certifiedOutput);
1450 }
1451
1452
1453 if (status == l_True){
1454
1455 if( justUsage() ){
1456 if( nSkipMark ){
1457 loadJust();
1458 } else {
1459 JustModel.shrink_(JustModel.size());
1460 assert(jheap.empty());
1461 //JustModel.growTo(nVars());
1462 int i = 0, j = 0;
1463 JustModel.push(toLit(0));
1464 for (; i < trail.size(); i++)
1465 if( isRoundWatch(var(trail[i])) && !isTwoFanin(var(trail[i])) )
1466 JustModel.push(trail[i]), j++;
1467 JustModel[0] = toLit(j);
1468 }
1469
1470 } else {
1471 // Extend & copy model:
1472 model.shrink_(model.size());
1473 model.growTo(nVars());
1474 for (int i = 0; i < trail.size(); i++) model[ var(trail[i]) ] = value(var(trail[i]));
1475 }
1476 }else if (status == l_False && conflict.size() == 0)
1477 ok = false;
1478
1479 //#ifdef CGLUCOSE_EXP
1480 //if(status == l_True && 0 < justUsage())
1481 // justCheck();
1482 //#endif
1483
1484 cancelUntil(0);
1485
1486 double finalTime = cpuTime();
1487 if(status==l_True) {
1488 nbSatCalls++;
1489 totalTime4Sat +=(finalTime-curTime);
1490 }
1491 if(status==l_False) {
1492 nbUnsatCalls++;
1493 totalTime4Unsat +=(finalTime-curTime);
1494 }
1495
1496 // ABC callback
1497 if (pCnfFunc && !terminate_search_early) {// hack to avoid calling callback twise if the solver was terminated early
1498 int * pCex = NULL;
1499 int message = (status == l_True ? 1 : status == l_False ? 0 : -1);
1500 if (status == l_True) {
1501 pCex = new int[nVars()];
1502 for (int i = 0; i < nVars(); i++)
1503 pCex[i] = (model[i] == l_True);
1504 }
1505
1506 int callback_result = pCnfFunc(pCnfMan, message, pCex);
1507 assert(callback_result == 0);
1508 }
1509 else if (pCnfFunc)
1510 terminate_search_early = false; // for next run
1511
1513 return status;
1514}
1515
1516//=================================================================================================
1517// Writing CNF to DIMACS:
1518//
1519// FIXME: this needs to be rewritten completely.
1520
1521static Var mapVar(Var x, vec<Var>& map, Var& max)
1522{
1523 if (map.size() <= x || map[x] == -1){
1524 map.growTo(x+1, -1);
1525 map[x] = max++;
1526 }
1527 return map[x];
1528}
1529
1530
1531void Solver::toDimacs(FILE* f, Clause& c, vec<Var>& map, Var& max)
1532{
1533 if (satisfied(c)) return;
1534
1535 for (int i = 0; i < c.size(); i++)
1536 if (value(c[i]) != l_False)
1537 fprintf(f, "%s%d ", sign(c[i]) ? "-" : "", mapVar(var(c[i]), map, max)+1);
1538 fprintf(f, "0\n");
1539}
1540
1541
1542void Solver::toDimacs(const char *file, const vec<Lit>& assumps)
1543{
1544 FILE* f = fopen(file, "wb");
1545 if (f == NULL)
1546 fprintf(stderr, "could not open file %s\n", file), exit(1);
1547 toDimacs(f, assumps);
1548 fclose(f);
1549}
1550
1551
1552void Solver::toDimacs(FILE* f, const vec<Lit>& assumps)
1553{
1554 // Handle case when solver is in contradictory state:
1555 if (!ok){
1556 fprintf(f, "p cnf 1 2\n1 0\n-1 0\n");
1557 return; }
1558
1559 vec<Var> map; Var max = 0;
1560
1561 // Cannot use removeClauses here because it is not safe
1562 // to deallocate them at this point. Could be improved.
1563 int i, cnt = 0;
1564 for (i = 0; i < clauses.size(); i++)
1565 if (!satisfied(ca[clauses[i]]))
1566 cnt++;
1567
1568 for (i = 0; i < clauses.size(); i++)
1569 if (!satisfied(ca[clauses[i]])){
1570 Clause& c = ca[clauses[i]];
1571 for (int j = 0; j < c.size(); j++)
1572 if (value(c[j]) != l_False)
1573 mapVar(var(c[j]), map, max);
1574 }
1575
1576 // Assumptions are added as unit clauses:
1577 cnt += assumptions.size();
1578
1579 fprintf(f, "p cnf %d %d\n", max, cnt);
1580
1581 for (i = 0; i < assumptions.size(); i++){
1583 fprintf(f, "%s%d 0\n", sign(assumptions[i]) ? "-" : "", mapVar(var(assumptions[i]), map, max)+1);
1584 }
1585
1586 for (i = 0; i < clauses.size(); i++)
1587 toDimacs(f, ca[clauses[i]], map, max);
1588
1589 if (verbosity > 0)
1590 printf("Wrote %d clauses with %d variables.\n", cnt, max);
1591}
1592
1593
1594//=================================================================================================
1595// Garbage Collection methods:
1596
1598{
1599 #ifdef CGLUCOSE_EXP
1600 if( CRef_Undef != itpc ){
1601 setItpcSize(3);
1602 ca.reloc(itpc, to);
1603 }
1604 #endif
1605 int v, s, i, j;
1606 // All watchers:
1607 //
1608 // for (int i = 0; i < watches.size(); i++)
1609 watches.cleanAll();
1610 watchesBin.cleanAll();
1611 for (v = 0; v < nVars(); v++)
1612 for (s = 0; s < 2; s++){
1613 Lit p = mkLit(v, s != 0);
1614 // printf(" >>> RELOCING: %s%d\n", sign(p)?"-":"", var(p)+1);
1615 vec<Watcher>& ws = watches[p];
1616 for (j = 0; j < ws.size(); j++)
1617 ca.reloc(ws[j].cref, to);
1618 vec<Watcher>& ws2 = watchesBin[p];
1619 for (j = 0; j < ws2.size(); j++)
1620 ca.reloc(ws2[j].cref, to);
1621 }
1622
1623 // All reasons:
1624 //
1625 for (i = 0; i < trail.size(); i++){
1626 Var v = var(trail[i]);
1627
1628 #ifdef CGLUCOSE_EXP
1629 if( isGateCRef(reason(v)) )
1630 continue;
1631 #endif
1632 if (reason(v) != CRef_Undef && (ca[reason(v)].reloced() || locked(ca[reason(v)])))
1633 ca.reloc(vardata[v].reason, to);
1634 }
1635
1636 // All learnt:
1637 //
1638 for (i = 0; i < learnts.size(); i++)
1639 ca.reloc(learnts[i], to);
1640
1641 // All original:
1642 //
1643 for (i = 0; i < clauses.size(); i++)
1644 ca.reloc(clauses[i], to);
1645}
1646
1647
1649{
1650 // Initialize the next region to a size corresponding to the estimated utilization degree. This
1651 // is not precise but should avoid some unnecessary reallocations for the new region:
1652 ClauseAllocator to(ca.size() - ca.wasted());
1653
1654 relocAll(to);
1655 if (verbosity >= 2)
1656 printf("| Garbage collection: %12d bytes => %12d bytes |\n",
1658 to.moveTo(ca);
1659}
1660
1662{
1663 // Reset everything
1664 ok = true;
1665 K = (double)opt_K;
1666 R = (double)opt_R;
1667 firstReduceDB = opt_first_reduce_db;
1668 var_decay = (double)opt_var_decay;
1669 //max_var_decay = opt_max_var_decay;
1671 curRestart = 1;
1672 cla_inc = var_inc = 1;
1673 watches.clear(false); // We don't free the memory, new calls should be of the same size order.
1674 watchesBin.clear(false);
1675 //unaryWatches.clear(false);
1676 qhead = 0;
1677 simpDB_assigns = -1;
1678 simpDB_props = 0;
1679 order_heap.clear(false);
1681 //lastLearntClause = CRef_Undef;
1682 conflict_budget = -1;
1683 propagation_budget = -1;
1685 totalTime4Sat = 0.;
1686 totalTime4Unsat = 0.;
1688 MYFLAG = 0;
1689 lbdQueue.clear(false);
1690 lbdQueue.initSize(sizeLBDQueue);
1691 trailQueue.clear(false);
1692 trailQueue.initSize(sizeTrailQueue);
1693 sumLBD = 0;
1695 //stats.clear();
1696 //stats.growTo(coreStatsSize, 0);
1697 clauses.clear(false);
1698 learnts.clear(false);
1699 //permanentLearnts.clear(false);
1700 //unaryWatchedClauses.clear(false);
1701 model .shrink_(model .size());
1702 conflict.shrink_(conflict.size());
1703 activity.shrink_(activity.size());
1704 assigns .shrink_(assigns .size());
1705 polarity.shrink_(polarity.size());
1706 //forceUNSAT.clear(false);
1707 decision .shrink_(decision .size());
1708 trail .shrink_(trail .size());
1709 trail_lim .shrink_(trail_lim .size());
1710 vardata .shrink_(vardata .size());
1711 assumptions.shrink_(assumptions.size());
1712 nbpos .shrink_(nbpos .size());
1713 permDiff .shrink_(permDiff .size());
1714 #ifdef UPDATEVARACTIVITY
1715 lastDecisionLevel.shrink_(lastDecisionLevel.size());
1716 #endif
1717 ca.clear();
1718 seen .shrink_(seen.size());
1719 analyze_stack .shrink_(analyze_stack .size());
1720 analyze_toclear.shrink_(analyze_toclear.size());
1721 add_tmp.clear(false);
1722 assumptionPositions.clear(false);
1723 initialPositions.clear(false);
1724
1725 #ifdef CGLUCOSE_EXP
1726
1727 ResetJustData(false);
1728
1729 //jwatch.shrink_(jwatch.size());
1730 //jdata .shrink_(jdata .size());
1731
1732 jhead = 0;
1733 travId = 0;
1734 travId_prev = 0;
1735 var2TravId .shrink_(var2TravId.size());
1736 JustModel .shrink_(JustModel .size());
1737 jlevel .shrink_(jlevel.size());
1738 jnext .shrink_(jnext.size());
1739
1740 //var2FaninLits.shrink_(var2FaninLits.size());
1741 var2NodeData .shrink_(var2NodeData .size());
1742 var2Fanout0 .shrink_(var2Fanout0 .size());
1743 var2FanoutN .shrink_(var2FanoutN .size());
1744 //var2FanoutP.clear(false);
1745 if( CRef_Undef != itpc ){
1746 itpc = CRef_Undef; // clause allocator has been cleared, do not worry
1747 // allocate space for clause interpretation
1748 vec<Lit> tmp; tmp.growTo(3);
1749 itpc = ca.alloc(tmp);
1750 ca[itpc].shrink( ca[itpc].size() );
1751 }
1752
1753 vMarked.shrink_( vMarked.size() );
1754 nSkipMark = 0;
1755 #endif
1756}
1757
#define CGLUCOSE_EXP
Definition CGlucose.h:4
unsigned int uint32_t
Definition Fxch.h:32
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define var_Undef
Definition SolverTypes.h:45
#define INT32_MAX
Definition pstdint.h:415
ABC_NAMESPACE_IMPL_START typedef signed char value
void moveTo(ClauseAllocator &to)
unsigned int sizeWithoutSelectors() const
unsigned learnt
void setCanBeDel(bool b)
void setLBD(int i)
uint32_t size() const
Definition Alloc.h:58
vec< int > initialPositions
Definition Solver.h:302
vec< double > activity
Definition Solver.h:237
OccLists< Lit, vec< Watcher >, WatcherDeleted > watchesBin
Definition Solver.h:242
void insertVarOrder(Var x)
Definition Solver.h:494
void varDecayActivity()
Definition Solver.h:502
Lit pickJustLit(int &index)
Lit pickBranchLit()
Definition Glucose2.cpp:565
int incReduceDB
Definition Solver.h:175
bool addClause_(vec< Lit > &ps)
Definition Glucose2.cpp:268
vec< int > nbpos
Definition Solver.h:250
unsigned int MYFLAG
Definition Solver.h:283
int64_t decisions
Definition Solver.h:200
bool withinBudget() const
Definition Solver.h:586
uint64_t nRuntimeLimit
Definition Solver.h:65
int64_t learnts_literals
Definition Solver.h:201
lbool search(int nof_conflicts)
void toDimacs(FILE *f, const vec< Lit > &assumps)
vec< Lit > JustModel
Definition Solver.h:481
void claDecayActivity()
Definition Solver.h:517
int64_t clauses_literals
Definition Solver.h:201
bool isGateCRef(CRef cr) const
Definition Solver.h:423
double var_inc
Definition Solver.h:238
double clause_decay
Definition Solver.h:184
vec< int > assumptionPositions
Definition Solver.h:302
vec< Lit > conflict
Definition Solver.h:159
int nbVarsInitialFormula
Definition Solver.h:299
vec< Lit > trail
Definition Solver.h:249
void cancelUntil(int level)
Definition Glucose2.cpp:515
static VarData mkVarData(CRef cr, int l)
Definition Solver.h:208
vec< unsigned int > permDiff
Definition Solver.h:260
uint32_t abstractLevel(Var x) const
Definition Solver.h:561
unsigned int computeLBD(const vec< Lit > &lits, int end=-1)
Definition Glucose2.cpp:411
bool litRedundant(Lit p, uint32_t abstract_levels)
Definition Glucose2.cpp:841
long curRestart
Definition Solver.h:204
Var getFaninVar1(Var v) const
Definition Solver.h:394
vec< Lit > var2FanoutN
Definition Solver.h:382
int justUsage() const
bool locked(const Clause &c) const
Definition Solver.h:537
vec< unsigned > var2TravId
Definition Solver.h:381
vec< char > polarity
Definition Solver.h:247
int nbclausesbeforereduce
Definition Solver.h:269
vec< VarData > vardata
Definition Solver.h:252
int64_t simpDB_props
Definition Solver.h:255
int64_t nbstopsrestarts
Definition Solver.h:200
unsigned int lbLBDFrozenClause
Definition Solver.h:177
vec< char > decision
Definition Solver.h:248
vec< Lit > analyze_stack
Definition Solver.h:280
double progress_estimate
Definition Solver.h:258
OccLists< Lit, vec< Watcher >, WatcherDeleted > watches
Definition Solver.h:240
virtual void garbageCollect()
double progressEstimate() const
void relocAll(ClauseAllocator &to)
ClauseAllocator ca
Definition Solver.h:267
unsigned travId_prev
Definition Solver.h:425
int64_t conflicts
Definition Solver.h:200
vec< Lit > add_tmp
Definition Solver.h:282
void ResetJustData(bool fCleanMemory)
void removeClause(CRef cr)
Definition Glucose2.cpp:377
int level(Var x) const
Definition Solver.h:492
bool asynch_interrupt
Definition Solver.h:294
int64_t dec_vars
Definition Solver.h:201
int64_t nbUn
Definition Solver.h:200
void setItpcSize(int sz)
int nVars() const
Definition Solver.h:569
virtual void reset()
int64_t lastblockatrestart
Definition Solver.h:200
void setDecisionVar(Var v, bool b, bool use_oheap=true)
Definition Solver.h:573
CRef getConfClause(CRef r)
vec< Lit > analyze_toclear
Definition Solver.h:281
void detachClause(CRef cr, bool strict=false)
Definition Glucose2.cpp:350
void rebuildOrderHeap()
int verbEveryConflicts
Definition Solver.h:165
vec< Var > vMarked
Definition Solver.h:460
int64_t conflictsRestarts
Definition Solver.h:200
int specialIncReduceDB
Definition Solver.h:176
float sumLBD
Definition Solver.h:272
vec< int > jlevel
Definition Solver.h:454
vec< CRef > clauses
Definition Solver.h:243
void minimisationWithBinaryResolution(vec< Lit > &out_learnt)
Definition Glucose2.cpp:473
int decisionLevel() const
Definition Solver.h:560
bool rnd_init_act
Definition Solver.h:190
double totalTime4Unsat
Definition Solver.h:300
bool certifiedUNSAT
Definition Solver.h:195
void attachClause(CRef cr)
Definition Glucose2.cpp:333
int firstReduceDB
Definition Solver.h:174
vec< int > jnext
Definition Solver.h:455
FILE * certifiedOutput
Definition Solver.h:194
int64_t starts
Definition Solver.h:200
unsigned travId
Definition Solver.h:425
static double drand(double &seed)
Definition Solver.h:358
int nClauses() const
Definition Solver.h:567
void removeSatisfied(vec< CRef > &cs)
void analyzeFinal(Lit p, vec< Lit > &out_conflict)
Definition Glucose2.cpp:888
Heap2< JustOrderLt2, JustKey > jheap
Definition Solver.h:453
int64_t tot_literals
Definition Solver.h:201
void checkGarbage()
Definition Solver.h:525
bqueue< unsigned int > trailQueue
Definition Solver.h:271
int64_t max_literals
Definition Solver.h:201
int phase_saving
Definition Solver.h:188
double random_seed
Definition Solver.h:186
bool remove_satisfied
Definition Solver.h:259
vec< lbool > assigns
Definition Solver.h:246
Var getFaninVar0(Var v) const
Definition Solver.h:393
int simpDB_assigns
Definition Solver.h:254
vec< lbool > model
Definition Solver.h:158
void varBumpActivity(Var v, double inc)
Definition Solver.h:504
void newDecisionLevel()
Definition Solver.h:558
double sizeLBDQueue
Definition Solver.h:170
int SolverType
Definition Solver.h:52
CRef castCRef(Lit p)
Heap< VarOrderLt > order_heap
Definition Solver.h:257
CRef reason(Var x) const
Definition Solver.h:491
static int irand(double &seed, int size)
Definition Solver.h:365
void * pCnfMan
Definition Solver.h:60
int64_t nbReduceDB
Definition Solver.h:200
int64_t nbDL2
Definition Solver.h:200
static NodeData mkNodeData()
Definition Solver.h:378
double cla_inc
Definition Solver.h:236
int incremental
Definition Solver.h:298
void initNbInitialVars(int nb)
Definition Glucose2.cpp:211
bqueue< unsigned int > lbdQueue
Definition Solver.h:271
bool terminate_search_early
Definition Solver.h:63
int64_t solves
Definition Solver.h:200
int nAssigns() const
Definition Solver.h:566
double var_decay
Definition Solver.h:183
virtual ~Solver()
Definition Glucose2.cpp:194
vec< Lit > var2Fanout0
Definition Solver.h:382
CRef gatePropagate(Lit p)
int * pstop
Definition Solver.h:64
void pushJustQueue(Var v, int index)
int(* pCnfFunc)(void *p, int, int *)
Definition Solver.h:61
int64_t conflict_budget
Definition Solver.h:292
int64_t nbstopsrestartssame
Definition Solver.h:200
Var newVar(bool polarity=true, bool dvar=true)
Definition Glucose2.cpp:223
int64_t propagation_budget
Definition Solver.h:293
int64_t nbReducedClauses
Definition Solver.h:200
vec< int > trail_lim
Definition Solver.h:251
double sizeTrailQueue
Definition Solver.h:171
vec< char > seen
Definition Solver.h:279
void claBumpActivity(Clause &c)
Definition Solver.h:518
unsigned int lbLBDMinimizingClause
Definition Solver.h:181
void printIncrementalStats()
int nbUnsatCalls
Definition Solver.h:301
bool isTwoFanin(Var v) const
void setIncrementalMode()
Definition Glucose2.cpp:206
bool isRoundWatch(Var v) const
Definition Solver.h:473
vec< Lit > assumptions
Definition Solver.h:256
int64_t propagations
Definition Solver.h:200
int nCallConfl
Definition Solver.h:62
int64_t nbBin
Definition Solver.h:200
int64_t rnd_decisions
Definition Solver.h:200
bool isSelector(Var v)
Definition Solver.h:352
int lbSizeMinimizingClause
Definition Solver.h:180
vec< CRef > learnts
Definition Solver.h:244
void analyze(CRef confl, vec< Lit > &out_learnt, vec< Lit > &selectors, int &out_btlevel, unsigned int &nblevels, unsigned int &szWithoutSelectors)
Definition Glucose2.cpp:604
double totalTime4Sat
Definition Solver.h:300
void uncheckedEnqueue(Lit p, CRef from=CRef_Undef)
Definition Glucose2.cpp:925
vec< NodeData > var2NodeData
Definition Solver.h:379
void updateJustActivity(Var v)
lbool value(Var x) const
Definition Solver.h:562
bool heap_rescale
Definition Solver.h:372
int64_t nbRemovedClauses
Definition Solver.h:200
double random_var_freq
Definition Solver.h:185
int nLearnts() const
Definition Solver.h:568
bool satisfied(const Clause &c) const
Definition Glucose2.cpp:396
double garbage_frac
Definition Solver.h:191
void shrink_(int nelems)
Definition Vec.h:67
void growTo(int size)
Definition Vec.h:126
void push(void)
Definition Vec.h:77
void copyTo_(vec< T > &copy) const
Definition Vec.h:95
void clear(bool dealloc=false)
Definition Vec.h:141
int size(void) const
Definition Vec.h:65
void map()
Cube * p
Definition exorList.c:222
#define LOWER_BOUND_FOR_BLOCKING_RESTART
Definition Constants.h:32
#define RATIOREMOVECLAUSES
Definition Constants.h:27
Definition Alg.h:28
Lit mkLit(Var var, bool sign=false)
Definition SolverTypes.h:69
bool sign(Lit p)
Definition SolverTypes.h:72
int var(Lit p)
Definition SolverTypes.h:73
const CRef CRef_Undef
void sort(T *array, int size, LessThan lt)
Definition Sort.h:58
StringOption opt_certified_file_(_certified, "certified-output", "Certified UNSAT output file", "NULL")
int Var
Definition SolverTypes.h:54
const Lit lit_Undef
Definition SolverTypes.h:83
RegionAllocator< uint32_t >::Ref CRef
BoolOption opt_certified_(_certified, "certified", "Certified UNSAT using DRUP format", false)
int toInt(Var v)
Definition SolverTypes.h:76
Lit toLit(int i)
Definition SolverTypes.h:78
#define true
Definition place_base.h:28
#define false
Definition place_base.h:29
signed char lbool
Definition satVec.h:135
Definition file.h:23
reduceDB_lt(ClauseAllocator &ca_)
ClauseAllocator & ca
Definition Solver.cpp:522
#define assert(ex)
Definition util_old.h:213
int strcmp()
VOID_HACK exit()
#define HUGE_VAL
Definition util_old.h:295