107{
111 int Me[102][102] = {{0}};
112 int pN[102][2] = {{0}};
113 int I = Gia_ManPiNum(
p);
114 int G = I + Gia_ManAndNum(
p);
115 int i, x, y, t, g, c, status, RetValue, Lit, iVar, nClauses = 0;
116
117 assert( X <= 100 && Y <= 100 && T <= 100 && G <= 100 );
118
119
120 for ( i = 0; i < I; i++ )
121 pN[i][0] = pN[i][1] = -1;
123 {
124 pN[i-1][0] = Gia_ObjFaninId0(pObj, i)-1;
125 pN[i-1][1] = Gia_ObjFaninId1(pObj, i)-1;
126 }
127 if ( fVerbose )
128 {
129 printf(
"The graph has %d inputs: ", Gia_ManPiNum(
p) );
130 for ( i = 0; i < I; i++ )
131 printf( "%c ", 'a' + i );
132 printf(
" and %d nodes: ", Gia_ManAndNum(
p) );
133 for ( i = I; i < G; i++ )
134 printf( "%c=%c%c ", 'a' + i, 'a' + pN[i][0] , 'a' + pN[i][1] );
135 printf( "\n" );
136 }
137
138
139
140 iVar = 0;
141 for ( y = 0; y < Y; y++ )
142 for ( x = 0; x < X; x++ )
143 {
144
145 Me[x][y] = iVar;
146 iVar += T + G +
NCPARS + 1;
147 }
148 Me[101][100] = T;
149 Me[101][101] = G;
150 if ( fVerbose )
151 printf(
"SAT variable count is %d (%d time vars + %d graph vars + %d config vars + %d aux vars)\n", iVar, X*Y*T, X*Y*G, X*Y*
NCPARS, X*Y );
152
153
154
155
156 for ( x = 0; x < X; x++ )
157 for ( y = 0; y < Y; y++ )
158 {
159 int iTVar = Bmc_MeshTVar( Me, x, y );
160 int iGVar = Bmc_MeshGVar( Me, x, y );
161
162 if ( x == 0 || x == X-1 || y == 0 || y == Y-1 )
163 {
164
165 for ( t = 0; t < T; t++ )
166 {
167 Lit = Abc_Var2Lit( iTVar+t, (int)(t > 0) );
169 }
170
171 for ( g = I; g < G; g++ )
172 {
173 Lit = Abc_Var2Lit( iGVar+g, 1 );
175 }
176 }
177 else
178 {
179 Lit = Abc_Var2Lit( iTVar, 1 );
181 }
182 }
183 for ( x = 1; x < X-1; x++ )
184 for ( y = 1; y < Y-1; y++ )
185 {
186 int pLits[100], nLits;
187
188 int iTVar = Bmc_MeshTVar( Me, x, y );
189 int iGVar = Bmc_MeshGVar( Me, x, y );
190 int iCVar = Bmc_MeshCVar( Me, x, y );
191 int iUVar = Bmc_MeshUVar( Me, x, y );
192
193
194 int iTVars[4];
195 int iGVars[4];
196
197 iTVars[0] = Bmc_MeshTVar( Me, x-1, y );
198 iGVars[0] = Bmc_MeshGVar( Me, x-1, y );
199
200 iTVars[1] = Bmc_MeshTVar( Me, x, y-1 );
201 iGVars[1] = Bmc_MeshGVar( Me, x, y-1 );
202
203 iTVars[2] = Bmc_MeshTVar( Me, x+1, y );
204 iGVars[2] = Bmc_MeshGVar( Me, x+1, y );
205
206 iTVars[3] = Bmc_MeshTVar( Me, x, y+1 );
207 iGVars[3] = Bmc_MeshGVar( Me, x, y+1 );
208
209
210 for ( g = 0; g < G; g++ )
211 {
212 pLits[0] = Abc_Var2Lit( iGVar+g, 1 );
213 pLits[1] = Abc_Var2Lit( iUVar, 0 );
215 nClauses++;
216 }
217
218
219 pLits[0] = Abc_Var2Lit( iUVar, 1 );
220 for ( t = 1; t < T; t++ )
221 pLits[t] = Abc_Var2Lit( iTVar+t, 0 );
223 nClauses++;
224
225
226 pLits[0] = Abc_Var2Lit( iUVar, 1 );
227 for ( c = 0; c <
NCPARS; c++ )
228 pLits[c+1] = Abc_Var2Lit( iCVar+c, 0 );
230 nClauses++;
231
232
233 for ( t = 1; t < T; t++ )
234 {
235 int Conf[12][2] = {{0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3}, {1, 0}, {2, 0}, {3, 0}, {2, 1}, {3, 1}, {3, 2}};
236
237 for ( g = 0; g < G; g++ )
238 for ( c = 0; c < 4; c++ )
239 {
240 nLits = 0;
241 pLits[ nLits++ ] = Abc_Var2Lit( iTVar+t, 1 );
242 pLits[ nLits++ ] = Abc_Var2Lit( iGVar+g, 1 );
243 pLits[ nLits++ ] = Abc_Var2Lit( iCVar+c, 1 );
244 pLits[ nLits++ ] = Abc_Var2Lit( iTVars[c]+t-1, 0 );
246
247 nLits = 0;
248 pLits[ nLits++ ] = Abc_Var2Lit( iTVar+t, 1 );
249 pLits[ nLits++ ] = Abc_Var2Lit( iGVar+g, 1 );
250 pLits[ nLits++ ] = Abc_Var2Lit( iCVar+c, 1 );
251 pLits[ nLits++ ] = Abc_Var2Lit( iGVars[c]+g, 0 );
253
254 nClauses += 2;
255 }
256 for ( g = 0; g < I; g++ )
257 for ( c = 4; c <
NCPARS; c++ )
258 {
259 pLits[0] = Abc_Var2Lit( iGVar+g, 1 );
260 pLits[1] = Abc_Var2Lit( iCVar+c, 1 );
262 nClauses++;
263 }
264
265 for ( g = I; g < G; g++ )
266 for ( c = 0; c < 12; c++ )
267 {
268 assert( pN[g][0] >= 0 && pN[g][1] >= 0 );
269
270 nLits = 0;
271 pLits[ nLits++ ] = Abc_Var2Lit( iTVar+t, 1 );
272 pLits[ nLits++ ] = Abc_Var2Lit( iGVar+g, 1 );
273 pLits[ nLits++ ] = Abc_Var2Lit( iCVar+c+4, 1 );
274 pLits[ nLits++ ] = Abc_Var2Lit( iTVars[Conf[c][0]]+t-1, 0 );
276
277 nLits = 0;
278 pLits[ nLits++ ] = Abc_Var2Lit( iTVar+t, 1 );
279 pLits[ nLits++ ] = Abc_Var2Lit( iGVar+g, 1 );
280 pLits[ nLits++ ] = Abc_Var2Lit( iCVar+c+4, 1 );
281 pLits[ nLits++ ] = Abc_Var2Lit( iTVars[Conf[c][1]]+t-1, 0 );
283
284
285 nLits = 0;
286 pLits[ nLits++ ] = Abc_Var2Lit( iTVar+t, 1 );
287 pLits[ nLits++ ] = Abc_Var2Lit( iGVar+g, 1 );
288 pLits[ nLits++ ] = Abc_Var2Lit( iCVar+c+4, 1 );
289 pLits[ nLits++ ] = Abc_Var2Lit( iGVars[Conf[c][0]]+pN[g][0], 0 );
291
292 nLits = 0;
293 pLits[ nLits++ ] = Abc_Var2Lit( iTVar+t, 1 );
294 pLits[ nLits++ ] = Abc_Var2Lit( iGVar+g, 1 );
295 pLits[ nLits++ ] = Abc_Var2Lit( iCVar+c+4, 1 );
296 pLits[ nLits++ ] = Abc_Var2Lit( iGVars[Conf[c][1]]+pN[g][1], 0 );
298
299 nClauses += 4;
300 }
301 }
302 }
303
304
305 {
306 int iGVar = Bmc_MeshGVar( Me, 1, 1 ) + G-1;
307 Lit = Abc_Var2Lit( iGVar, 0 );
309 if ( RetValue == 0 )
310 {
311 printf( "Problem has no solution. " );
312 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
314 return;
315 }
316 }
317
318 if ( fVerbose )
319 printf( "Finished adding %d clauses. Started solving...\n", nClauses );
320
321 while ( 1 )
322 {
323 int nAddClauses = 0;
326 {
327 printf( "Problem has no solution. " );
328 break;
329 }
331 {
332 printf( "Computation timed out. " );
333 break;
334 }
336
337 for ( x = 0; x < X; x++ )
338 for ( y = 0; y < Y; y++ )
339 {
340 if ( x == 0 || x == X-1 || y == 0 || y == Y-1 )
341 {
342 int iGVar = Bmc_MeshGVar( Me, x, y );
344 }
345 else
346 {
347 int iTVar = Bmc_MeshTVar( Me, x, y );
348 int iGVar = Bmc_MeshGVar( Me, x, y );
349 int iCVar = Bmc_MeshCVar( Me, x, y );
353 }
354 }
355 if ( nAddClauses > 0 )
356 {
357 printf( "Adding %d one-hotness clauses.\n", nAddClauses );
358 continue;
359 }
360 printf( "Satisfying solution found. " );
361
362
363
364
365
366
367
368 break;
369 }
370 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
372 {
373
374 int nBuffs = 0, nNodes = 0;
375 for ( y = 1; y < Y-1; y++ )
376 for ( x = 1; x < X-1; x++ )
377 {
378 int iCVar = Bmc_MeshCVar( Me, x, y );
379 for ( c = 0; c < 4; c++ )
380 if ( Bmc_MeshVarValue(pSat, iCVar+c) )
381 {
382
383 nBuffs++;
384 }
385 for ( c = 4; c <
NCPARS; c++ )
386 if ( Bmc_MeshVarValue(pSat, iCVar+c) )
387 {
388
389 nNodes++;
390 }
391 }
392 printf( "The %d x %d mesh with latency %d with %d active cells (%d nodes and %d buffers):\n", X, Y, T, nNodes+nBuffs, nNodes, nBuffs );
393
394 printf( " Y\\X " );
395 for ( x = 0; x < X; x++ )
396 printf( " %-2d ", x );
397 printf( "\n" );
398 for ( y = 0; y < Y; y++ )
399 {
400 printf( " %-2d ", y );
401 for ( x = 0; x < X; x++ )
402 {
403 int iTVar = Bmc_MeshTVar( Me, x, y );
404 int iGVar = Bmc_MeshGVar( Me, x, y );
405
406 int fFound = 0; ;
407 for ( t = 0; t < T; t++ )
408 for ( g = 0; g < G; g++ )
409 if ( Bmc_MeshVarValue(pSat, iTVar+t) && Bmc_MeshVarValue(pSat, iGVar+g) )
410 {
411 printf( " %c%-2d ", 'a' + g, t );
412 fFound = 1;
413 }
414 if ( fFound )
415 continue;
416 if ( x == 0 || x == X-1 || y == 0 || y == Y-1 )
417 printf( " * " );
418 else
419 printf( " " );
420 }
421 printf( "\n" );
422 }
423 }
425}
#define NCPARS
DECLARATIONS ///.
int Bmc_MeshAddOneHotness(satoko_t *pSat, int iFirst, int iLast)
#define Gia_ManForEachAnd(p, pObj, i)
struct Gia_Obj_t_ Gia_Obj_t
int satoko_solve(satoko_t *)
struct solver_t_ satoko_t
void satoko_destroy(satoko_t *)
satoko_t * satoko_create(void)