ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cnfUtil.c
Go to the documentation of this file.
1
20
21#include "cnf.h"
22#include "sat/bsat/satSolver.h"
23
24#ifdef _MSC_VER
25#define unlink _unlink
26#else
27#include <unistd.h>
28#endif
29
30#ifdef ABC_USE_PTHREADS
31
32#ifdef _WIN32
33#include "../lib/pthread.h"
34#else
35#include <pthread.h>
36#endif
37
38#endif
39
41
45
46extern Vec_Int_t *Exa4_ManParse(char *pFileName);
47
51
63Vec_Int_t *Cnf_RunSolverOnce(int Id, int Rand, int TimeOut, int fVerbose)
64{
65 int fVerboseSolver = 0;
66 Vec_Int_t *vRes = NULL;
67 abctime clkTotal = Abc_Clock();
68 char FileNameIn[100], FileNameOut[100];
69 sprintf(FileNameIn, "%02d.cnf", Id);
70 sprintf(FileNameOut, "%02d.txt", Id);
71#ifdef _WIN32
72 char *pKissat = "kissat.exe";
73#else
74 char *pKissat = "kissat";
75#endif
76 char Command[1000], *pCommand = (char *)&Command;
77 if (TimeOut)
78 sprintf(pCommand, "%s --seed=%d --time=%d %s %s > %s", pKissat, Rand, TimeOut, fVerboseSolver ? "" : "-q", FileNameIn, FileNameOut);
79 else
80 sprintf(pCommand, "%s --seed=%d %s %s > %s", pKissat, Rand, fVerboseSolver ? "" : "-q", FileNameIn, FileNameOut);
81 //printf( "Thread command: %s\n", pCommand);
82 FILE * pFile = fopen(FileNameIn, "rb");
83 if ( pFile != NULL ) {
84 fclose( pFile );
85#if defined(__wasm)
86 if ( 1 ) {
87#else
88 if (system(pCommand) == -1) {
89#endif
90 fprintf(stdout, "Command \"%s\" did not succeed.\n", pCommand);
91 return 0;
92 }
93 vRes = Exa4_ManParse(FileNameOut); // FileNameOut is removed here
94 }
95 if (fVerbose) {
96 double SolvingTime = ((double)(Abc_Clock() - clkTotal))/((double)CLOCKS_PER_SEC);
97 if (vRes)
98 printf("Problem %2d has a solution. ", Id);
99 else if (vRes == NULL && (TimeOut == 0 || SolvingTime < (double)TimeOut))
100 printf("Problem %2d has no solution. ", Id);
101 else if (vRes == NULL)
102 printf("Problem %2d has no solution or timed out after %d sec. ", Id, TimeOut);
103 Abc_PrintTime(1, "Solving time", Abc_Clock() - clkTotal );
104 }
105 else if (vRes) {
106 printf("Problem %2d has a solution. ", Id);
107 Abc_PrintTime(1, "Solving time", Abc_Clock() - clkTotal );
108 printf("(Currently waiting for %d sec for other threads to finish.)\n", TimeOut);
109 }
110 return vRes;
111}
112Vec_Int_t * Cnf_RunSolverArray(int nProcs, int TimeOut, int fVerbose)
113{
114 Vec_Int_t *vRes = NULL; int i;
115 for ( i = 0; i < nProcs; i++ )
116 if ((vRes = Cnf_RunSolverOnce(i, 0, TimeOut, fVerbose)))
117 break;
118 return vRes;
119}
120
132#ifndef ABC_USE_PTHREADS
133
134Vec_Int_t *Cnf_RunSolver(int nProcs, int TimeOut, int fVerbose)
135{
136 return Cnf_RunSolverArray(nProcs, TimeOut, fVerbose);
137}
138
139#else // pthreads are used
140
141#define PAR_THR_MAX 100
142typedef struct Cnf_ThData_t_
143{
144 Vec_Int_t *vRes;
145 int Index;
146 int Rand;
147 int nTimeOut;
148 int fWorking;
149 int fVerbose;
150} Cnf_ThData_t;
151
152void *Cnf_WorkerThread(void *pArg)
153{
154 Cnf_ThData_t *pThData = (Cnf_ThData_t *)pArg;
155 volatile int *pPlace = &pThData->fWorking;
156 while (1)
157 {
158 while (*pPlace == 0)
159 ;
160 assert(pThData->fWorking);
161 if (pThData->Index == -1)
162 {
163 pthread_exit(NULL);
164 assert(0);
165 return NULL;
166 }
167 pThData->vRes = Cnf_RunSolverOnce(pThData->Index, pThData->Rand, pThData->nTimeOut, pThData->fVerbose);
168 pThData->fWorking = 0;
169 }
170 assert(0);
171 return NULL;
172}
173
174Vec_Int_t *Cnf_RunSolver(int nProcs, int TimeOut, int fVerbose)
175{
176 Vec_Int_t *vRes = NULL;
177 Cnf_ThData_t ThData[PAR_THR_MAX];
178 pthread_t WorkerThread[PAR_THR_MAX];
179 int i, k, status;
180 if (fVerbose)
181 printf("Running concurrent solving with %d processes.\n", nProcs);
182 fflush(stdout);
183 if (nProcs < 2)
184 return Cnf_RunSolverArray(nProcs, TimeOut, fVerbose);
185 // subtract manager thread
186 // nProcs--;
187 assert(nProcs >= 1 && nProcs <= PAR_THR_MAX);
188 // start threads
189 for (i = 0; i < nProcs; i++)
190 {
191 ThData[i].vRes = NULL;
192 ThData[i].Index = -1;
193 ThData[i].Rand = Abc_Random(0) % 0x1000000;
194 ThData[i].nTimeOut = TimeOut;
195 ThData[i].fWorking = 0;
196 ThData[i].fVerbose = fVerbose;
197 status = pthread_create(WorkerThread + i, NULL, Cnf_WorkerThread, (void *)(ThData + i));
198 assert(status == 0);
199 }
200 // look at the threads
201 for (k = 0; k < nProcs;)
202 {
203 for (i = 0; i < nProcs; i++)
204 {
205 if (ThData[i].fWorking)
206 continue;
207 if (ThData[i].vRes)
208 {
209 k = nProcs;
210 break;
211 }
212 ThData[i].Index = k++;
213 ThData[i].fWorking = 1;
214 break;
215 }
216 }
217 // wait till threads finish
218 for (i = 0; i < nProcs; i++)
219 if (ThData[i].fWorking)
220 i = -1;
221 // stop threads
222 for (i = 0; i < nProcs; i++)
223 {
224 assert(!ThData[i].fWorking);
225 if (ThData[i].vRes && vRes == NULL)
226 {
227 vRes = ThData[i].vRes;
228 ThData[i].vRes = NULL;
229 }
230 Vec_IntFreeP(&ThData[i].vRes);
231 // stop
232 ThData[i].Index = -1;
233 ThData[i].fWorking = 1;
234 }
235 return vRes;
236}
237
238#endif // pthreads are used
239
240
241
254{
255 Aig_Obj_t *pLeaf;
256 Dar_Cut_t *pCutBest;
257 int aArea, i;
258 if (pObj->nRefs++ || Aig_ObjIsCi(pObj) || Aig_ObjIsConst1(pObj))
259 return 0;
260 assert(Aig_ObjIsAnd(pObj));
261 // collect the node first to derive pre-order
262 if (vMapped)
263 Vec_PtrPush(vMapped, pObj);
264 // visit the transitive fanin of the selected cut
265 if (pObj->fMarkB)
266 {
267 Vec_Ptr_t *vSuper = Vec_PtrAlloc(100);
268 Aig_ObjCollectSuper(pObj, vSuper);
269 aArea = Vec_PtrSize(vSuper) + 1;
270 Vec_PtrForEachEntry(Aig_Obj_t *, vSuper, pLeaf, i)
271 aArea += Aig_ManScanMapping_rec(p, Aig_Regular(pLeaf), vMapped);
272 Vec_PtrFree(vSuper);
274 pObj->fMarkB = 1;
275 }
276 else
277 {
278 pCutBest = Dar_ObjBestCut(pObj);
279 aArea = Cnf_CutSopCost(p, pCutBest);
280 Dar_CutForEachLeaf(p->pManAig, pCutBest, pLeaf, i)
281 aArea += Aig_ManScanMapping_rec(p, pLeaf, vMapped);
282 }
283 return aArea;
284}
285
298{
299 Vec_Ptr_t *vMapped = NULL;
300 Aig_Obj_t *pObj;
301 int i;
302 // clean all references
303 Aig_ManForEachObj(p->pManAig, pObj, i)
304 pObj->nRefs = 0;
305 // allocate the array
306 if (fCollect)
307 vMapped = Vec_PtrAlloc(1000);
308 // collect nodes reachable from POs in the DFS order through the best cuts
309 p->aArea = 0;
310 Aig_ManForEachCo(p->pManAig, pObj, i)
311 p->aArea += Aig_ManScanMapping_rec(p, Aig_ObjFanin0(pObj), vMapped);
312 // printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) + Aig_ManCiNum(p->pManAig) + 1 : 0, p->aArea + 2 );
313 return vMapped;
314}
315
327int Cnf_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped, int fPreorder)
328{
329 Aig_Obj_t *pLeaf;
330 Cnf_Cut_t *pCutBest;
331 int aArea, i;
332 if (pObj->nRefs++ || Aig_ObjIsCi(pObj) || Aig_ObjIsConst1(pObj))
333 return 0;
334 assert(Aig_ObjIsAnd(pObj));
335 assert(pObj->pData != NULL);
336 // add the node to the mapping
337 if (vMapped && fPreorder)
338 Vec_PtrPush(vMapped, pObj);
339 // visit the transitive fanin of the selected cut
340 if (pObj->fMarkB)
341 {
342 Vec_Ptr_t *vSuper = Vec_PtrAlloc(100);
343 Aig_ObjCollectSuper(pObj, vSuper);
344 aArea = Vec_PtrSize(vSuper) + 1;
345 Vec_PtrForEachEntry(Aig_Obj_t *, vSuper, pLeaf, i)
346 aArea += Cnf_ManScanMapping_rec(p, Aig_Regular(pLeaf), vMapped, fPreorder);
347 Vec_PtrFree(vSuper);
349 pObj->fMarkB = 1;
350 }
351 else
352 {
353 pCutBest = (Cnf_Cut_t *)pObj->pData;
354 // assert( pCutBest->nFanins > 0 );
355 assert(pCutBest->Cost < 127);
356 aArea = pCutBest->Cost;
357 Cnf_CutForEachLeaf(p->pManAig, pCutBest, pLeaf, i)
358 aArea += Cnf_ManScanMapping_rec(p, pLeaf, vMapped, fPreorder);
359 }
360 // add the node to the mapping
361 if (vMapped && !fPreorder)
362 Vec_PtrPush(vMapped, pObj);
363 return aArea;
364}
365
377Vec_Ptr_t *Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
378{
379 Vec_Ptr_t *vMapped = NULL;
380 Aig_Obj_t *pObj;
381 int i;
382 // clean all references
383 Aig_ManForEachObj(p->pManAig, pObj, i)
384 pObj->nRefs = 0;
385 // allocate the array
386 if (fCollect)
387 vMapped = Vec_PtrAlloc(1000);
388 // collect nodes reachable from POs in the DFS order through the best cuts
389 p->aArea = 0;
390 Aig_ManForEachCo(p->pManAig, pObj, i)
391 p->aArea += Cnf_ManScanMapping_rec(p, Aig_ObjFanin0(pObj), vMapped, fPreorder);
392 // printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) + Aig_ManCiNum(p->pManAig) + 1 : 0, p->aArea + 2 );
393 return vMapped;
394}
395
408{
409 Vec_Int_t *vCiIds;
410 Aig_Obj_t *pObj;
411 int i;
412 vCiIds = Vec_IntAlloc(Aig_ManCiNum(p));
413 Aig_ManForEachCi(p, pObj, i)
414 Vec_IntPush(vCiIds, pCnf->pVarNums[pObj->Id]);
415 return vCiIds;
416}
417
430{
431 Vec_Int_t *vCoIds;
432 Aig_Obj_t *pObj;
433 int i;
434 vCoIds = Vec_IntAlloc(Aig_ManCoNum(p));
435 Aig_ManForEachCo(p, pObj, i)
436 Vec_IntPush(vCoIds, pCnf->pVarNums[pObj->Id]);
437 return vCoIds;
438}
439
452{
453 int i, c, iClaBeg, iClaEnd, *pLit;
454 unsigned *pPols0 = ABC_CALLOC(unsigned, Aig_ManObjNumMax(p->pMan));
455 unsigned *pPols1 = ABC_CALLOC(unsigned, Aig_ManObjNumMax(p->pMan));
456 unsigned char *pPres = ABC_CALLOC(unsigned char, p->nClauses);
457 for (i = 0; i < Aig_ManObjNumMax(p->pMan); i++)
458 {
459 if (p->pObj2Count[i] == 0)
460 continue;
461 iClaBeg = p->pObj2Clause[i];
462 iClaEnd = p->pObj2Clause[i] + p->pObj2Count[i];
463 // go through the negative polarity clauses
464 for (c = iClaBeg; c < iClaEnd; c++)
465 for (pLit = p->pClauses[c] + 1; pLit < p->pClauses[c + 1]; pLit++)
466 if (Abc_LitIsCompl(p->pClauses[c][0]))
467 pPols0[Abc_Lit2Var(*pLit)] |= (unsigned)(2 - Abc_LitIsCompl(*pLit)); // taking the opposite (!) -- not the case
468 else
469 pPols1[Abc_Lit2Var(*pLit)] |= (unsigned)(2 - Abc_LitIsCompl(*pLit)); // taking the opposite (!) -- not the case
470 // record these clauses
471 for (c = iClaBeg; c < iClaEnd; c++)
472 for (pLit = p->pClauses[c] + 1; pLit < p->pClauses[c + 1]; pLit++)
473 if (Abc_LitIsCompl(p->pClauses[c][0]))
474 pPres[c] = (unsigned char)((unsigned)pPres[c] | (pPols0[Abc_Lit2Var(*pLit)] << (2 * (pLit - p->pClauses[c] - 1))));
475 else
476 pPres[c] = (unsigned char)((unsigned)pPres[c] | (pPols1[Abc_Lit2Var(*pLit)] << (2 * (pLit - p->pClauses[c] - 1))));
477 // clean negative polarity
478 for (c = iClaBeg; c < iClaEnd; c++)
479 for (pLit = p->pClauses[c] + 1; pLit < p->pClauses[c + 1]; pLit++)
480 pPols0[Abc_Lit2Var(*pLit)] = pPols1[Abc_Lit2Var(*pLit)] = 0;
481 }
482 ABC_FREE(pPols0);
483 ABC_FREE(pPols1);
484 /*
485 // for ( c = 0; c < p->nClauses; c++ )
486 for ( c = 0; c < 100; c++ )
487 {
488 printf( "Clause %6d : ", c );
489 for ( i = 0; i < 4; i++ )
490 printf( "%d ", ((unsigned)pPres[c] >> (2*i)) & 3 );
491 printf( " " );
492 for ( pLit = p->pClauses[c]; pLit < p->pClauses[c+1]; pLit++ )
493 printf( "%6d ", *pLit );
494 printf( "\n" );
495 }
496 */
497 return pPres;
498}
499
512{
513 int MaxLine = 1000000;
514 int Var, Lit, nVars = -1, nClas = -1, i, Entry, iLine = 0;
515 Cnf_Dat_t *pCnf = NULL;
516 Vec_Int_t *vClas = NULL;
517 Vec_Int_t *vLits = NULL;
518 char *pBuffer, *pToken;
519 FILE *pFile = fopen(pFileName, "rb");
520 if (pFile == NULL)
521 {
522 printf("Cannot open file \"%s\" for writing.\n", pFileName);
523 return NULL;
524 }
525 pBuffer = ABC_ALLOC(char, MaxLine);
526 while (fgets(pBuffer, MaxLine, pFile) != NULL)
527 {
528 iLine++;
529 if (pBuffer[0] == 'c')
530 continue;
531 if (pBuffer[0] == 'p')
532 {
533 pToken = strtok(pBuffer + 1, " \t");
534 if (strcmp(pToken, "cnf"))
535 {
536 printf("Incorrect input file.\n");
537 goto finish;
538 }
539 pToken = strtok(NULL, " \t");
540 nVars = atoi(pToken);
541 pToken = strtok(NULL, " \t");
542 nClas = atoi(pToken);
543 if (nVars <= 0 || nClas <= 0)
544 {
545 printf("Incorrect parameters.\n");
546 goto finish;
547 }
548 // temp storage
549 vClas = Vec_IntAlloc(nClas + 1);
550 vLits = Vec_IntAlloc(nClas * 8);
551 continue;
552 }
553 pToken = strtok(pBuffer, " \t\r\n");
554 if (pToken == NULL)
555 continue;
556 Vec_IntPush(vClas, Vec_IntSize(vLits));
557 while (pToken)
558 {
559 Var = atoi(pToken);
560 if (Var == 0)
561 break;
562 Lit = (Var > 0) ? Abc_Var2Lit(Var - 1, 0) : Abc_Var2Lit(-Var - 1, 1);
563 if (Lit >= 2 * nVars)
564 {
565 printf("Literal %d is out-of-bound for %d variables.\n", Lit, nVars);
566 goto finish;
567 }
568 Vec_IntPush(vLits, Lit);
569 pToken = strtok(NULL, " \t\r\n");
570 }
571 if (Var != 0)
572 {
573 printf("There is no zero-terminator in line %d.\n", iLine);
574 goto finish;
575 }
576 }
577 // finalize
578 if (Vec_IntSize(vClas) != nClas)
579 printf("Warning! The number of clauses (%d) is different from declaration (%d).\n", Vec_IntSize(vClas), nClas);
580 Vec_IntPush(vClas, Vec_IntSize(vLits));
581 // create
582 pCnf = ABC_CALLOC(Cnf_Dat_t, 1);
583 pCnf->nVars = nVars;
584 pCnf->nClauses = Vec_IntSize(vClas) - 1;
585 pCnf->nLiterals = Vec_IntSize(vLits);
586 pCnf->pClauses = ABC_ALLOC(int *, Vec_IntSize(vClas));
587 pCnf->pClauses[0] = Vec_IntReleaseArray(vLits);
588 Vec_IntForEachEntry(vClas, Entry, i)
589 pCnf->pClauses[i] = pCnf->pClauses[0] + Entry;
590finish:
591 fclose(pFile);
592 Vec_IntFreeP(&vClas);
593 Vec_IntFreeP(&vLits);
594 ABC_FREE(pBuffer);
595 return pCnf;
596}
597
609int Cnf_DataSolveFromFile(char *pFileName, int nConfLimit, int nLearnedStart, int nLearnedDelta, int nLearnedPerce, int fVerbose, int fShowPattern, int **ppModel, int nPis)
610{
611 abctime clk = Abc_Clock();
612 Cnf_Dat_t *pCnf = Cnf_DataReadFromFile(pFileName);
613 sat_solver *pSat;
614 int i, status, RetValue = -1;
615 if (pCnf == NULL)
616 return -1;
617 if (fVerbose)
618 {
619 printf("CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals);
620 Abc_PrintTime(1, "Time", Abc_Clock() - clk);
621 }
622 // convert into SAT solver
623 pSat = (sat_solver *)Cnf_DataWriteIntoSolver(pCnf, 1, 0);
624 if (pSat == NULL)
625 {
626 printf("The problem is trivially UNSAT.\n");
627 Cnf_DataFree(pCnf);
628 return 1;
629 }
630 if (nLearnedStart)
631 pSat->nLearntStart = pSat->nLearntMax = nLearnedStart;
632 if (nLearnedDelta)
633 pSat->nLearntDelta = nLearnedDelta;
634 if (nLearnedPerce)
635 pSat->nLearntRatio = nLearnedPerce;
636 if (fVerbose)
637 pSat->fVerbose = fVerbose;
638
639 // sat_solver_start_cardinality( pSat, 100 );
640
641 // solve the miter
642 status = sat_solver_solve(pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, (ABC_INT64_T)0, (ABC_INT64_T)0);
643 if (status == l_Undef)
644 RetValue = -1;
645 else if (status == l_True)
646 RetValue = 0;
647 else if (status == l_False)
648 RetValue = 1;
649 else
650 assert(0);
651 if (fVerbose)
652 Sat_SolverPrintStats(stdout, pSat);
653 if (RetValue == -1)
654 Abc_Print(1, "UNDECIDED ");
655 else if (RetValue == 0)
656 Abc_Print(1, "SATISFIABLE ");
657 else
658 Abc_Print(1, "UNSATISFIABLE ");
659 // Abc_Print( -1, "\n" );
660 Abc_PrintTime(1, "Time", Abc_Clock() - clk);
661 // derive SAT assignment
662 if (RetValue == 0 && nPis > 0)
663 {
664 *ppModel = ABC_ALLOC(int, nPis);
665 for (i = 0; i < nPis; i++)
666 (*ppModel)[i] = sat_solver_var_value(pSat, pCnf->nVars - nPis + i);
667 }
668 if (RetValue == 0 && fShowPattern)
669 {
670 for (i = 0; i < pCnf->nVars; i++)
671 printf("%d", sat_solver_var_value(pSat, i));
672 printf("\n");
673 }
674 Cnf_DataFree(pCnf);
675 sat_solver_delete(pSat);
676 return RetValue;
677}
678
690int Cnf_DataBestVar(Cnf_Dat_t *p, int *pSkip)
691{
692 int *pNums = ABC_CALLOC(int, p->nVars);
693 int i, *pLit, NumMax = -1, iVarMax = -1;
694 for (i = 0; i < p->nClauses; i++)
695 for (pLit = p->pClauses[i]; pLit < p->pClauses[i + 1]; pLit++)
696 pNums[Abc_Lit2Var(*pLit)]++;
697 for (i = 0; i < p->nVars; i++)
698 if ((!pSkip || !pSkip[i]) && NumMax < pNums[i])
699 NumMax = pNums[i], iVarMax = i;
700 ABC_FREE(pNums);
701 return iVarMax;
702}
704{
705 Cnf_Dat_t *pTemp, *p = Cnf_DataReadFromFile("../166b.cnf");
706 int i, *pSkip = ABC_CALLOC(int, p->nVars);
707 for (i = 0; i < 100; i++)
708 {
709 int iVar = Cnf_DataBestVar(p, pSkip);
710 char FileName[100];
711 sprintf(FileName, "cnf/%03d.cnf", i);
712 Cnf_DataWriteIntoFile(p, FileName, 0, NULL, NULL);
713 printf("Dumped file \"%s\".\n", FileName);
714 p = Cnf_DataDupCof(pTemp = p, Abc_Var2Lit(iVar, 0));
715 Cnf_DataFree(pTemp);
716 pSkip[iVar] = 1;
717 }
719 ABC_FREE(pSkip);
720}
721
733Vec_Int_t *Cnf_GenRandLits(int iVarBeg, int iVarEnd, int nLits, int Value, int Rand, int fVerbose)
734{
735 Vec_Int_t *vLits = Vec_IntAlloc(nLits);
736 assert(iVarBeg < iVarEnd && nLits < iVarEnd - iVarBeg);
737 while (Vec_IntSize(vLits) < nLits)
738 {
739 int iVar = iVarBeg + (Abc_Random(0) ^ Rand) % (iVarEnd - iVarBeg);
740 assert(iVar >= iVarBeg && iVar < iVarEnd);
741 if (Vec_IntFind(vLits, Abc_Var2Lit(iVar, 0)) == -1 && Vec_IntFind(vLits, Abc_Var2Lit(iVar, 1)) == -1)
742 {
743 if (Value == 0)
744 Vec_IntPush(vLits, Abc_Var2Lit(iVar, 1));
745 else if (Value == 1)
746 Vec_IntPush(vLits, Abc_Var2Lit(iVar, 0));
747 else
748 Vec_IntPush(vLits, Abc_Var2Lit(iVar, Abc_Random(0) & 1));
749 }
750 }
751 Vec_IntSort(vLits, 0);
752 if ( fVerbose )
753 Vec_IntPrint(vLits);
754 fflush(stdout);
755 return vLits;
756}
757void Cnf_SplitCnfFile(char * pFileName, int nParts, int iVarBeg, int iVarEnd, int nLits, int Value, int Rand, int fPrepro, int fVerbose)
758{
759 Cnf_Dat_t *p = Cnf_DataReadFromFile(pFileName); int k;
760 if (iVarEnd == ABC_INFINITY)
761 iVarEnd = p->nVars;
762 for (k = 0; k < nParts; k++)
763 {
764 Vec_Int_t *vLits = Cnf_GenRandLits(iVarBeg, iVarEnd, nLits, Value, Rand, fVerbose);
765 Cnf_Dat_t *pCnf = Cnf_DataDupCofArray(p, vLits);
766 char FileName[100]; sprintf(FileName, "%02d.cnf", k);
767 if ( fPrepro ) {
768 char Command[1000];
769 sprintf(Command, "satelite --verbosity=0 -pre temp.cnf %s", FileName);
770 Cnf_DataWriteIntoFile(pCnf, "temp.cnf", 0, NULL, NULL);
771#if defined(__wasm)
772 if ( 1 ) {
773#else
774 if (system(Command) == -1) {
775#endif
776 fprintf(stdout, "Command \"%s\" did not succeed. Preprocessing skipped.\n", Command);
777 Cnf_DataWriteIntoFile(pCnf, FileName, 0, NULL, NULL);
778 }
779 unlink("temp.cnf");
780 }
781 else
782 Cnf_DataWriteIntoFile(pCnf, FileName, 0, NULL, NULL);
783 Cnf_DataFree(pCnf);
784 Vec_IntFree(vLits);
785 }
787}
788void Cnf_SplitCnfCleanup(int nParts)
789{
790 char FileName[100]; int k;
791 for (k = 0; k < nParts; k++) {
792 sprintf(FileName, "%02d.cnf", k);
793 unlink(FileName);
794 }
795}
796void Cnf_SplitSat(char *pFileName, int iVarBeg, int iVarEnd, int nLits, int Value, int TimeOut, int nProcs, int nIters, int Seed, int fPrepro, int fVerbose)
797{
798 abctime clk = Abc_Clock();
799 Vec_Int_t *vSol = NULL;
800 int i, Rand = 0;
801 if ( nIters == 0 )
802 nIters = ABC_INFINITY;
803 Abc_Random(1);
804 for ( i = 0; i < Seed; i++ )
805 Abc_Random(0);
806 Rand = Abc_Random(0);
807 for (i = 0; i < nIters && !vSol; i++)
808 {
809 abctime clk2 = Abc_Clock();
810 Cnf_SplitCnfFile(pFileName, nProcs, iVarBeg, iVarEnd, nLits, Value, Rand, fPrepro, fVerbose);
811 vSol = Cnf_RunSolver(nProcs, TimeOut, fVerbose);
812 Cnf_SplitCnfCleanup(nProcs);
813 if (fVerbose) {
814 printf( "Finished iteration %d. ", i);
815 Abc_PrintTime(0, "Time", Abc_Clock() - clk2);
816 }
817 }
818 printf("%solution is found. ", vSol ? "S" : "No s");
819 Abc_PrintTime(0, "Total time", Abc_Clock() - clk);
820 Vec_IntFreeP(&vSol);
821}
822
826
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
unsigned Abc_Random(int fReset)
Definition utilSort.c:1004
#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
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
int Aig_ObjCollectSuper(Aig_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition aigDfs.c:1111
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define PAR_THR_MAX
DECLARATIONS ///.
Definition bmcBmcG.c:31
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
Vec_Int_t * Cnf_DataCollectCoSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfUtil.c:429
void Cnf_SplitSat(char *pFileName, int iVarBeg, int iVarEnd, int nLits, int Value, int TimeOut, int nProcs, int nIters, int Seed, int fPrepro, int fVerbose)
Definition cnfUtil.c:796
Cnf_Dat_t * Cnf_DataReadFromFile(char *pFileName)
Definition cnfUtil.c:511
Vec_Int_t * Cnf_RunSolverOnce(int Id, int Rand, int TimeOut, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition cnfUtil.c:63
int Cnf_DataSolveFromFile(char *pFileName, int nConfLimit, int nLearnedStart, int nLearnedDelta, int nLearnedPerce, int fVerbose, int fShowPattern, int **ppModel, int nPis)
Definition cnfUtil.c:609
unsigned char * Cnf_DataDeriveLitPolarities(Cnf_Dat_t *p)
Definition cnfUtil.c:451
Vec_Int_t * Cnf_RunSolverArray(int nProcs, int TimeOut, int fVerbose)
Definition cnfUtil.c:112
int Cnf_DataBestVar(Cnf_Dat_t *p, int *pSkip)
Definition cnfUtil.c:690
ABC_NAMESPACE_IMPL_START Vec_Int_t * Exa4_ManParse(char *pFileName)
DECLARATIONS ///.
Definition bmcMaj.c:1812
void Cnf_SplitCnfCleanup(int nParts)
Definition cnfUtil.c:788
int Aig_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped)
Definition cnfUtil.c:253
void Cnf_SplitCnfFile(char *pFileName, int nParts, int iVarBeg, int iVarEnd, int nLits, int Value, int Rand, int fPrepro, int fVerbose)
Definition cnfUtil.c:757
void Cnf_Experiment1()
Definition cnfUtil.c:703
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition cnfUtil.c:377
int Cnf_ManScanMapping_rec(Cnf_Man_t *p, Aig_Obj_t *pObj, Vec_Ptr_t *vMapped, int fPreorder)
Definition cnfUtil.c:327
Vec_Int_t * Cnf_GenRandLits(int iVarBeg, int iVarEnd, int nLits, int Value, int Rand, int fVerbose)
Definition cnfUtil.c:733
Vec_Int_t * Cnf_DataCollectCiSatNums(Cnf_Dat_t *pCnf, Aig_Man_t *p)
Definition cnfUtil.c:407
Vec_Int_t * Cnf_RunSolver(int nProcs, int TimeOut, int fVerbose)
Definition cnfUtil.c:134
Vec_Ptr_t * Aig_ManScanMapping(Cnf_Man_t *p, int fCollect)
Definition cnfUtil.c:297
Cnf_Dat_t * Cnf_DataDupCofArray(Cnf_Dat_t *p, Vec_Int_t *vLits)
Definition cnfMan.c:178
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition cnf.h:51
Cnf_Dat_t * Cnf_DataDupCof(Cnf_Dat_t *p, int Lit)
Definition cnfMan.c:163
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
struct Cnf_Cut_t_ Cnf_Cut_t
Definition cnf.h:53
#define Cnf_CutForEachLeaf(p, pCut, pLeaf, i)
Definition cnf.h:121
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition cnfMan.c:387
struct Dar_Cut_t_ Dar_Cut_t
Definition darInt.h:52
#define Dar_CutForEachLeaf(p, pCut, pLeaf, i)
Definition darInt.h:124
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
void Sat_SolverPrintStats(FILE *pFile, sat_solver *p)
Definition satUtil.c:193
int Id
Definition aig.h:85
unsigned int nRefs
Definition aig.h:81
unsigned int fMarkB
Definition aig.h:80
void * pData
Definition aig.h:87
char Cost
Definition cnf.h:74
int nVars
Definition cnf.h:59
int nLiterals
Definition cnf.h:60
int * pVarNums
Definition cnf.h:63
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
#define assert(ex)
Definition util_old.h:213
int system()
int strcmp()
char * sprintf()
char * strtok()
#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