Commit 61850d59 by Alan Mishchenko

Version abc80116

parent 4a61139d
......@@ -1170,6 +1170,10 @@ SOURCE=.\src\sat\bsat\satInter.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satInterA.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satMem.c
# End Source File
# Begin Source File
......@@ -2870,6 +2874,10 @@ SOURCE=.\src\aig\aig\aigHaig.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\aig\aigInter.c
# End Source File
# Begin Source File
SOURCE=.\src\aig\aig\aigMan.c
# End Source File
# Begin Source File
......
/**CFile****************************************************************
FileName [aigInter.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [AIG package.]
Synopsis [Interpolate two AIGs.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - April 28, 2007.]
Revision [$Id: aigInter.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
***********************************************************************/
#include "aig.h"
#include "cnf.h"
#include "satStore.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Aig_Man_t * Aig_ManInter( Aig_Man_t * pManOn, Aig_Man_t * pManOff, int fVerbose )
{
void * pSatCnf = NULL;
Inta_Man_t * pManInter;
Aig_Man_t * pRes;
sat_solver * pSat;
Cnf_Dat_t * pCnfOn, * pCnfOff;
Vec_Int_t * vVarsAB;
Aig_Obj_t * pObj, * pObj2;
int Lits[3], status, i;
int clk = clock();
assert( Aig_ManPiNum(pManOn) == Aig_ManPiNum(pManOff) );
// derive CNFs
pCnfOn = Cnf_Derive( pManOn, 0 );
pCnfOff = Cnf_Derive( pManOff, 0 );
// pCnfOn = Cnf_DeriveSimple( pManOn, 0 );
// pCnfOff = Cnf_DeriveSimple( pManOff, 0 );
Cnf_DataLift( pCnfOff, pCnfOn->nVars );
// start the solver
pSat = sat_solver_new();
sat_solver_store_alloc( pSat );
sat_solver_setnvars( pSat, pCnfOn->nVars + pCnfOff->nVars );
// add clauses of A
for ( i = 0; i < pCnfOn->nClauses; i++ )
{
if ( !sat_solver_addclause( pSat, pCnfOn->pClauses[i], pCnfOn->pClauses[i+1] ) )
{
Cnf_DataFree( pCnfOn );
Cnf_DataFree( pCnfOff );
sat_solver_delete( pSat );
return NULL;
}
}
sat_solver_store_mark_clauses_a( pSat );
// add clauses of B
for ( i = 0; i < pCnfOff->nClauses; i++ )
{
if ( !sat_solver_addclause( pSat, pCnfOff->pClauses[i], pCnfOff->pClauses[i+1] ) )
{
Cnf_DataFree( pCnfOn );
Cnf_DataFree( pCnfOff );
sat_solver_delete( pSat );
return NULL;
}
}
// add PI clauses
// collect the common variables
vVarsAB = Vec_IntAlloc( Aig_ManPiNum(pManOn) );
Aig_ManForEachPi( pManOn, pObj, i )
{
Vec_IntPush( vVarsAB, pCnfOn->pVarNums[pObj->Id] );
pObj2 = Aig_ManPi( pManOff, i );
Lits[0] = toLitCond( pCnfOn->pVarNums[pObj->Id], 0 );
Lits[1] = toLitCond( pCnfOff->pVarNums[pObj2->Id], 1 );
if ( !sat_solver_addclause( pSat, Lits, Lits+2 ) )
assert( 0 );
Lits[0] = toLitCond( pCnfOn->pVarNums[pObj->Id], 1 );
Lits[1] = toLitCond( pCnfOff->pVarNums[pObj2->Id], 0 );
if ( !sat_solver_addclause( pSat, Lits, Lits+2 ) )
assert( 0 );
}
Cnf_DataFree( pCnfOn );
Cnf_DataFree( pCnfOff );
sat_solver_store_mark_roots( pSat );
if ( fVerbose )
{
PRT( "Prepare", clock() - clk );
}
/*
status = sat_solver_simplify(pSat);
if ( status == 0 )
{
Vec_IntFree( vVarsAB );
Cnf_DataFree( pCnfOn );
Cnf_DataFree( pCnfOff );
sat_solver_delete( pSat );
return NULL;
}
*/
// solve the problem
clk = clock();
status = sat_solver_solve( pSat, NULL, NULL, (sint64)0, (sint64)0, (sint64)0, (sint64)0 );
if ( fVerbose )
{
PRT( "Solving", clock() - clk );
}
if ( status == l_False )
{
pSatCnf = sat_solver_store_release( pSat );
// printf( "unsat\n" );
}
else if ( status == l_True )
{
// printf( "sat\n" );
}
else
{
// printf( "undef\n" );
}
sat_solver_delete( pSat );
if ( pSatCnf == NULL )
{
printf( "The SAT problem is not unsat.\n" );
Vec_IntFree( vVarsAB );
return NULL;
}
// create the resulting manager
pManInter = Inta_ManAlloc();
pRes = Inta_ManInterpolate( pManInter, pSatCnf, vVarsAB, fVerbose );
Inta_ManFree( pManInter );
Vec_IntFree( vVarsAB );
Sto_ManFree( pSatCnf );
return pRes;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......@@ -3,6 +3,7 @@ SRC += src/aig/aig/aigCheck.c \
src/aig/aig/aigFanout.c \
src/aig/aig/aigFrames.c \
src/aig/aig/aigHaig.c \
src/aig/aig/aigInter.c \
src/aig/aig/aigMan.c \
src/aig/aig/aigMem.c \
src/aig/aig/aigMffc.c \
......
......@@ -133,6 +133,7 @@ extern Cnf_Man_t * Cnf_ManStart();
extern void Cnf_ManStop( Cnf_Man_t * p );
extern Vec_Int_t * Cnf_DataCollectPiSatNums( Cnf_Dat_t * pCnf, Aig_Man_t * p );
extern void Cnf_DataFree( Cnf_Dat_t * p );
extern void Cnf_DataLift( Cnf_Dat_t * p, int nVarsPlus );
extern void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable );
void * Cnf_DataWriteIntoSolver( Cnf_Dat_t * p, int nFrames, int fInit );
/*=== cnfMap.c ========================================================*/
......
......@@ -139,6 +139,28 @@ void Cnf_DataFree( Cnf_Dat_t * p )
SeeAlso []
***********************************************************************/
void Cnf_DataLift( Cnf_Dat_t * p, int nVarsPlus )
{
Aig_Obj_t * pObj;
int v;
Aig_ManForEachObj( p->pMan, pObj, v )
if ( p->pVarNums[pObj->Id] )
p->pVarNums[pObj->Id] += nVarsPlus;
for ( v = 0; v < p->nLiterals; v++ )
p->pClauses[0][v] += 2*nVarsPlus;
}
/**Function*************************************************************
Synopsis [Writes CNF into a file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cnf_DataWriteIntoFile( Cnf_Dat_t * p, char * pFileName, int fReadable )
{
FILE * pFile;
......
......@@ -104,6 +104,7 @@ static int Abc_CommandEspresso ( Abc_Frame_t * pAbc, int argc, char ** arg
static int Abc_CommandGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
//static int Abc_CommandXyz ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandDouble ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandInter ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandQuaVar ( Abc_Frame_t * pAbc, int argc, char ** argv );
......@@ -281,6 +282,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "Various", "gen", Abc_CommandGen, 0 );
// Cmd_CommandAdd( pAbc, "Various", "xyz", Abc_CommandXyz, 1 );
Cmd_CommandAdd( pAbc, "Various", "double", Abc_CommandDouble, 1 );
Cmd_CommandAdd( pAbc, "Various", "inter", Abc_CommandInter, 1 );
Cmd_CommandAdd( pAbc, "Various", "test", Abc_CommandTest, 0 );
Cmd_CommandAdd( pAbc, "Various", "qvar", Abc_CommandQuaVar, 1 );
......@@ -6209,6 +6211,77 @@ usage:
SeeAlso []
***********************************************************************/
int Abc_CommandInter( Abc_Frame_t * pAbc, int argc, char ** argv )
{
FILE * pOut, * pErr;
Abc_Ntk_t * pNtk, * pNtkRes, * pNtk1, * pNtk2;
char ** pArgvNew;
int nArgcNew;
int c, fDelete1, fDelete2;
int fVerbose;
extern Abc_Ntk_t * Abc_NtkInter( Abc_Ntk_t * pNtkOn, Abc_Ntk_t * pNtkOff, int fVerbose );
pNtk = Abc_FrameReadNtk(pAbc);
pOut = Abc_FrameReadOut(pAbc);
pErr = Abc_FrameReadErr(pAbc);
// set defaults
fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
{
switch ( c )
{
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
pArgvNew = argv + globalUtilOptind;
nArgcNew = argc - globalUtilOptind;
if ( !Abc_NtkPrepareTwoNtks( pErr, pNtk, pArgvNew, nArgcNew, &pNtk1, &pNtk2, &fDelete1, &fDelete2 ) )
return 1;
if ( nArgcNew == 0 )
{
printf( "Deriving new circuit structure for the current network.\n" );
Abc_ObjXorFaninC( Abc_NtkPo(pNtk2,0), 0 );
}
pNtkRes = Abc_NtkInter( pNtk1, pNtk2, fVerbose );
if ( fDelete1 ) Abc_NtkDelete( pNtk1 );
if ( fDelete2 ) Abc_NtkDelete( pNtk2 );
if ( pNtkRes == NULL )
{
fprintf( pErr, "Command has failed.\n" );
return 0;
}
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
return 0;
usage:
fprintf( pErr, "usage: inter [-vh] <fileOnSet> <fileOffSet>\n" );
fprintf( pErr, "\t derives interpolant of two networks (onset and offset)\n" );
fprintf( pErr, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
fprintf( pErr, "\t-h : print the command usage\n");
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandDouble( Abc_Frame_t * pAbc, int argc, char ** argv )
{
FILE * pOut, * pErr;
......@@ -6311,7 +6384,7 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
extern Abc_Ntk_t * Abc_NtkDarToCnf( Abc_Ntk_t * pNtk, char * pFileName );
extern Abc_Ntk_t * Abc_NtkFilter( Abc_Ntk_t * pNtk );
// extern Abc_Ntk_t * Abc_NtkDarRetime( Abc_Ntk_t * pNtk, int nStepsMax, int fVerbose );
extern Abc_Ntk_t * Abc_NtkPcmTest( Abc_Ntk_t * pNtk, int fVerbose );
// extern Abc_Ntk_t * Abc_NtkPcmTest( Abc_Ntk_t * pNtk, int fVerbose );
extern Abc_NtkDarHaigRecord( Abc_Ntk_t * pNtk );
extern void Abc_NtkDarTestBlif( char * pFileName );
......@@ -6464,7 +6537,7 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
}
*/
/*
if ( Abc_NtkIsStrash(pNtk) )
{
fprintf( stdout, "Currently only works for logic circuits.\n" );
......@@ -6482,7 +6555,7 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
}
// replace the current network
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
*/
// Abc_NtkDarHaigRecord( pNtk );
// Abc_NtkDarClau( pNtk, nFrames, nLevels, fBmc, fVerbose, fVeryVerbose );
......
......@@ -1482,6 +1482,54 @@ Abc_Ntk_t * Abc_NtkDarEnlarge( Abc_Ntk_t * pNtk, int nFrames, int fVerbose )
return pNtkAig;
}
/**Function*************************************************************
Synopsis [Interplates two networks.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Ntk_t * Abc_NtkInter( Abc_Ntk_t * pNtkOn, Abc_Ntk_t * pNtkOff, int fVerbose )
{
extern Aig_Man_t * Aig_ManInter( Aig_Man_t * pManOn, Aig_Man_t * pManOff, int fVerbose );
Abc_Ntk_t * pNtkAig;
Aig_Man_t * pManOn, * pManOff, * pManAig;
if ( Abc_NtkCoNum(pNtkOn) != 1 || Abc_NtkCoNum(pNtkOff) != 1 )
{
printf( "Currently works only for single output networks.\n" );
return NULL;
}
if ( Abc_NtkCiNum(pNtkOn) != Abc_NtkCiNum(pNtkOff) )
{
printf( "The number of PIs should be the same.\n" );
return NULL;
}
// create internal AIGs
pManOn = Abc_NtkToDar( pNtkOn, 0 );
if ( pManOn == NULL )
return NULL;
pManOff = Abc_NtkToDar( pNtkOff, 0 );
if ( pManOff == NULL )
return NULL;
// derive the interpolant
pManAig = Aig_ManInter( pManOn, pManOff, fVerbose );
if ( pManAig == NULL )
{
printf( "Interpolant computation failed.\n" );
return NULL;
}
Aig_ManStop( pManOn );
Aig_ManStop( pManOff );
// create logic network
pNtkAig = Abc_NtkFromDar( pNtkOn, pManAig );
Aig_ManStop( pManAig );
return pNtkAig;
}
#include "ntl.h"
......
......@@ -100,7 +100,7 @@ Res_Man_t * Res_ManAlloc( Res_Par_t * pPars )
p->pPars = pPars;
p->pWin = Res_WinAlloc();
p->pSim = Res_SimAlloc( pPars->nSimWords );
p->pMan = Int_ManAlloc( 512 );
p->pMan = Int_ManAlloc();
p->vMem = Vec_IntAlloc( 0 );
p->vResubs = Vec_VecStart( pPars->nCands );
p->vResubsW = Vec_VecStart( pPars->nCands );
......
SRC += src/sat/bsat/satMem.c \
src/sat/bsat/satInter.c \
src/sat/bsat/satInterA.c \
src/sat/bsat/satSolver.c \
src/sat/bsat/satStore.c \
src/sat/bsat/satTrace.c \
......
......@@ -99,7 +99,7 @@ static inline void Int_ManProofSet( Int_Man_t * p, Sto_Cls_t * pCls, int n
SeeAlso []
***********************************************************************/
Int_Man_t * Int_ManAlloc( int nVarsAlloc )
Int_Man_t * Int_ManAlloc()
{
Int_Man_t * p;
// allocate the manager
......
......@@ -71,6 +71,7 @@ static inline int lit_var (lit l) { return l >> 1; }
static inline int lit_sign (lit l) { return l & 1; }
static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
static inline int lit_check(lit l, int n) { return l >= 0 && lit_var(l) < n; }
//=================================================================================================
......
/**CFile****************************************************************
FileName [pr.h]
FileName [satStore.h]
SystemName [ABC: Logic synthesis and verification system.]
......@@ -18,11 +18,13 @@
***********************************************************************/
#ifndef __PR_H__
#define __PR_H__
#ifndef __SAT_STORE_H__
#define __SAT_STORE_H__
#include "satSolver.h"
/*
The trace of SAT solving contains the original clause of the problem
The trace of SAT solving contains the original clauses of the problem
along with the learned clauses derived during SAT solving.
The first line of the resulting file contains 3 numbers instead of 2:
c <num_vars> <num_all_clauses> <num_root_clauses>
......@@ -54,7 +56,18 @@ extern "C" {
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
/*
typedef unsigned lit;
// variable/literal conversions (taken from MiniSat)
static inline lit toLit (int v) { return v + v; }
static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
static inline lit lit_neg (lit l) { return l ^ 1; }
static inline int lit_var (lit l) { return l >> 1; }
static inline int lit_sign (lit l) { return l & 1; }
static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
static inline int lit_check(lit l, int n) { return l >= 0 && lit_var(l) < n; }
*/
typedef struct Sto_Cls_t_ Sto_Cls_t;
struct Sto_Cls_t_
......@@ -87,16 +100,6 @@ struct Sto_Man_t_
char * pChunkLast; // the last memory chunk
};
// variable/literal conversions (taken from MiniSat)
static inline lit toLit (int v) { return v + v; }
static inline lit toLitCond(int v, int c) { return v + v + (c != 0); }
static inline lit lit_neg (lit l) { return l ^ 1; }
static inline int lit_var (lit l) { return l >> 1; }
static inline int lit_sign (lit l) { return l & 1; }
static inline int lit_print(lit l) { return lit_sign(l)? -lit_var(l)-1 : lit_var(l)+1; }
static inline lit lit_read (int s) { return s > 0 ? toLit(s-1) : lit_neg(toLit(-s-1)); }
static inline int lit_check(lit l, int n) { return l >= 0 && lit_var(l) < n; }
// iterators through the clauses
#define Sto_ManForEachClause( p, pCls ) for( pCls = p->pHead; pCls; pCls = pCls->pNext )
#define Sto_ManForEachClauseRoot( p, pCls ) for( pCls = p->pHead; pCls && pCls->fRoot; pCls = pCls->pNext )
......@@ -121,10 +124,16 @@ extern Sto_Man_t * Sto_ManLoadClauses( char * pFileName );
/*=== satInter.c ==========================================================*/
typedef struct Int_Man_t_ Int_Man_t;
extern Int_Man_t * Int_ManAlloc( int nVarsAlloc );
extern Int_Man_t * Int_ManAlloc();
extern void Int_ManFree( Int_Man_t * p );
extern int Int_ManInterpolate( Int_Man_t * p, Sto_Man_t * pCnf, int fVerbose, unsigned ** ppResult );
/*=== satInterA.c ==========================================================*/
typedef struct Inta_Man_t_ Inta_Man_t;
extern Inta_Man_t * Inta_ManAlloc();
extern void Inta_ManFree( Inta_Man_t * p );
extern void * Inta_ManInterpolate( Inta_Man_t * p, Sto_Man_t * pCnf, void * vVarsAB, int fVerbose );
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment