58 return Abc_Var2Lit( nSize * y + x, 0 );
62 return Abc_Var2Lit( nSize * (nSize + 1) + nSize * x + y, 0 );
69 int x, y, nVars = 2*nSize*(nSize+1);
70 for ( x = 0; x < nVars; x++ )
71 Gia_ManAppendCi( pGia );
76 for ( x = 1; x <= nSize; x++ )
79 for ( y = 1; y <= nSize; y++ )
84 for ( x = 1; x <= nSize; x++ )
91 Gia_ManAppendCo( pGia, pNodes[nSize] );
119 Vec_Int_t * vEdges = Vec_IntAlloc( 4*n*(n-1) );
121 for ( i = 0; i < n; i++ )
123 for ( k = 0; k < n-1; k++ )
124 Vec_IntPushTwo( vEdges, i*n+k, i*n+k+1 );
125 if ( i == n-1 )
break;
126 for ( k = 0; k < n; k++ )
127 Vec_IntPushTwo( vEdges, i*n+k, i*n+k+n );
134 Vec_Int_t * vLife = Vec_IntStartFull( 2*n*n );
138 if ( Vec_IntEntry(vLife, 2*One) == -1 )
139 Vec_IntWriteEntry(vLife, 2*One, i/2);
140 if ( Vec_IntEntry(vLife, 2*Two) == -1 )
141 Vec_IntWriteEntry(vLife, 2*Two, i/2);
142 Vec_IntWriteEntry(vLife, 2*One+1, i/2);
143 Vec_IntWriteEntry(vLife, 2*Two+1, i/2);
150 Vec_Wec_t * vFronts = Vec_WecAlloc( Vec_IntSize(vEdges)/2 );
151 Vec_Int_t * vTemp = Vec_IntAlloc( Vec_IntSize(vLife)/2 );
153 Vec_WecPushLevel(vFronts);
154 for ( e = 0; e < Vec_IntSize(vEdges)/2; e++ )
156 int * pNodes = Vec_IntEntryP(vEdges, 2*e);
157 for ( n = 0; n < 2; n++ )
158 if ( Vec_IntEntry(vLife, 2*pNodes[n]) == e )
159 Vec_IntPush( vTemp, pNodes[n] );
160 else if ( Vec_IntEntry(vLife, 2*pNodes[n]+1) == e )
161 Vec_IntRemove( vTemp, pNodes[n] );
162 Vec_IntAppend( Vec_WecPushLevel(vFronts), vTemp );
165 Vec_IntFree( vTemp );
184 int e, nEdges = Vec_IntSize(vEdges)/2;
185 for ( y = 0; y < 13; y++ )
186 for ( x = 0; x < 13; x++ )
187 if ( y % 4 == 0 && x % 4 == 0 )
191 for ( e = 0; e < nEdges; e++ )
193 int * pNodes = Vec_IntEntryP(vEdges, 2*e);
194 int y0 = 4*(pNodes[0]/4);
195 int x0 = 4*(pNodes[0]%4);
196 int y1 = 4*(pNodes[1]/4);
197 int x1 = 4*(pNodes[1]%4);
202 for ( x = x0+1; x < x1; x++ )
207 for ( y = y0+1; y < y1; y++ )
212 for ( y = 0; y < 13; y++, printf(
"\n") )
213 for ( x = 0; x < 13; x++ )
214 printf(
"%c", Box[y][x] );
215 printf(
"\n\n=================================\n\n" );
221 int e, nEdges = Vec_IntSize(vEdges)/2;
222 for ( y = 0; y < 17; y++ )
223 for ( x = 0; x < 17; x++ )
224 if ( y % 4 == 0 && x % 4 == 0 )
228 for ( e = 0; e < nEdges; e++ )
230 int * pNodes = Vec_IntEntryP(vEdges, 2*e);
231 int y0 = 4*(pNodes[0]/5);
232 int x0 = 4*(pNodes[0]%5);
233 int y1 = 4*(pNodes[1]/5);
234 int x1 = 4*(pNodes[1]%5);
239 for ( x = x0+1; x < x1; x++ )
244 for ( y = y0+1; y < y1; y++ )
249 for ( y = 0; y < 17; y++, printf(
"\n") )
250 for ( x = 0; x < 17; x++ )
251 printf(
"%c", Box[y][x] );
252 printf(
"\n\n=================================\n\n" );
274 if ( pCache[Lev][Node] != -1.0 )
275 return pCache[Lev][Node];
277 Res0 =
Abc_GraphCountPaths_rec( Lev+1, Vec_IntEntry( Vec_WecEntry(vNodes, Lev), 2*Node ), vNodes, pCache, pBuffer, vEdges );
279 Res1 =
Abc_GraphCountPaths_rec( Lev+1, Vec_IntEntry( Vec_WecEntry(vNodes, Lev), 2*Node+1 ), vNodes, pCache, pBuffer, vEdges );
280 return (pCache[Lev][Node] = Res0 + Res1);
284 int i, k, pBuffer[1000] = {0};
285 double ** pCache =
ABC_ALLOC(
double *, Vec_WecSize(vNodes) );
289 pCache[i] =
ABC_ALLOC(
double, Vec_IntSize(vLevel) );
290 for ( k = 0; k < Vec_IntSize(vLevel); k++ )
294 for ( i = 0; i < Vec_WecSize(vNodes); i++ )
318 if ( pCache[Lev][Node] != -1 )
319 return pCache[Lev][Node];
321 Res0 =
Abc_GraphDeriveGia_rec(
p, Lev+1, Vec_IntEntry( Vec_WecEntry(vNodes, Lev), 2*Node ), vNodes, pCache, pBuffer, vEdges );
323 Res1 =
Abc_GraphDeriveGia_rec(
p, Lev+1, Vec_IntEntry( Vec_WecEntry(vNodes, Lev), 2*Node+1 ), vNodes, pCache, pBuffer, vEdges );
324 return ( pCache[Lev][Node] =
Gia_ManHashMux(
p, Gia_Obj2Lit(
p, Gia_ManCi(
p, Lev)), Res1, Res0) );
329 int i, Value, pBuffer[1000] = {0};
333 p->pName = Abc_UtilStrsav(
"paths");
334 for ( i = 0; i < Vec_IntSize(vEdges)/2; i++ )
338 pCache =
ABC_ALLOC(
int *, Vec_WecSize(vNodes) );
340 pCache[i] =
ABC_FALLOC(
int, Vec_IntSize(vLevel) );
342 for ( i = 0; i < Vec_WecSize(vNodes); i++ )
346 Gia_ManAppendCo(
p, Value );
355 sprintf( pFileName,
"grid_%dx%d_e%03d.aig", Size, Size, Vec_IntSize(vEdges)/2 );
358 printf(
"Finished dumping AIG into file \"%s\".\n", pFileName );
374 Vec_Int_t * vFront = Vec_WecEntry( vFronts, e );
375 Vec_Int_t * vFront2 = Vec_WecEntry( vFronts, e+1 );
376 int * pNodes = Vec_IntEntryP(vEdges, 2*e);
377 int nNodes = Vec_IntSize(vLife)/2;
378 int i, n, Node, First, pEquivs[2];
379 assert( pNodes[0] < pNodes[1] );
380 if ( fVerbose ) printf(
"Edge = %d. Arc = %d.\nCurrent state: ", e, x );
383 pFront[Node] = Vec_IntEntry(vState, i);
384 if ( fVerbose ) printf(
"%d(%d) ", pFront[Node] & 0xFFFF, pFront[Node] >> 16 );
386 if ( fVerbose ) printf(
"\n" );
387 for ( n = 0; n < 2; n++ )
388 if ( Vec_IntEntry(vLife, 2*pNodes[n]) == e )
389 pFront[pNodes[n]] = pNodes[n];
392 if ( (pFront[pNodes[0]] & 0xFFFF) == (pFront[pNodes[1]] & 0xFFFF) )
394 for ( n = 0; n < 2; n++ )
396 int Degree = pFront[pNodes[n]] >> 16;
397 if ( (pNodes[n] == 0 || pNodes[n] == nNodes-1) ? Degree >= 1 : Degree >= 2 )
399 pFront[pNodes[n]] += (1 << 16);
403 pEquivs[0] = pFront[pNodes[0]] & 0xFFFF;
404 pEquivs[1] = pFront[pNodes[1]] & 0xFFFF;
406 for ( n = 0; n < 2; n++ )
407 if ( Vec_IntEntry(vLife, 2*pNodes[n]+1) == e )
409 int Degree = pFront[pNodes[n]] >> 16;
410 if ( (pNodes[n] == 0 || pNodes[n] == nNodes-1) ? Degree != 1 : Degree != 0 && Degree != 2 )
416 assert( Node != pNodes[n] );
417 if ( (pFront[Node] & 0xFFFF) == pEquivs[n] )
421 pFront[Node] = (pFront[Node] & 0xFFFF0000) | First;
432 if ( (pFront[Node] & 0xFFFF) == pEquivs[0] || (pFront[Node] & 0xFFFF) == pEquivs[1] )
436 pFront[Node] = (pFront[Node] & 0xFFFF0000) | First;
440 Vec_IntClear( vStateNew );
441 if ( fVerbose ) printf(
"Next state: " );
444 Vec_IntPush( vStateNew, pFront[Node] );
445 if ( fVerbose ) printf(
"%d(%d) ", pFront[Node] & 0xFFFF, pFront[Node] >> 16 );
447 if ( fVerbose ) printf(
"\n\n" );
454 int nEdges = Vec_IntSize(vEdges)/2;
455 int nNodes = Vec_IntSize(vLife)/2;
456 Vec_Wec_t * vNodes = Vec_WecAlloc( nEdges );
457 Vec_Int_t * vStateNew = Vec_IntAlloc( nNodes );
458 Vec_Int_t * vStateCount = Vec_IntAlloc( nEdges );
459 int e, s, x, Next, * pFront =
ABC_CALLOC(
int, nNodes );
462 Hsh_VecManAdd( pThis, vStateNew );
463 for ( e = 0; e < nEdges; e++ )
465 Vec_Int_t * vNode = Vec_WecPushLevel(vNodes);
466 int nStates = Hsh_VecSize( pThis );
467 Vec_IntPush( vStateCount, nStates );
471 printf(
"Processing edge %d = {%d %d}\n", e, Vec_IntEntry(vEdges, 2*e), Vec_IntEntry(vEdges, 2*e+1) );
472 printf(
"Frontier: " ); Vec_IntPrint( Vec_WecEntry(vFronts, e) );
475 for ( s = 0; s < nStates; s++ )
477 Vec_Int_t * vState = Hsh_VecReadEntry(pThis, s);
478 for ( x = 0; x < 2; x++ )
480 Next =
Abc_GraphBuildState(vState, e, x, vEdges, vLife, vFronts, pFront, vStateNew, fVerbose);
483 if ( e == nEdges - 1 )
486 Next = Hsh_VecManAdd( pNext, vStateNew );
488 if ( fVerbose ) printf(
"Return value = %d\n", Next );
489 Vec_IntPush( vNode, Next );
492 Hsh_VecManStop( pThis );
494 pNext = Hsh_VecManStart( 1000 );
497 printf(
"States = %8d Paths = %24.0f ", Vec_IntSum(vStateCount), nPaths );
498 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
500 Vec_IntPrint( vStateCount );
503 Vec_WecFree( vNodes );
504 Vec_IntFree( vStateNew );
505 Vec_IntFree( vStateCount );
506 Hsh_VecManStop( pThis );
507 Hsh_VecManStop( pNext );
519 Vec_WecFree( vFronts );
520 Vec_IntFree( vLife );
521 Vec_IntFree( vEdges );
538 double Res = 0;
int i;
539 for ( i = 0; i < 64; i++ )
549 int i, k, iLit, nVars = Gia_ManCiNum(pGia);
550 int iCiVarBeg = pCnf->
nVars - nVars;
559 for ( i = 0; i < pCnf->
nClauses; i++ )
563 Vec_IntClear( vLits );
564 for ( k = 0; k < nVars; k++ )
565 Vec_IntPush( vLits, Abc_Var2Lit(iCiVarBeg+k, 1) );
567 for ( i = 0; i < nIters; i++ )
575 Vec_IntWriteEntry( vLits, k, Abc_LitNot(iLit) );
579 Vec_IntWriteEntry( vLits, k, Abc_LitNot(iLit) );
583 if ( !Abc_LitIsCompl(iLit) )
584 Mint2 |= ((
word)1) << (nVars-1-k);
592 Total = (Mint2-Mint1)/nIters;
598 Vec_IntFree( vLits );
#define ABC_FALLOC(type, num)
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
#define sat_solver_addclause
struct Cnf_Dat_t_ Cnf_Dat_t
void Cnf_DataFree(Cnf_Dat_t *p)
void Gia_ManStop(Gia_Man_t *p)
void Gia_ManHashAlloc(Gia_Man_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
int Gia_ManHashOr(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Man_t_ Gia_Man_t
int Gia_ManHashMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
void Gia_AigerWrite(Gia_Man_t *p, char *pFileName, int fWriteSymbols, int fCompact, int fWriteNewLine)
unsigned __int64 word
DECLARATIONS ///.
sat_solver * sat_solver_new(void)
void sat_solver_setnvars(sat_solver *s, int n)
void sat_solver_delete(sat_solver *s)
int sat_solver_solve_lexsat(sat_solver *s, int *pLits, int nLits)
struct Hsh_VecMan_t_ Hsh_VecMan_t
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.