ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
relationGeneration.cpp
Go to the documentation of this file.
1
20
21#include <cassert>
22
23#include "misc/vec/vec.h"
24#include "sat/cnf/cnf.h"
25#include "sat/bsat/satSolver.h"
26
28
30 void * Mf_ManGenerateCnf( Gia_Man_t * pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose );
31 void * Cnf_DataWriteIntoSolver( Cnf_Dat_t * p, int nFrames, int fInit );
32 Vec_Int_t * Gia_ManCollectNodeTfos( Gia_Man_t * p, int * pNodes, int nNodes );
35
37
38
39namespace eSLIM {
40
41 RelationGeneratorABC::RelationGeneratorABC(Gia_Man_t* pGia, const Subcircuit& subcir)
42 : RelationGenerator(pGia, subcir) {
43
44 // for (const auto& [out, inputs] : subcir.forbidden_pairs) {
45 for (const auto& it: subcir.forbidden_pairs) {
46 const auto& inputs = it.second;
47 inputs_in_forbidden_pairs.insert(inputs.begin(), inputs.end());
48 }
49}
50
51 Vec_Int_t* RelationGeneratorABC::getRelationImpl() {
52 abctime clkStart = Abc_Clock();
53 int nTimeOut = 600, nConfLimit = 1000000;
54 int i, iNode, iSatVar, Iter, Mask, nSolutions = 0, RetValue = 0;
55 // --------------- Modification ---------------
56 Gia_Man_t* pMiter = generateMiter();
57 // --------------- Modification ---------------
58 Cnf_Dat_t * pCnf = (Cnf_Dat_t*)Mf_ManGenerateCnf( pMiter, 8, 0, 0, 0, 0 );
59 sat_solver * pSat = (sat_solver*)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
60 int iLit = Abc_Var2Lit( 1, 0 ); // enumerating the care set (the miter output is 1)
61 int status = sat_solver_addclause( pSat, &iLit, &iLit + 1 ); assert( status );
62 Vec_Int_t * vSatVars = Vec_IntAlloc( Vec_IntSize(subcir.io) );
63 Vec_IntForEachEntry( subcir.io, iNode, i )
64 Vec_IntPush( vSatVars, i < subcir.nof_inputs ? 2+i : pCnf->nVars-Vec_IntSize(subcir.io)+i );
65 Vec_Int_t * vLits = Vec_IntAlloc( 100 );
66 Vec_Int_t * vRes = Vec_IntAlloc( 1000 );
67 for ( Iter = 0; Iter < 1000000; Iter++ )
68 {
69 int status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, 0, 0, 0 );
70 if ( status == l_False ) { RetValue = 1; break; }
71 if ( status == l_Undef ) { RetValue = 0; break; }
72 nSolutions++;
73 // extract SAT assignment
74 Mask = 0;
75 Vec_IntClear( vLits );
76 Vec_IntForEachEntry( vSatVars, iSatVar, i ) {
77 Vec_IntPush( vLits, Abc_Var2Lit(iSatVar, sat_solver_var_value(pSat, iSatVar)) );
78 if ( sat_solver_var_value(pSat, iSatVar) )
79 Mask |= 1 << (Vec_IntSize(subcir.io)-1-i);
80 }
81 Vec_IntPush( vRes, Mask );
82 if ( !sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) ) )
83 { RetValue = 1; break; }
84 if ( nTimeOut && (Abc_Clock() - clkStart)/CLOCKS_PER_SEC >= nTimeOut ) { RetValue = 0; break; }
85 }
86 // complement the set of input/output minterms
87 Vec_Int_t * vBits = Vec_IntStart( 1 << Vec_IntSize(subcir.io) );
88 Vec_IntForEachEntry( vRes, Mask, i )
89 Vec_IntWriteEntry( vBits, Mask, 1 );
90 Vec_IntClear( vRes );
91 Vec_IntForEachEntry( vBits, Mask, i )
92 if ( !Mask )
93 Vec_IntPush( vRes, i );
94 Vec_IntFree( vBits );
95 // cleanup
96 Vec_IntFree( vLits );
97 Vec_IntFree( vSatVars );
98 sat_solver_delete( pSat );
99 Gia_ManStop( pMiter );
100 Cnf_DataFree( pCnf );
101 if ( RetValue == 0 )
102 Vec_IntFreeP( &vRes );
103 return vRes;
104 }
105
106 Gia_Man_t * RelationGeneratorABC::generateMiter() {
107 Vec_Int_t * vInsOuts = subcir.io;
108 int nIns = subcir.nof_inputs;
109
110 Vec_Int_t * vTfo = Gia_ManCollectNodeTfos( pGia, Vec_IntEntryP(vInsOuts, nIns), Vec_IntSize(vInsOuts)-nIns );
111 Vec_Int_t * vTfi = Gia_ManCollectNodeTfis( pGia, vTfo );
112 Vec_Int_t * vInLits = Vec_IntAlloc( nIns );
113 Vec_Int_t * vOutLits = Vec_IntAlloc( Vec_IntSize(vInsOuts) - nIns );
114 Gia_Man_t * pNew, * pTemp; Gia_Obj_t * pObj; int i, iLit = 0;
115 Gia_ManFillValue( pGia );
116 pNew = Gia_ManStart( 1000 );
117 pNew->pName = Abc_UtilStrsav( pGia->pName );
118 Gia_ManHashAlloc( pNew );
119 Gia_ManForEachObjVec( vTfi, pGia, pObj, i )
120 if ( Gia_ObjIsCi(pObj) )
121 pObj->Value = Gia_ManAppendCi(pNew);
122 for ( i = 0; i < Vec_IntSize(vInsOuts)-nIns; i++ )
123 Vec_IntPush( vInLits, Gia_ManAppendCi(pNew) );
124 Gia_ManForEachObjVec( vTfi, pGia, pObj, i )
125 if ( Gia_ObjIsAnd(pObj) )
126 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
127 Gia_ManForEachObjVec( vTfo, pGia, pObj, i )
128 if ( Gia_ObjIsCo(pObj) )
129 pObj->Value = Gia_ObjFanin0Copy(pObj);
130 Gia_ManForEachObjVec( vInsOuts, pGia, pObj, i )
131 if ( i < nIns )
132 Vec_IntPush( vOutLits, pObj->Value );
133 else
134 pObj->Value = Vec_IntEntry( vInLits, i-nIns );
135
137 Gia_ManForEachObjVec( subcir.nodes, pGia, pObj, i ) {
138 Gia_ObjSetTravIdCurrent(pGia, pObj);
139 }
140
141 Gia_ManForEachObjVec( vTfo, pGia, pObj, i )
142 // in case there are forbidden pairs we have to ensure that nodes from the sucircuit are not added
143 if ( Gia_ObjIsAnd(pObj) && !Gia_ObjIsTravIdCurrent(pGia, pObj) )
144 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
145 Gia_ManForEachObjVec( vTfo, pGia, pObj, i )
146 if ( Gia_ObjIsCo(pObj) )
147 iLit = Gia_ManHashOr( pNew, iLit, Gia_ManHashXor(pNew, Gia_ObjFanin0Copy(pObj), pObj->Value) );
148 // --------------- Modification ---------------
149 // In case there are forbidden pairs, the outputs of the subcircuit influence the inputs of the subcircuit.
150 // Therefore, we need the values of the inputs in the version of the circuit that is affected by the new outputs.
151 for (int inp : inputs_in_forbidden_pairs) {
152 int node_id = Vec_IntEntry(vInsOuts, inp);
153 pObj = Gia_ManObj(pGia, node_id);
154 Vec_IntWriteEntry(vOutLits, inp, pObj->Value);
155 }
156 // --------------- Modification ---------------
157 Gia_ManAppendCo( pNew, iLit );
158 Vec_IntForEachEntry( vOutLits, iLit, i )
159 Gia_ManAppendCo( pNew, iLit );
160 Vec_IntFree( vTfo );
161 Vec_IntFree( vTfi );
162 Vec_IntFree( vInLits );
163 Vec_IntFree( vOutLits );
164 pNew = Gia_ManCleanup( pTemp = pNew );
165 Gia_ManStop( pTemp );
166 Gia_ManSetRegNum( pNew, Gia_ManRegNum(pGia) );
167 return pNew;
168 }
169
170}
171
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
Cube * p
Definition exorList.c:222
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition giaHash.c:105
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:621
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:668
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition cnfMan.c:579
Vec_Int_t * Gia_ManCollectNodeTfos(Gia_Man_t *p, int *pNodes, int nNodes)
Definition giaQbf.c:1075
Vec_Int_t * Gia_ManCollectNodeTfis(Gia_Man_t *p, Vec_Int_t *vNodes)
Definition giaQbf.c:1093
ABC_NAMESPACE_HEADER_START void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
Definition giaMf.c:1877
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54