Commit bb8e1808 by Mathias Soeken

New search strategy in BMS.

parent 452303b7
...@@ -273,6 +273,8 @@ struct Ses_Man_t_ ...@@ -273,6 +273,8 @@ struct Ses_Man_t_
int nSatCalls; /* number of SAT calls */ int nSatCalls; /* number of SAT calls */
int nUnsatCalls; /* number of UNSAT calls */ int nUnsatCalls; /* number of UNSAT calls */
int nUndefCalls; /* number of UNDEF calls */ int nUndefCalls; /* number of UNDEF calls */
int nDebugOffset; /* for debug printing */
}; };
/*********************************************************************** /***********************************************************************
...@@ -1333,14 +1335,13 @@ static int Ses_ManCreateClauses( Ses_Man_t * pSes ) ...@@ -1333,14 +1335,13 @@ static int Ses_ManCreateClauses( Ses_Man_t * pSes )
} }
/* EXTRA stair decomposition */ /* EXTRA stair decomposition */
if ( Vec_IntSize( pSes->vStairDecVars ) ) if (Vec_IntSize( pSes->vStairDecVars ) )
{ {
Vec_IntForEachEntry( pSes->vStairDecVars, j, i ) Vec_IntForEachEntry( pSes->vStairDecVars, j, i )
{ {
if ( pSes->nGates - 2 - i < 0 ) if ( pSes->nGates - 2 - i < j )
{ {
Vec_IntFree( vLits ); continue;
return 0;
} }
Vec_IntPush( pSes->vAssump, Abc_Var2Lit( Ses_ManSelectVar( pSes, pSes->nGates - 1 - i, j, pSes->nSpecVars + pSes->nGates - 2 - i ), 0 ) ); Vec_IntPush( pSes->vAssump, Abc_Var2Lit( Ses_ManSelectVar( pSes, pSes->nGates - 1 - i, j, pSes->nSpecVars + pSes->nGates - 2 - i ), 0 ) );
...@@ -2195,135 +2196,139 @@ static int Ses_ManFindNetworkExact( Ses_Man_t * pSes, int nGates ) ...@@ -2195,135 +2196,139 @@ static int Ses_ManFindNetworkExact( Ses_Man_t * pSes, int nGates )
return 2; /* UNSAT continue */ return 2; /* UNSAT continue */
} }
static int Ses_ManFindMinimumSize( Ses_Man_t * pSes ) // is there a network for a given number of gates
/* return: (2: continue, 1: found, 0: gave up) */
static int Ses_ManFindNetworkExactCEGAR( Ses_Man_t * pSes, int nGates, char ** pSol )
{ {
int nGates = pSes->nStartGates, fRes, fSat, nOffset = 0, fFirst = 1, iMint; int fFirst = 0, fRes, iMint, fSat;
char * pSol;
word pTruth[4]; word pTruth[4];
/* store whether call was unsuccessful due to resource limit and not due to impossible constraint */ /* debug */
pSes->fHitResLimit = 0; Abc_DebugErase( pSes->nDebugOffset + ( nGates > 10 ? 5 : 4 ), pSes->fVeryVerbose && !fFirst );
Abc_DebugPrintIntInt( " (%d/%d)", nGates, pSes->nMaxGates, pSes->fVeryVerbose );
/* do the arrival times allow for a network? */ /* do #gates and max depth allow for a network? */
if ( pSes->nMaxDepth != -1 && pSes->pArrTimeProfile ) if ( !Ses_CheckGatesConsistency( pSes, nGates ) )
return 0;
fRes = Ses_ManFindNetworkExact( pSes, nGates );
if ( fRes != 1 ) return fRes;
while ( true )
{ {
if ( !Ses_CheckDepthConsistency( pSes ) ) *pSol = Ses_ManExtractSolution( pSes );
return 0; Abc_TtXor( pTruth, Ses_ManDeriveTruth( pSes, *pSol, 0 ), pSes->pSpec, pSes->nSpecWords, 0 );
Ses_ManComputeMaxGates( pSes ); iMint = Abc_TtFindFirstBit( pTruth, pSes->nSpecVars );
nOffset = pSes->nMaxGates >= 10 ? 3 : 2;
if ( iMint == -1 )
{
assert( fRes == 1 );
return 1;
}
ABC_FREE( *pSol );
//Abc_TtSetBit( pSes->pTtValues, iMint - 1 );
if ( !Ses_ManCreateTruthTableClause( pSes, iMint - 1 ) ) /* UNSAT, continue */
return 2;
if ( ( fSat = Ses_ManSolve( pSes ) ) == 1 ) continue;
return ( fSat == 2 ) ? 0 : 2;
} }
}
// find minimum size by increasing the number of gates
static char * Ses_ManFindMinimumSizeBottomUp( Ses_Man_t * pSes )
{
int nGates = pSes->nStartGates, fRes;
char * pSol = NULL;
/* store whether call was unsuccessful due to resource limit and not due to impossible constraint */
pSes->fHitResLimit = 0;
pSes->nDebugOffset = pSes->nMaxGates >= 10 ? 3 : 2;
/* adjust number of gates if there is a stair decomposition */
if ( Vec_IntSize( pSes->vStairDecVars ) ) if ( Vec_IntSize( pSes->vStairDecVars ) )
nGates = Abc_MaxInt( nGates, Vec_IntSize( pSes->vStairDecVars ) - 1 ); nGates = Abc_MaxInt( nGates, Vec_IntSize( pSes->vStairDecVars ) - 1 );
//Ses_ManStoreDepthAndArrivalTimes( pSes ); //Ses_ManStoreDepthAndArrivalTimes( pSes );
//memset( pSes->pTtValues, (word)~0, 4 * sizeof( word ) );
memset( pSes->pTtValues, 0, 4 * sizeof( word ) ); memset( pSes->pTtValues, 0, 4 * sizeof( word ) );
while ( true ) while ( true )
{ {
++nGates; ++nGates;
Abc_DebugErase( nOffset + ( nGates > 10 ? 5 : 4 ), pSes->fVeryVerbose && !fFirst ); fRes = Ses_ManFindNetworkExactCEGAR( pSes, nGates, &pSol );
Abc_DebugPrintIntInt( " (%d/%d)", nGates, pSes->nMaxGates, pSes->fVeryVerbose );
fFirst = 0;
//Ses_AdjustDepthAndArrivalTimes( pSes, nGates ); printf( "fRes = %d\n", fRes );
/* do #gates and max depth allow for a network? */ if ( fRes == 0 )
if ( !Ses_CheckGatesConsistency( pSes, nGates ) )
{ {
fRes = 0; pSes->fHitResLimit = 1;
break; break;
} }
else if ( fRes == 1 )
break;
}
fRes = Ses_ManFindNetworkExact( pSes, nGates ); Abc_DebugErase( pSes->nDebugOffset + ( nGates >= 10 ? 5 : 4 ), pSes->fVeryVerbose );
if ( fRes == 2 ) continue; /* unsat */
if ( fRes == 0 ) break; /* undef */
while ( true )
{
pSol = Ses_ManExtractSolution( pSes );
Abc_TtXor( pTruth, Ses_ManDeriveTruth( pSes, pSol, 0 ), pSes->pSpec, pSes->nSpecWords, 0 );
ABC_FREE( pSol );
iMint = Abc_TtFindFirstBit( pTruth, pSes->nSpecVars );
if ( iMint == -1 ) return fRes ? pSol : NULL;
{ }
assert( fRes == 1 );
break;
}
assert( iMint ); static char * Ses_ManFindMinimumSizeTopDown( Ses_Man_t * pSes, int nMinGates )
//Abc_TtSetBit( pSes->pTtValues, iMint - 1 ); {
if ( !Ses_ManCreateTruthTableClause( pSes, iMint - 1 ) ) /* UNSAT, continue */ int nGates = pSes->nMaxGates, fRes;
{ char * pSol = NULL, * pSol2 = NULL;
fRes = 2;
break;
}
if ( ( fSat = Ses_ManSolve( pSes ) ) == 1 ) continue; pSes->fHitResLimit = 0;
if ( fSat == 0 ) while ( true )
fRes = 2; {
else if ( fSat == 2 ) fRes = Ses_ManFindNetworkExactCEGAR( pSes, nGates, &pSol2 );
{
pSes->fHitResLimit = 1;
fRes = 0;
}
if ( fRes == 0 )
{
pSes->fHitResLimit = 1;
break; break;
} }
else if ( fRes == 2 )
break;
pSol = pSol2;
if ( fRes != 2 ) if ( nGates == nMinGates )
break; break;
/* /\* solve *\/ */ --nGates;
/* timeStart = Abc_Clock(); */ }
/* Ses_ManCreateVars( pSes, nGates ); */
/* f = Ses_ManCreateDepthClauses( pSes ); */
/* pSes->timeInstance += ( Abc_Clock() - timeStart ); */
/* if ( !f ) continue; /\* proven UNSAT while creating clauses *\/ */
/* /\* first solve *\/ */
/* fSat = Ses_ManSolve( pSes ); */
/* if ( fSat == 0 ) */
/* continue; /\* UNSAT, continue with next # of gates *\/ */
/* else if ( fSat == 2 ) */
/* { */
/* pSes->fHitResLimit = 1; */
/* fRes = 0; */
/* break; */
/* } */
/* timeStart = Abc_Clock(); */ return pSol;
/* f = Ses_ManCreateClauses( pSes ); */ }
/* pSes->timeInstance += ( Abc_Clock() - timeStart ); */
/* if ( !f ) continue; /\* proven UNSAT while creating clauses *\/ */
/* fSat = Ses_ManSolve( pSes ); */ static char * Ses_ManFindMinimumSize( Ses_Man_t * pSes )
/* if ( fSat == 1 ) */ {
/* { */ char * pSol;
/* fRes = 1; */
/* break; */
/* } */
/* else if ( fSat == 2 ) */
/* { */
/* pSes->fHitResLimit = 1; */
/* fRes = 0; */
/* break; */
/* } */
/* UNSAT => continue */ /* do the arrival times allow for a network? */
if ( pSes->nMaxDepth != -1 && pSes->pArrTimeProfile )
{
if ( !Ses_CheckDepthConsistency( pSes ) )
return 0;
Ses_ManComputeMaxGates( pSes );
} }
//Ses_ManRestoreDepthAndArrivalTimes( pSes ); pSol = Ses_ManFindMinimumSizeBottomUp( pSes );
Abc_DebugErase( nOffset + ( nGates >= 10 ? 5 : 4 ), pSes->fVeryVerbose ); if ( !pSol && pSes->fHitResLimit && pSes->nGates != pSes->nMaxGates )
return fRes; return Ses_ManFindMinimumSizeTopDown( pSes, pSes->nGates + 1 );
else
return pSol;
} }
/**Function************************************************************* /**Function*************************************************************
Synopsis [Find minimum size networks with a SAT solver.] Synopsis [Find minimum size networks with a SAT solver.]
...@@ -2356,9 +2361,8 @@ Abc_Ntk_t * Abc_NtkFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth ...@@ -2356,9 +2361,8 @@ Abc_Ntk_t * Abc_NtkFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth
if ( fVerbose ) if ( fVerbose )
Ses_ManPrintFuncs( pSes ); Ses_ManPrintFuncs( pSes );
if ( Ses_ManFindMinimumSize( pSes ) ) if ( ( pSol = Ses_ManFindMinimumSize( pSes ) ) != NULL )
{ {
pSol = Ses_ManExtractSolution( pSes );
pNtk = Ses_ManExtractNtk( pSol ); pNtk = Ses_ManExtractNtk( pSol );
ABC_FREE( pSol ); ABC_FREE( pSol );
} }
...@@ -2395,9 +2399,8 @@ Gia_Man_t * Gia_ManFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth ...@@ -2395,9 +2399,8 @@ Gia_Man_t * Gia_ManFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth
if ( fVerbose ) if ( fVerbose )
Ses_ManPrintFuncs( pSes ); Ses_ManPrintFuncs( pSes );
if ( Ses_ManFindMinimumSize( pSes ) ) if ( ( pSol = Ses_ManFindMinimumSize( pSes ) ) != NULL )
{ {
pSol = Ses_ManExtractSolution( pSes );
pGia = Ses_ManExtractGia( pSol ); pGia = Ses_ManExtractGia( pSol );
ABC_FREE( pSol ); ABC_FREE( pSol );
} }
...@@ -2645,7 +2648,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char * ...@@ -2645,7 +2648,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char *
{ {
int i, nMaxArrival, nDelta, l; int i, nMaxArrival, nDelta, l;
Ses_Man_t * pSes = NULL; Ses_Man_t * pSes = NULL;
char * pSol = NULL, * p; char * pSol = NULL, * pSol2 = NULL, * p;
int pNormalArrTime[8]; int pNormalArrTime[8];
int Delay = ABC_INFINITY, nMaxDepth, fResLimit; int Delay = ABC_INFINITY, nMaxDepth, fResLimit;
abctime timeStart = Abc_Clock(), timeStartExact; abctime timeStart = Abc_Clock(), timeStartExact;
...@@ -2730,7 +2733,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char * ...@@ -2730,7 +2733,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char *
fflush( stdout ); fflush( stdout );
} }
if ( Ses_ManFindMinimumSize( pSes ) ) if ( ( pSol2 = Ses_ManFindMinimumSize( pSes ) ) != NULL )
{ {
if ( s_pSesStore->fVeryVerbose ) if ( s_pSesStore->fVeryVerbose )
{ {
...@@ -2739,7 +2742,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char * ...@@ -2739,7 +2742,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char *
} }
if ( pSol ) if ( pSol )
ABC_FREE( pSol ); ABC_FREE( pSol );
pSol = Ses_ManExtractSolution( pSes ); pSol = pSol2;
pSes->nMaxDepth--; pSes->nMaxDepth--;
} }
else else
......
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