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