ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cecSolve.c
Go to the documentation of this file.
1
20
21#include "cecInt.h"
22
24
25
29
30static inline int Cec_ObjSatNum( Cec_ManSat_t * p, Gia_Obj_t * pObj ) { return p->pSatVars[Gia_ObjId(p->pAig,pObj)]; }
31static inline void Cec_ObjSetSatNum( Cec_ManSat_t * p, Gia_Obj_t * pObj, int Num ) { p->pSatVars[Gia_ObjId(p->pAig,pObj)] = Num; }
32
36
49{
50 return sat_solver_var_value( p->pSat, Cec_ObjSatNum(p, pObj) );
51}
52
65{
66 Gia_Obj_t * pNodeI, * pNodeT, * pNodeE;
67 int pLits[4], RetValue, VarF, VarI, VarT, VarE, fCompT, fCompE;
68
69 assert( !Gia_IsComplement( pNode ) );
70 assert( Gia_ObjIsMuxType( pNode ) );
71 // get nodes (I = if, T = then, E = else)
72 pNodeI = Gia_ObjRecognizeMux( pNode, &pNodeT, &pNodeE );
73 // get the variable numbers
74 VarF = Cec_ObjSatNum(p,pNode);
75 VarI = Cec_ObjSatNum(p,pNodeI);
76 VarT = Cec_ObjSatNum(p,Gia_Regular(pNodeT));
77 VarE = Cec_ObjSatNum(p,Gia_Regular(pNodeE));
78 // get the complementation flags
79 fCompT = Gia_IsComplement(pNodeT);
80 fCompE = Gia_IsComplement(pNodeE);
81
82 // f = ITE(i, t, e)
83
84 // i' + t' + f
85 // i' + t + f'
86 // i + e' + f
87 // i + e + f'
88
89 // create four clauses
90 pLits[0] = toLitCond(VarI, 1);
91 pLits[1] = toLitCond(VarT, 1^fCompT);
92 pLits[2] = toLitCond(VarF, 0);
93 if ( p->pPars->fPolarFlip )
94 {
95 if ( pNodeI->fPhase ) pLits[0] = lit_neg( pLits[0] );
96 if ( Gia_Regular(pNodeT)->fPhase ) pLits[1] = lit_neg( pLits[1] );
97 if ( pNode->fPhase ) pLits[2] = lit_neg( pLits[2] );
98 }
99 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 3 );
100 assert( RetValue );
101 pLits[0] = toLitCond(VarI, 1);
102 pLits[1] = toLitCond(VarT, 0^fCompT);
103 pLits[2] = toLitCond(VarF, 1);
104 if ( p->pPars->fPolarFlip )
105 {
106 if ( pNodeI->fPhase ) pLits[0] = lit_neg( pLits[0] );
107 if ( Gia_Regular(pNodeT)->fPhase ) pLits[1] = lit_neg( pLits[1] );
108 if ( pNode->fPhase ) pLits[2] = lit_neg( pLits[2] );
109 }
110 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 3 );
111 assert( RetValue );
112 pLits[0] = toLitCond(VarI, 0);
113 pLits[1] = toLitCond(VarE, 1^fCompE);
114 pLits[2] = toLitCond(VarF, 0);
115 if ( p->pPars->fPolarFlip )
116 {
117 if ( pNodeI->fPhase ) pLits[0] = lit_neg( pLits[0] );
118 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = lit_neg( pLits[1] );
119 if ( pNode->fPhase ) pLits[2] = lit_neg( pLits[2] );
120 }
121 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 3 );
122 assert( RetValue );
123 pLits[0] = toLitCond(VarI, 0);
124 pLits[1] = toLitCond(VarE, 0^fCompE);
125 pLits[2] = toLitCond(VarF, 1);
126 if ( p->pPars->fPolarFlip )
127 {
128 if ( pNodeI->fPhase ) pLits[0] = lit_neg( pLits[0] );
129 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = lit_neg( pLits[1] );
130 if ( pNode->fPhase ) pLits[2] = lit_neg( pLits[2] );
131 }
132 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 3 );
133 assert( RetValue );
134
135 // two additional clauses
136 // t' & e' -> f'
137 // t & e -> f
138
139 // t + e + f'
140 // t' + e' + f
141
142 if ( VarT == VarE )
143 {
144// assert( fCompT == !fCompE );
145 return;
146 }
147
148 pLits[0] = toLitCond(VarT, 0^fCompT);
149 pLits[1] = toLitCond(VarE, 0^fCompE);
150 pLits[2] = toLitCond(VarF, 1);
151 if ( p->pPars->fPolarFlip )
152 {
153 if ( Gia_Regular(pNodeT)->fPhase ) pLits[0] = lit_neg( pLits[0] );
154 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = lit_neg( pLits[1] );
155 if ( pNode->fPhase ) pLits[2] = lit_neg( pLits[2] );
156 }
157 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 3 );
158 assert( RetValue );
159 pLits[0] = toLitCond(VarT, 1^fCompT);
160 pLits[1] = toLitCond(VarE, 1^fCompE);
161 pLits[2] = toLitCond(VarF, 0);
162 if ( p->pPars->fPolarFlip )
163 {
164 if ( Gia_Regular(pNodeT)->fPhase ) pLits[0] = lit_neg( pLits[0] );
165 if ( Gia_Regular(pNodeE)->fPhase ) pLits[1] = lit_neg( pLits[1] );
166 if ( pNode->fPhase ) pLits[2] = lit_neg( pLits[2] );
167 }
168 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 3 );
169 assert( RetValue );
170}
171
184{
185 Gia_Obj_t * pFanin;
186 int * pLits, nLits, RetValue, i;
187 assert( !Gia_IsComplement(pNode) );
188 assert( Gia_ObjIsAnd( pNode ) );
189 // create storage for literals
190 nLits = Vec_PtrSize(vSuper) + 1;
191 pLits = ABC_ALLOC( int, nLits );
192 // suppose AND-gate is A & B = C
193 // add !A => !C or A + !C
194 Vec_PtrForEachEntry( Gia_Obj_t *, vSuper, pFanin, i )
195 {
196 pLits[0] = toLitCond(Cec_ObjSatNum(p,Gia_Regular(pFanin)), Gia_IsComplement(pFanin));
197 pLits[1] = toLitCond(Cec_ObjSatNum(p,pNode), 1);
198 if ( p->pPars->fPolarFlip )
199 {
200 if ( Gia_Regular(pFanin)->fPhase ) pLits[0] = lit_neg( pLits[0] );
201 if ( pNode->fPhase ) pLits[1] = lit_neg( pLits[1] );
202 }
203 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 2 );
204 assert( RetValue );
205 }
206 // add A & B => C or !A + !B + C
207 Vec_PtrForEachEntry( Gia_Obj_t *, vSuper, pFanin, i )
208 {
209 pLits[i] = toLitCond(Cec_ObjSatNum(p,Gia_Regular(pFanin)), !Gia_IsComplement(pFanin));
210 if ( p->pPars->fPolarFlip )
211 {
212 if ( Gia_Regular(pFanin)->fPhase ) pLits[i] = lit_neg( pLits[i] );
213 }
214 }
215 pLits[nLits-1] = toLitCond(Cec_ObjSatNum(p,pNode), 0);
216 if ( p->pPars->fPolarFlip )
217 {
218 if ( pNode->fPhase ) pLits[nLits-1] = lit_neg( pLits[nLits-1] );
219 }
220 RetValue = sat_solver_addclause( p->pSat, pLits, pLits + nLits );
221 assert( RetValue );
222 ABC_FREE( pLits );
223}
224
236void Cec_CollectSuper_rec( Gia_Obj_t * pObj, Vec_Ptr_t * vSuper, int fFirst, int fUseMuxes )
237{
238 // if the new node is complemented or a PI, another gate begins
239 if ( Gia_IsComplement(pObj) || Gia_ObjIsCi(pObj) ||
240 (!fFirst && Gia_ObjValue(pObj) > 1) ||
241 (fUseMuxes && Gia_ObjIsMuxType(pObj)) )
242 {
243 Vec_PtrPushUnique( vSuper, pObj );
244 return;
245 }
246 // go through the branches
247 Cec_CollectSuper_rec( Gia_ObjChild0(pObj), vSuper, 0, fUseMuxes );
248 Cec_CollectSuper_rec( Gia_ObjChild1(pObj), vSuper, 0, fUseMuxes );
249}
250
262void Cec_CollectSuper( Gia_Obj_t * pObj, int fUseMuxes, Vec_Ptr_t * vSuper )
263{
264 assert( !Gia_IsComplement(pObj) );
265 assert( !Gia_ObjIsCi(pObj) );
266 Vec_PtrClear( vSuper );
267 Cec_CollectSuper_rec( pObj, vSuper, 1, fUseMuxes );
268}
269
282{
283 assert( !Gia_IsComplement(pObj) );
284 if ( Cec_ObjSatNum(p,pObj) )
285 return;
286 assert( Cec_ObjSatNum(p,pObj) == 0 );
287 if ( Gia_ObjIsConst0(pObj) )
288 return;
289 Vec_PtrPush( p->vUsedNodes, pObj );
290 Cec_ObjSetSatNum( p, pObj, p->nSatVars++ );
291 if ( Gia_ObjIsAnd(pObj) )
292 Vec_PtrPush( vFrontier, pObj );
293}
294
307{
308 Vec_Ptr_t * vFrontier;
309 Gia_Obj_t * pNode, * pFanin;
310 int i, k, fUseMuxes = 1;
311 // quit if CNF is ready
312 if ( Cec_ObjSatNum(p,pObj) )
313 return;
314 if ( Gia_ObjIsCi(pObj) )
315 {
316 Vec_PtrPush( p->vUsedNodes, pObj );
317 Cec_ObjSetSatNum( p, pObj, p->nSatVars++ );
318 sat_solver_setnvars( p->pSat, p->nSatVars );
319 return;
320 }
321 assert( Gia_ObjIsAnd(pObj) );
322 // start the frontier
323 vFrontier = Vec_PtrAlloc( 100 );
324 Cec_ObjAddToFrontier( p, pObj, vFrontier );
325 // explore nodes in the frontier
326 Vec_PtrForEachEntry( Gia_Obj_t *, vFrontier, pNode, i )
327 {
328 // create the supergate
329 assert( Cec_ObjSatNum(p,pNode) );
330 if ( fUseMuxes && Gia_ObjIsMuxType(pNode) )
331 {
332 Vec_PtrClear( p->vFanins );
333 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin0( Gia_ObjFanin0(pNode) ) );
334 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin0( Gia_ObjFanin1(pNode) ) );
335 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin1( Gia_ObjFanin0(pNode) ) );
336 Vec_PtrPushUnique( p->vFanins, Gia_ObjFanin1( Gia_ObjFanin1(pNode) ) );
337 Vec_PtrForEachEntry( Gia_Obj_t *, p->vFanins, pFanin, k )
338 Cec_ObjAddToFrontier( p, Gia_Regular(pFanin), vFrontier );
339 Cec_AddClausesMux( p, pNode );
340 }
341 else
342 {
343 Cec_CollectSuper( pNode, fUseMuxes, p->vFanins );
344 Vec_PtrForEachEntry( Gia_Obj_t *, p->vFanins, pFanin, k )
345 Cec_ObjAddToFrontier( p, Gia_Regular(pFanin), vFrontier );
346 Cec_AddClausesSuper( p, pNode, p->vFanins );
347 }
348 assert( Vec_PtrSize(p->vFanins) > 1 );
349 }
350 Vec_PtrFree( vFrontier );
351}
352
353
366{
367 int Lit;
368 if ( p->pSat )
369 {
370 Gia_Obj_t * pObj;
371 int i;
372 Vec_PtrForEachEntry( Gia_Obj_t *, p->vUsedNodes, pObj, i )
373 Cec_ObjSetSatNum( p, pObj, 0 );
374 Vec_PtrClear( p->vUsedNodes );
375// memset( p->pSatVars, 0, sizeof(int) * Gia_ManObjNumMax(p->pAigTotal) );
376 sat_solver_delete( p->pSat );
377 }
378 p->pSat = sat_solver_new();
379 sat_solver_setnvars( p->pSat, 1000 );
380 p->pSat->factors = ABC_CALLOC( double, p->pSat->cap );
381 // var 0 is not used
382 // var 1 is reserved for const0 node - add the clause
383 p->nSatVars = 1;
384// p->nSatVars = 0;
385 Lit = toLitCond( p->nSatVars, 1 );
386// if ( p->pPars->fPolarFlip ) // no need to normalize const0 node (bug fix by SS on 9/17/2012)
387// Lit = lit_neg( Lit );
388 sat_solver_addclause( p->pSat, &Lit, &Lit + 1 );
389 Cec_ObjSetSatNum( p, Gia_ManConst0(p->pAig), p->nSatVars++ );
390
391 p->nRecycles++;
392 p->nCallsSince = 0;
393}
394
406void Cec_SetActivityFactors_rec( Cec_ManSat_t * p, Gia_Obj_t * pObj, int LevelMin, int LevelMax )
407{
408 float dActConeBumpMax = 20.0;
409 int iVar;
410 // skip visited variables
411 if ( Gia_ObjIsTravIdCurrent(p->pAig, pObj) )
412 return;
413 Gia_ObjSetTravIdCurrent(p->pAig, pObj);
414 // add the PI to the list
415 if ( Gia_ObjLevel(p->pAig, pObj) <= LevelMin || Gia_ObjIsCi(pObj) )
416 return;
417 // set the factor of this variable
418 // (LevelMax-LevelMin) / (pObj->Level-LevelMin) = p->pPars->dActConeBumpMax / ThisBump
419 if ( (iVar = Cec_ObjSatNum(p,pObj)) )
420 {
421 p->pSat->factors[iVar] = dActConeBumpMax * (Gia_ObjLevel(p->pAig, pObj) - LevelMin)/(LevelMax - LevelMin);
422 veci_push(&p->pSat->act_vars, iVar);
423 }
424 // explore the fanins
425 Cec_SetActivityFactors_rec( p, Gia_ObjFanin0(pObj), LevelMin, LevelMax );
426 Cec_SetActivityFactors_rec( p, Gia_ObjFanin1(pObj), LevelMin, LevelMax );
427}
428
441{
442 float dActConeRatio = 0.5;
443 int LevelMin, LevelMax;
444 // reset the active variables
445 veci_resize(&p->pSat->act_vars, 0);
446 // prepare for traversal
447 Gia_ManIncrementTravId( p->pAig );
448 // determine the min and max level to visit
449 assert( dActConeRatio > 0 && dActConeRatio < 1 );
450 LevelMax = Gia_ObjLevel(p->pAig,pObj);
451 LevelMin = (int)(LevelMax * (1.0 - dActConeRatio));
452 // traverse
453 Cec_SetActivityFactors_rec( p, pObj, LevelMin, LevelMax );
454//Cec_PrintActivity( p );
455 return 1;
456}
457
458
471{
472 Gia_Obj_t * pObjR = Gia_Regular(pObj);
473 int nBTLimit = p->pPars->nBTLimit;
474 int Lit, RetValue, status, nConflicts;
475 abctime clk, clk2;
476
477 if ( pObj == Gia_ManConst0(p->pAig) )
478 return 1;
479 if ( pObj == Gia_ManConst1(p->pAig) )
480 {
481 assert( 0 );
482 return 0;
483 }
484
485 p->nCallsSince++; // experiment with this!!!
486 p->nSatTotal++;
487
488 // check if SAT solver needs recycling
489 if ( p->pSat == NULL ||
490 (p->pPars->nSatVarMax &&
491 p->nSatVars > p->pPars->nSatVarMax &&
492 p->nCallsSince > p->pPars->nCallsRecycle) )
494
495 // if the nodes do not have SAT variables, allocate them
496clk2 = Abc_Clock();
497 Cec_CnfNodeAddToSolver( p, pObjR );
498//ABC_PRT( "cnf", Abc_Clock() - clk2 );
499//Abc_Print( 1, "%d \n", p->pSat->size );
500
501clk2 = Abc_Clock();
502// Cec_SetActivityFactors( p, pObjR );
503//ABC_PRT( "act", Abc_Clock() - clk2 );
504
505 // propage unit clauses
506 if ( p->pSat->qtail != p->pSat->qhead )
507 {
508 status = sat_solver_simplify(p->pSat);
509 assert( status != 0 );
510 assert( p->pSat->qtail == p->pSat->qhead );
511 }
512
513 // solve under assumptions
514 // A = 1; B = 0 OR A = 1; B = 1
515 Lit = toLitCond( Cec_ObjSatNum(p,pObjR), Gia_IsComplement(pObj) );
516 if ( p->pPars->fPolarFlip )
517 {
518 if ( pObjR->fPhase ) Lit = lit_neg( Lit );
519 }
520//Sat_SolverWriteDimacs( p->pSat, "temp.cnf", pLits, pLits + 2, 1 );
521clk = Abc_Clock();
522 nConflicts = p->pSat->stats.conflicts;
523
524clk2 = Abc_Clock();
525 RetValue = sat_solver_solve( p->pSat, &Lit, &Lit + 1,
526 (ABC_INT64_T)nBTLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
527//ABC_PRT( "sat", Abc_Clock() - clk2 );
528
529 if ( RetValue == l_False )
530 {
531p->timeSatUnsat += Abc_Clock() - clk;
532 Lit = lit_neg( Lit );
533 RetValue = sat_solver_addclause( p->pSat, &Lit, &Lit + 1 );
534 assert( RetValue );
535 p->nSatUnsat++;
536 p->nConfUnsat += p->pSat->stats.conflicts - nConflicts;
537//Abc_Print( 1, "UNSAT after %d conflicts\n", p->pSat->stats.conflicts - nConflicts );
538 return 1;
539 }
540 else if ( RetValue == l_True )
541 {
542p->timeSatSat += Abc_Clock() - clk;
543 p->nSatSat++;
544 p->nConfSat += p->pSat->stats.conflicts - nConflicts;
545//Abc_Print( 1, "SAT after %d conflicts\n", p->pSat->stats.conflicts - nConflicts );
546 return 0;
547 }
548 else // if ( RetValue == l_Undef )
549 {
550p->timeSatUndec += Abc_Clock() - clk;
551 p->nSatUndec++;
552 p->nConfUndec += p->pSat->stats.conflicts - nConflicts;
553//Abc_Print( 1, "UNDEC after %d conflicts\n", p->pSat->stats.conflicts - nConflicts );
554 return -1;
555 }
556}
557
570{
571 Gia_Obj_t * pObjR1 = Gia_Regular(pObj1);
572 Gia_Obj_t * pObjR2 = Gia_Regular(pObj2);
573 int nBTLimit = p->pPars->nBTLimit;
574 int Lits[2], RetValue, status, nConflicts;
575 abctime clk, clk2;
576
577 if ( pObj1 == Gia_ManConst0(p->pAig) || pObj2 == Gia_ManConst0(p->pAig) || pObj1 == Gia_Not(pObj2) )
578 return 1;
579 if ( pObj1 == Gia_ManConst1(p->pAig) && (pObj2 == NULL || pObj2 == Gia_ManConst1(p->pAig)) )
580 {
581 assert( 0 );
582 return 0;
583 }
584
585 p->nCallsSince++; // experiment with this!!!
586 p->nSatTotal++;
587
588 // check if SAT solver needs recycling
589 if ( p->pSat == NULL ||
590 (p->pPars->nSatVarMax &&
591 p->nSatVars > p->pPars->nSatVarMax &&
592 p->nCallsSince > p->pPars->nCallsRecycle) )
594
595 // if the nodes do not have SAT variables, allocate them
596clk2 = Abc_Clock();
597 Cec_CnfNodeAddToSolver( p, pObjR1 );
598 Cec_CnfNodeAddToSolver( p, pObjR2 );
599//ABC_PRT( "cnf", Abc_Clock() - clk2 );
600//Abc_Print( 1, "%d \n", p->pSat->size );
601
602clk2 = Abc_Clock();
603// Cec_SetActivityFactors( p, pObjR1 );
604// Cec_SetActivityFactors( p, pObjR2 );
605//ABC_PRT( "act", Abc_Clock() - clk2 );
606
607 // propage unit clauses
608 if ( p->pSat->qtail != p->pSat->qhead )
609 {
610 status = sat_solver_simplify(p->pSat);
611 assert( status != 0 );
612 assert( p->pSat->qtail == p->pSat->qhead );
613 }
614
615 // solve under assumptions
616 // A = 1; B = 0 OR A = 1; B = 1
617 Lits[0] = toLitCond( Cec_ObjSatNum(p,pObjR1), Gia_IsComplement(pObj1) );
618 Lits[1] = toLitCond( Cec_ObjSatNum(p,pObjR2), Gia_IsComplement(pObj2) );
619 if ( p->pPars->fPolarFlip )
620 {
621 if ( pObjR1->fPhase ) Lits[0] = lit_neg( Lits[0] );
622 if ( pObjR2->fPhase ) Lits[1] = lit_neg( Lits[1] );
623 }
624//Sat_SolverWriteDimacs( p->pSat, "temp.cnf", pLits, pLits + 2, 1 );
625clk = Abc_Clock();
626 nConflicts = p->pSat->stats.conflicts;
627
628clk2 = Abc_Clock();
629 RetValue = sat_solver_solve( p->pSat, Lits, Lits + 2,
630 (ABC_INT64_T)nBTLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
631//ABC_PRT( "sat", Abc_Clock() - clk2 );
632
633 if ( RetValue == l_False )
634 {
635p->timeSatUnsat += Abc_Clock() - clk;
636 Lits[0] = lit_neg( Lits[0] );
637 Lits[1] = lit_neg( Lits[1] );
638 RetValue = sat_solver_addclause( p->pSat, Lits, Lits + 2 );
639 assert( RetValue );
640 p->nSatUnsat++;
641 p->nConfUnsat += p->pSat->stats.conflicts - nConflicts;
642//Abc_Print( 1, "UNSAT after %d conflicts\n", p->pSat->stats.conflicts - nConflicts );
643 return 1;
644 }
645 else if ( RetValue == l_True )
646 {
647p->timeSatSat += Abc_Clock() - clk;
648 p->nSatSat++;
649 p->nConfSat += p->pSat->stats.conflicts - nConflicts;
650//Abc_Print( 1, "SAT after %d conflicts\n", p->pSat->stats.conflicts - nConflicts );
651 return 0;
652 }
653 else // if ( RetValue == l_Undef )
654 {
655p->timeSatUndec += Abc_Clock() - clk;
656 p->nSatUndec++;
657 p->nConfUndec += p->pSat->stats.conflicts - nConflicts;
658//Abc_Print( 1, "UNDEC after %d conflicts\n", p->pSat->stats.conflicts - nConflicts );
659 return -1;
660 }
661}
662
663
677{
678 Abc_Cex_t * pCex;
679 pCex = Abc_CexAlloc( 0, Gia_ManCiNum(p->pAig), 1 );
680 pCex->iPo = iOut;
681 pCex->iFrame = 0;
682 return pCex;
683}
685{
686 Abc_Cex_t * pCex;
687 int i;
688 pCex = Abc_CexAlloc( 0, Gia_ManCiNum(p->pAig), 1 );
689 pCex->iPo = iOut;
690 pCex->iFrame = 0;
691 for ( i = 0; i < Gia_ManCiNum(p->pAig); i++ )
692 {
693 int iVar = Cec_ObjSatNum(p, Gia_ManCi(p->pAig, i));
694 if ( iVar > 0 && sat_solver_var_value(p->pSat, iVar) )
695 pCex->pData[i>>5] |= (1<<(i & 31));
696 }
697 return pCex;
698}
699void Cec_ManSatSolve( Cec_ManPat_t * pPat, Gia_Man_t * pAig, Cec_ParSat_t * pPars, Vec_Int_t * vIdsOrig, Vec_Int_t * vMiterPairs, Vec_Int_t * vEquivPairs, int f0Proved )
700{
701 Bar_Progress_t * pProgress = NULL;
702 Cec_ManSat_t * p;
703 Gia_Obj_t * pObj;
704 int i, status;
705 abctime clk = Abc_Clock(), clk2;
706 Vec_PtrFreeP( &pAig->vSeqModelVec );
707 if ( pPars->fSaveCexes )
708 pAig->vSeqModelVec = Vec_PtrStart( Gia_ManCoNum(pAig) );
709 // reset the manager
710 if ( pPat )
711 {
712 pPat->iStart = Vec_StrSize(pPat->vStorage);
713 pPat->nPats = 0;
714 pPat->nPatLits = 0;
715 pPat->nPatLitsMin = 0;
716 }
717 Gia_ManSetPhase( pAig );
718 Gia_ManLevelNum( pAig );
720 p = Cec_ManSatCreate( pAig, pPars );
721 pProgress = Bar_ProgressStart( stdout, Gia_ManPoNum(pAig) );
722 Gia_ManForEachCo( pAig, pObj, i )
723 {
724 if ( Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
725 {
726 status = !Gia_ObjFaninC0(pObj);
727 pObj->fMark0 = (status == 0);
728 pObj->fMark1 = (status == 1);
729 if ( pPars->fSaveCexes )
730 Vec_PtrWriteEntry( pAig->vSeqModelVec, i, status ? (Abc_Cex_t *)(ABC_PTRINT_T)1 : Cex_ManGenSimple(p, i) );
731 continue;
732 }
733 Bar_ProgressUpdate( pProgress, i, "SAT..." );
734clk2 = Abc_Clock();
735 status = Cec_ManSatCheckNode( p, Gia_ObjChild0(pObj) );
736 pObj->fMark0 = (status == 0);
737 pObj->fMark1 = (status == 1);
738 if ( status == 1 && vIdsOrig )
739 {
740 int iObj1 = Vec_IntEntry(vMiterPairs, 2*i);
741 int iObj2 = Vec_IntEntry(vMiterPairs, 2*i+1);
742 int OrigId1 = Vec_IntEntry(vIdsOrig, iObj1);
743 int OrigId2 = Vec_IntEntry(vIdsOrig, iObj2);
744 assert( OrigId1 >= 0 && OrigId2 >= 0 );
745 Vec_IntPushTwo( vEquivPairs, OrigId1, OrigId2 );
746 }
747 if ( pPars->fSaveCexes && status != -1 )
748 Vec_PtrWriteEntry( pAig->vSeqModelVec, i, status ? (Abc_Cex_t *)(ABC_PTRINT_T)1 : Cex_ManGenCex(p, i) );
749
750 if ( f0Proved && status == 1 )
751 Gia_ManPatchCoDriver( pAig, i, 0 );
752
753/*
754 if ( status == -1 )
755 {
756 Gia_Man_t * pTemp = Gia_ManDupDfsCone( pAig, pObj );
757 Gia_AigerWrite( pTemp, "gia_hard.aig", 0, 0, 0 );
758 Gia_ManStop( pTemp );
759 Abc_Print( 1, "Dumping hard cone into file \"%s\".\n", "gia_hard.aig" );
760 }
761*/
762 if ( status != 0 )
763 continue;
764 // save the pattern
765 if ( pPat )
766 {
767 abctime clk3 = Abc_Clock();
768 Cec_ManPatSavePattern( pPat, p, pObj );
769 pPat->timeTotalSave += Abc_Clock() - clk3;
770 }
771 // quit if one of them is solved
772 if ( pPars->fCheckMiter )
773 break;
774 }
775 p->timeTotal = Abc_Clock() - clk;
776 Bar_ProgressStop( pProgress );
777 if ( pPars->fVerbose )
779 Cec_ManSatStop( p );
780}
781
794int Cec_ManSatSolveExractPattern( Vec_Int_t * vCexStore, int iStart, Vec_Int_t * vPat )
795{
796 int k, nSize;
797 Vec_IntClear( vPat );
798 // skip the output number
799 iStart++;
800 // get the number of items
801 nSize = Vec_IntEntry( vCexStore, iStart++ );
802 if ( nSize <= 0 )
803 return iStart;
804 // extract pattern
805 for ( k = 0; k < nSize; k++ )
806 Vec_IntPush( vPat, Vec_IntEntry( vCexStore, iStart++ ) );
807 return iStart;
808}
810{
811 Vec_Str_t * vStatus;
812 Vec_Int_t * vPat = Vec_IntAlloc( 1000 );
813 Vec_Int_t * vCexStore = Cbs_ManSolveMiterNc( pAig, pPars->nBTLimit, &vStatus, 0, 0 );
814 Gia_Obj_t * pObj;
815 int i, status, iStart = 0;
816 assert( Vec_StrSize(vStatus) == Gia_ManCoNum(pAig) );
817 // reset the manager
818 if ( pPat )
819 {
820 pPat->iStart = Vec_StrSize(pPat->vStorage);
821 pPat->nPats = 0;
822 pPat->nPatLits = 0;
823 pPat->nPatLitsMin = 0;
824 }
825 Gia_ManForEachCo( pAig, pObj, i )
826 {
827 status = (int)Vec_StrEntry(vStatus, i);
828 pObj->fMark0 = (status == 0);
829 pObj->fMark1 = (status == 1);
830 if ( Vec_IntSize(vCexStore) > 0 && status != 1 )
831 iStart = Cec_ManSatSolveExractPattern( vCexStore, iStart, vPat );
832 if ( status != 0 )
833 continue;
834 // save the pattern
835 if ( pPat && Vec_IntSize(vPat) > 0 )
836 {
837 abctime clk3 = Abc_Clock();
838 Cec_ManPatSavePatternCSat( pPat, vPat );
839 pPat->timeTotalSave += Abc_Clock() - clk3;
840 }
841 // quit if one of them is solved
842 if ( pPars->fCheckMiter )
843 break;
844 }
845 assert( iStart == Vec_IntSize(vCexStore) );
846 Vec_IntFree( vPat );
847 Vec_StrFree( vStatus );
848 Vec_IntFree( vCexStore );
849}
850
851
852
865{
866 return pSat->vCex;
867}
868
880void Cec_ManSatSolveSeq_rec( Cec_ManSat_t * pSat, Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Ptr_t * vInfo, int iPat, int nRegs )
881{
882 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
883 return;
884 Gia_ObjSetTravIdCurrent(p, pObj);
885 if ( Gia_ObjIsCi(pObj) )
886 {
887 unsigned * pInfo = (unsigned *)Vec_PtrEntry( vInfo, nRegs + Gia_ObjCioId(pObj) );
888 if ( Cec_ObjSatVarValue( pSat, pObj ) != Abc_InfoHasBit( pInfo, iPat ) )
889 Abc_InfoXorBit( pInfo, iPat );
890 pSat->nCexLits++;
891// Vec_IntPush( pSat->vCex, Abc_Var2Lit( Gia_ObjCioId(pObj), !Cec_ObjSatVarValue(pSat, pObj) ) );
892 return;
893 }
894 assert( Gia_ObjIsAnd(pObj) );
895 Cec_ManSatSolveSeq_rec( pSat, p, Gia_ObjFanin0(pObj), vInfo, iPat, nRegs );
896 Cec_ManSatSolveSeq_rec( pSat, p, Gia_ObjFanin1(pObj), vInfo, iPat, nRegs );
897}
898
911Vec_Str_t * Cec_ManSatSolveSeq( Vec_Ptr_t * vPatts, Gia_Man_t * pAig, Cec_ParSat_t * pPars, int nRegs, int * pnPats )
912{
913 Bar_Progress_t * pProgress = NULL;
914 Vec_Str_t * vStatus;
915 Cec_ManSat_t * p;
916 Gia_Obj_t * pObj;
917 int iPat = 0, nPatsInit, nPats;
918 int i, status;
919 abctime clk = Abc_Clock();
920 nPatsInit = nPats = 32 * Vec_PtrReadWordsSimInfo(vPatts);
921 Gia_ManSetPhase( pAig );
922 Gia_ManLevelNum( pAig );
924 p = Cec_ManSatCreate( pAig, pPars );
925 vStatus = Vec_StrAlloc( Gia_ManPoNum(pAig) );
926 pProgress = Bar_ProgressStart( stdout, Gia_ManPoNum(pAig) );
927 Gia_ManForEachCo( pAig, pObj, i )
928 {
929 Bar_ProgressUpdate( pProgress, i, "SAT..." );
930 if ( Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
931 {
932 if ( Gia_ObjFaninC0(pObj) )
933 {
934// Abc_Print( 1, "Constant 1 output of SRM!!!\n" );
935 Vec_StrPush( vStatus, 0 );
936 }
937 else
938 {
939// Abc_Print( 1, "Constant 0 output of SRM!!!\n" );
940 Vec_StrPush( vStatus, 1 );
941 }
942 continue;
943 }
944 status = Cec_ManSatCheckNode( p, Gia_ObjChild0(pObj) );
945//Abc_Print( 1, "output %d status = %d\n", i, status );
946 Vec_StrPush( vStatus, (char)status );
947 if ( status != 0 )
948 continue;
949 // resize storage
950 if ( iPat == nPats )
951 {
952 int nWords = Vec_PtrReadWordsSimInfo(vPatts);
953 Vec_PtrReallocSimInfo( vPatts );
954 Vec_PtrCleanSimInfo( vPatts, nWords, 2*nWords );
955 nPats = 32 * Vec_PtrReadWordsSimInfo(vPatts);
956 }
957 if ( iPat % nPatsInit == 0 )
958 iPat++;
959 // save the pattern
961// Vec_IntClear( p->vCex );
962 Cec_ManSatSolveSeq_rec( p, pAig, Gia_ObjFanin0(pObj), vPatts, iPat++, nRegs );
963// Gia_SatVerifyPattern( pAig, pObj, p->vCex, p->vVisits );
964// Cec_ManSatAddToStore( p->vCexStore, p->vCex );
965// if ( iPat == nPats )
966// break;
967 // quit if one of them is solved
968// if ( pPars->fFirstStop )
969// break;
970// if ( iPat == 32 * 15 * 16 - 1 )
971// break;
972 }
973 p->timeTotal = Abc_Clock() - clk;
974 Bar_ProgressStop( pProgress );
975 if ( pPars->fVerbose )
977// Abc_Print( 1, "Total number of cex literals = %d. (Ave = %d)\n", p->nCexLits, p->nCexLits/p->nSatSat );
978 Cec_ManSatStop( p );
979 if ( pnPats )
980 *pnPats = iPat-1;
981 return vStatus;
982}
983
984
996void Cec_ManSatAddToStore( Vec_Int_t * vCexStore, Vec_Int_t * vCex, int Out )
997{
998 int i, Entry;
999 Vec_IntPush( vCexStore, Out );
1000 if ( vCex == NULL ) // timeout
1001 {
1002 Vec_IntPush( vCexStore, -1 );
1003 return;
1004 }
1005 // write the counter-example
1006 Vec_IntPush( vCexStore, Vec_IntSize(vCex) );
1007 Vec_IntForEachEntry( vCex, Entry, i )
1008 Vec_IntPush( vCexStore, Entry );
1009}
1010
1023{
1024 if ( Gia_ObjIsTravIdCurrent(p, pObj) )
1025 return;
1026 Gia_ObjSetTravIdCurrent(p, pObj);
1027 if ( Gia_ObjIsCi(pObj) )
1028 {
1029 pSat->nCexLits++;
1030 Vec_IntPush( pSat->vCex, Abc_Var2Lit( Gia_ObjCioId(pObj), !Cec_ObjSatVarValue(pSat, pObj) ) );
1031 return;
1032 }
1033 assert( Gia_ObjIsAnd(pObj) );
1034 Cec_ManSatSolveMiter_rec( pSat, p, Gia_ObjFanin0(pObj) );
1035 Cec_ManSatSolveMiter_rec( pSat, p, Gia_ObjFanin1(pObj) );
1036}
1037
1050{
1051 Vec_IntClear( p->vCex );
1052 Gia_ManIncrementTravId( p->pAig );
1053 Cec_ManSatSolveMiter_rec( p, p->pAig, Gia_Regular(pObj1) );
1054 if ( pObj2 )
1055 Cec_ManSatSolveMiter_rec( p, p->pAig, Gia_Regular(pObj2) );
1056}
1057
1071{
1072 Bar_Progress_t * pProgress = NULL;
1073 Vec_Int_t * vCexStore;
1074 Vec_Str_t * vStatus;
1075 Cec_ManSat_t * p;
1076 Gia_Obj_t * pObj;
1077 int i, status;
1078 abctime clk = Abc_Clock();
1079 // prepare AIG
1080 Gia_ManSetPhase( pAig );
1081 Gia_ManLevelNum( pAig );
1082 Gia_ManIncrementTravId( pAig );
1083 // create resulting data-structures
1084 vStatus = Vec_StrAlloc( Gia_ManPoNum(pAig) );
1085 vCexStore = Vec_IntAlloc( 10000 );
1086 // perform solving
1087 p = Cec_ManSatCreate( pAig, pPars );
1088 pProgress = Bar_ProgressStart( stdout, Gia_ManPoNum(pAig) );
1089 Gia_ManForEachCo( pAig, pObj, i )
1090 {
1091 Vec_IntClear( p->vCex );
1092 Bar_ProgressUpdate( pProgress, i, "SAT..." );
1093 if ( Gia_ObjIsConst0(Gia_ObjFanin0(pObj)) )
1094 {
1095 if ( Gia_ObjFaninC0(pObj) )
1096 {
1097// Abc_Print( 1, "Constant 1 output of SRM!!!\n" );
1098 Cec_ManSatAddToStore( vCexStore, p->vCex, i ); // trivial counter-example
1099 Vec_StrPush( vStatus, 0 );
1100 }
1101 else
1102 {
1103// Abc_Print( 1, "Constant 0 output of SRM!!!\n" );
1104 Vec_StrPush( vStatus, 1 );
1105 }
1106 continue;
1107 }
1108 status = Cec_ManSatCheckNode( p, Gia_ObjChild0(pObj) );
1109 Vec_StrPush( vStatus, (char)status );
1110 if ( status == -1 )
1111 {
1112 Cec_ManSatAddToStore( vCexStore, NULL, i ); // timeout
1113 continue;
1114 }
1115 if ( status == 1 )
1116 continue;
1117 assert( status == 0 );
1118 // save the pattern
1119// Gia_ManIncrementTravId( pAig );
1120// Cec_ManSatSolveMiter_rec( p, pAig, Gia_ObjFanin0(pObj) );
1121 Cec_ManSavePattern( p, Gia_ObjFanin0(pObj), NULL );
1122// Gia_SatVerifyPattern( pAig, pObj, p->vCex, p->vVisits );
1123 Cec_ManSatAddToStore( vCexStore, p->vCex, i );
1124 }
1125 p->timeTotal = Abc_Clock() - clk;
1126 Bar_ProgressStop( pProgress );
1127// if ( pPars->fVerbose )
1128// Cec_ManSatPrintStats( p );
1129 Cec_ManSatStop( p );
1130 *pvStatus = vStatus;
1131 return vCexStore;
1132}
1133
1134
1138
1139
1141
int nWords
Definition abcNpn.c:127
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Bar_ProgressStop(Bar_Progress_t *p)
Definition bar.c:126
Bar_Progress_t * Bar_ProgressStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Definition bar.c:66
struct Bar_Progress_t_ Bar_Progress_t
BASIC TYPES ///.
Definition bar.h:48
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
#define l_True
Definition bmcBmcS.c:35
#define l_False
Definition bmcBmcS.c:36
void Cec_ManPatSavePattern(Cec_ManPat_t *pPat, Cec_ManSat_t *p, Gia_Obj_t *pObj)
Definition cecPat.c:359
void Cec_ManPatSavePatternCSat(Cec_ManPat_t *pMan, Vec_Int_t *vPat)
Definition cecPat.c:402
void Cec_ManSatPrintStats(Cec_ManSat_t *p)
Definition cecMan.c:74
typedefABC_NAMESPACE_HEADER_START struct Cec_ManPat_t_ Cec_ManPat_t
INCLUDES ///.
Definition cecInt.h:49
void Cec_ManSatStop(Cec_ManSat_t *p)
Definition cecMan.c:105
struct Cec_ManSat_t_ Cec_ManSat_t
Definition cecInt.h:75
Cec_ManSat_t * Cec_ManSatCreate(Gia_Man_t *pAig, Cec_ParSat_t *pPars)
DECLARATIONS ///.
Definition cecMan.c:45
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver_solve
Definition cecSatG2.c:45
void Cec_CollectSuper_rec(Gia_Obj_t *pObj, Vec_Ptr_t *vSuper, int fFirst, int fUseMuxes)
Definition cecSolve.c:236
void Cec_CnfNodeAddToSolver(Cec_ManSat_t *p, Gia_Obj_t *pObj)
Definition cecSolve.c:306
void Cec_SetActivityFactors_rec(Cec_ManSat_t *p, Gia_Obj_t *pObj, int LevelMin, int LevelMax)
Definition cecSolve.c:406
void Cec_ManSatAddToStore(Vec_Int_t *vCexStore, Vec_Int_t *vCex, int Out)
Definition cecSolve.c:996
int Cec_ManSatCheckNode(Cec_ManSat_t *p, Gia_Obj_t *pObj)
Definition cecSolve.c:470
void Cec_ManSatSolveCSat(Cec_ManPat_t *pPat, Gia_Man_t *pAig, Cec_ParSat_t *pPars)
Definition cecSolve.c:809
void Cec_ManSavePattern(Cec_ManSat_t *p, Gia_Obj_t *pObj1, Gia_Obj_t *pObj2)
Definition cecSolve.c:1049
Abc_Cex_t * Cex_ManGenSimple(Cec_ManSat_t *p, int iOut)
Definition cecSolve.c:676
Abc_Cex_t * Cex_ManGenCex(Cec_ManSat_t *p, int iOut)
Definition cecSolve.c:684
Vec_Int_t * Cec_ManSatReadCex(Cec_ManSat_t *pSat)
Definition cecSolve.c:864
int Cec_ManSatCheckNodeTwo(Cec_ManSat_t *p, Gia_Obj_t *pObj1, Gia_Obj_t *pObj2)
Definition cecSolve.c:569
Vec_Str_t * Cec_ManSatSolveSeq(Vec_Ptr_t *vPatts, Gia_Man_t *pAig, Cec_ParSat_t *pPars, int nRegs, int *pnPats)
Definition cecSolve.c:911
int Cec_SetActivityFactors(Cec_ManSat_t *p, Gia_Obj_t *pObj)
Definition cecSolve.c:440
void Cec_ManSatSolveMiter_rec(Cec_ManSat_t *pSat, Gia_Man_t *p, Gia_Obj_t *pObj)
Definition cecSolve.c:1022
void Cec_ObjAddToFrontier(Cec_ManSat_t *p, Gia_Obj_t *pObj, Vec_Ptr_t *vFrontier)
Definition cecSolve.c:281
void Cec_CollectSuper(Gia_Obj_t *pObj, int fUseMuxes, Vec_Ptr_t *vSuper)
Definition cecSolve.c:262
void Cec_AddClausesMux(Cec_ManSat_t *p, Gia_Obj_t *pNode)
Definition cecSolve.c:64
void Cec_AddClausesSuper(Cec_ManSat_t *p, Gia_Obj_t *pNode, Vec_Ptr_t *vSuper)
Definition cecSolve.c:183
void Cec_ManSatSolve(Cec_ManPat_t *pPat, Gia_Man_t *pAig, Cec_ParSat_t *pPars, Vec_Int_t *vIdsOrig, Vec_Int_t *vMiterPairs, Vec_Int_t *vEquivPairs, int f0Proved)
Definition cecSolve.c:699
int Cec_ObjSatVarValue(Cec_ManSat_t *p, Gia_Obj_t *pObj)
FUNCTION DEFINITIONS ///.
Definition cecSolve.c:48
void Cec_ManSatSolverRecycle(Cec_ManSat_t *p)
Definition cecSolve.c:365
Vec_Int_t * Cec_ManSatSolveMiter(Gia_Man_t *pAig, Cec_ParSat_t *pPars, Vec_Str_t **pvStatus)
Definition cecSolve.c:1070
void Cec_ManSatSolveSeq_rec(Cec_ManSat_t *pSat, Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Ptr_t *vInfo, int iPat, int nRegs)
Definition cecSolve.c:880
int Cec_ManSatSolveExractPattern(Vec_Int_t *vCexStore, int iStart, Vec_Int_t *vPat)
Definition cecSolve.c:794
typedefABC_NAMESPACE_HEADER_START struct Cec_ParSat_t_ Cec_ParSat_t
INCLUDES ///.
Definition cec.h:43
Cube * p
Definition exorList.c:222
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition giaUtil.c:1056
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ObjIsMuxType(Gia_Obj_t *pNode)
Definition giaUtil.c:982
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Vec_Int_t * Cbs_ManSolveMiterNc(Gia_Man_t *pGia, int nConfs, Vec_Str_t **pvStatus, int f0Proved, int fVerbose)
Definition giaCSat.c:1037
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
void Gia_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
Vec_Int_t * vCex
Definition cecInt.h:93
Vec_Ptr_t * vSeqModelVec
Definition gia.h:151
unsigned fMark1
Definition gia.h:86
unsigned fPhase
Definition gia.h:87
unsigned fMark0
Definition gia.h:81
ABC_NAMESPACE_IMPL_START Abc_Cex_t * Abc_CexAlloc(int nRegs, int nRealPis, int nFrames)
DECLARATIONS ///.
Definition utilCex.c:51
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
Definition utilCex.h:39
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55