abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
sscUtil.c File Reference
#include "sscInt.h"
#include "sat/cnf/cnf.h"
#include "aig/gia/giaAig.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START
Gia_Man_t
Gia_ManDropContained (Gia_Man_t *p)
 DECLARATIONS ///. More...
 
Gia_Man_tGia_ManOptimizeRing (Gia_Man_t *p)
 

Function Documentation

ABC_NAMESPACE_IMPL_START Gia_Man_t* Gia_ManDropContained ( Gia_Man_t p)

DECLARATIONS ///.

CFile****************************************************************

FileName [sscUtil.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT sweeping under constraints.]

Synopsis [Various utilities.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 29, 2008.]

Revision [

Id:
sscUtil.c,v 1.00 2008/07/29 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file sscUtil.c.

48 {
49  Gia_Man_t * pNew;
50  Aig_Man_t * pMan = Gia_ManToAigSimple( p );
51  Cnf_Dat_t * pDat = Cnf_Derive( pMan, Gia_ManPoNum(p) );
52  Gia_Obj_t * pObj;
53  Vec_Int_t * vLits, * vKeep;
54  sat_solver * pSat;
55  int ConstLit = Abc_Var2Lit(pDat->pVarNums[0], 0);
56  int i, status;//, Count = 0;
57  Aig_ManStop( pMan );
58 
59  vLits = Vec_IntAlloc( Gia_ManPoNum(p) );
60  Gia_ManForEachPo( p, pObj, i )
61  {
62  int iObj = Gia_ObjId( p, pObj );
63  Vec_IntPush( vLits, Abc_Var2Lit(pDat->pVarNums[iObj], 1) );
64  }
65 
66  // start the SAT solver
67  pSat = sat_solver_new();
68  sat_solver_setnvars( pSat, pDat->nVars );
69  for ( i = 0; i < pDat->nClauses; i++ )
70  {
71  if ( !sat_solver_addclause( pSat, pDat->pClauses[i], pDat->pClauses[i+1] ) )
72  {
73  Cnf_DataFree( pDat );
74  sat_solver_delete( pSat );
75  Vec_IntFree( vLits );
76  return NULL;
77  }
78  }
79  Cnf_DataFree( pDat );
80  status = sat_solver_simplify( pSat );
81  if ( status == 0 )
82  {
83  sat_solver_delete( pSat );
84  Vec_IntFree( vLits );
85  return NULL;
86  }
87 
88  // iterate over POs
89  vKeep = Vec_IntAlloc( Gia_ManPoNum(p) );
90  Gia_ManForEachPo( p, pObj, i )
91  {
92  Vec_IntWriteEntry( vLits, i, Abc_LitNot(Vec_IntEntry(vLits,i)) );
93  status = sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits), 0, 0, 0, 0 );
94  Vec_IntWriteEntry( vLits, i, Abc_LitNot(Vec_IntEntry(vLits,i)) );
95  if ( status == l_False )
96  Vec_IntWriteEntry( vLits, i, ConstLit ); // const1 SAT var is always true
97  else
98  {
99  assert( status = l_True );
100  Vec_IntPush( vKeep, i );
101  }
102  }
103  sat_solver_delete( pSat );
104  Vec_IntFree( vLits );
105  if ( Vec_IntSize(vKeep) == Gia_ManPoNum(p) )
106  {
107  Vec_IntFree( vKeep );
108  return Gia_ManDup(p);
109  }
110  pNew = Gia_ManDupCones( p, Vec_IntArray(vKeep), Vec_IntSize(vKeep), 0 );
111  Vec_IntFree( vKeep );
112  return pNew;
113 }
static int * Vec_IntArray(Vec_Int_t *p)
Definition: vecInt.h:328
Gia_Man_t * Gia_ManDupCones(Gia_Man_t *p, int *pPos, int nPos, int fTrimPis)
Definition: giaDup.c:2691
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition: giaDup.c:552
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
Definition: giaAig.c:367
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:165
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Definition: satSolver.c:1492
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Aig_ManStop(Aig_Man_t *p)
Definition: aigMan.c:187
int nClauses
Definition: cnf.h:61
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
Definition: satSolver.c:1700
int nVars
Definition: cnf.h:59
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
static int Abc_Var2Lit(int Var, int fCompl)
Definition: abc_global.h:263
int * pVarNums
Definition: cnf.h:63
#define l_True
Definition: SolverTypes.h:84
Definition: cnf.h:56
Definition: gia.h:75
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
int ** pClauses
Definition: cnf.h:62
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
void sat_solver_setnvars(sat_solver *s, int n)
Definition: satSolver.c:1072
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
static int Abc_LitNot(int Lit)
Definition: abc_global.h:266
int sat_solver_simplify(sat_solver *s)
Definition: satSolver.c:1276
sat_solver * sat_solver_new(void)
Definition: satSolver.c:1001
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
Definition: gia.h:95
#define l_False
Definition: SolverTypes.h:85
void Cnf_DataFree(Cnf_Dat_t *p)
Definition: cnfMan.c:180
#define assert(ex)
Definition: util_old.h:213
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Gia_ManForEachPo(p, pObj, i)
Definition: gia.h:1036
Gia_Man_t* Gia_ManOptimizeRing ( Gia_Man_t p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 126 of file sscUtil.c.

127 {
128  Ssc_Pars_t Pars, * pPars = &Pars;
129  Gia_Man_t * pTemp, * pAux;
130  int i;
131  assert( p->nConstrs == 0 );
132  printf( "User AIG: " );
133  Gia_ManPrintStats( p, NULL );
134  pTemp = Gia_ManDropContained( p );
135  printf( "Drop AIG: " );
136  Gia_ManPrintStats( pTemp, NULL );
137 // return pTemp;
138  if ( Gia_ManPoNum(pTemp) == 1 )
139  return pTemp;
140  Ssc_ManSetDefaultParams( pPars );
141  pPars->fAppend = 1;
142  pPars->fVerbose = 0;
143  pTemp->nConstrs = Gia_ManPoNum(pTemp) - 1;
144  for ( i = 0; i < Gia_ManPoNum(pTemp); i++ )
145  {
146  // move i-th PO forward
147  Gia_ManSwapPos( pTemp, i );
148  pTemp = Gia_ManDupDfs( pAux = pTemp );
149  Gia_ManStop( pAux );
150  // minimize this PO
151  pTemp = Ssc_PerformSweepingConstr( pAux = pTemp, pPars );
152  Gia_ManStop( pAux );
153  pTemp = Gia_ManDupDfs( pAux = pTemp );
154  Gia_ManStop( pAux );
155  // move i-th PO back
156  Gia_ManSwapPos( pTemp, i );
157  pTemp = Gia_ManDupDfs( pAux = pTemp );
158  Gia_ManStop( pAux );
159  // report results
160  printf( "AIG%3d : ", i );
161  Gia_ManPrintStats( pTemp, NULL );
162  }
163  pTemp->nConstrs = 0;
164  return pTemp;
165 }
void Ssc_ManSetDefaultParams(Ssc_Pars_t *p)
MACRO DEFINITIONS ///.
Definition: sscCore.c:46
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition: giaMan.c:389
static int Gia_ManPoNum(Gia_Man_t *p)
Definition: gia.h:386
typedefABC_NAMESPACE_HEADER_START struct Ssc_Pars_t_ Ssc_Pars_t
INCLUDES ///.
Definition: ssc.h:43
Gia_Man_t * Ssc_PerformSweepingConstr(Gia_Man_t *p, Ssc_Pars_t *pPars)
Definition: sscCore.c:420
int nConstrs
Definition: gia.h:117
void Gia_ManSwapPos(Gia_Man_t *p, int i)
Definition: giaUtil.c:1582
Gia_Man_t * Gia_ManDupDfs(Gia_Man_t *p)
Definition: giaDup.c:1238
ABC_NAMESPACE_IMPL_START Gia_Man_t * Gia_ManDropContained(Gia_Man_t *p)
DECLARATIONS ///.
Definition: sscUtil.c:47
Definition: gia.h:95
#define assert(ex)
Definition: util_old.h:213