abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pair.c File Reference
#include "espresso.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void set_pair (pPLA PLA)
 
void set_pair1 (pPLA PLA, bool adjust_labels)
 
pcover pairvar (pcover A, ppair pair)
 
pcover delvar (pcover A, paired)
 
void find_optimal_pairing (pPLA PLA, int strategy)
 
int ** find_pairing_cost (pPLA PLA, int strategy)
 
void print_pair (ppair pair)
 
int greedy_best_cost (int **cost_array_local, ppair *pair_p)
 
ppair pair_best_cost (int **cost_array_local)
 
void find_best_cost (ppair pair)
 
void pair_all (pPLA PLA, int pair_strategy)
 
void minimize_pair (ppair pair)
 
void generate_all_pairs (ppair pair, int n, pset candidate, int(*action)())
 
ppair pair_new (int n)
 
ppair pair_save (ppair pair, int n)
 
void pair_free (ppair pair)
 

Variables

static int best_cost
 
static int ** cost_array
 
static ppair best_pair
 
static pset best_phase
 
static pPLA global_PLA
 
static pcover best_F
 
static pcover best_D
 
static pcover best_R
 
static int pair_minim_strategy
 

Function Documentation

pcover delvar ( pcover  A,
paired   
)

Definition at line 164 of file pair.c.

167 {
168  bool run;
169  int first_run = 0; // Suppress "might be used uninitialized"
170  int run_length, var, offset = 0;
171 
172  run = FALSE; run_length = 0;
173  for(var = 0; var < cube.num_binary_vars; var++)
174  if (paired[var])
175  if (run)
176  run_length += cube.part_size[var];
177  else {
178  run = TRUE;
179  first_run = cube.first_part[var];
180  run_length = cube.part_size[var];
181  }
182  else
183  if (run) {
184  A = sf_delcol(A, first_run-offset, run_length);
185  run = FALSE;
186  offset += run_length;
187  }
188  if (run)
189  A = sf_delcol(A, first_run-offset, run_length);
190  return A;
191 }
#define FALSE
Definition: cudd.h:91
int var(Lit p)
Definition: SolverTypes.h:62
pset_family sf_delcol()
#define TRUE
Definition: cudd.h:88
void find_best_cost ( ppair  pair)

Definition at line 448 of file pair.c.

450 {
451  register int i, cost;
452 
453  cost = 0;
454  for(i = 0; i < pair->cnt; i++)
455  cost += cost_array[pair->var1[i]-1][pair->var2[i]-1];
456  if (cost > best_cost) {
457  best_cost = cost;
458  best_pair = pair_save(pair, pair->cnt);
459  }
460  if ((debug & MINCOV) && trace) {
461  printf("cost is %d ", cost);
462  print_pair(pair);
463  }
464 }
void print_pair(ppair pair)
Definition: pair.c:375
bool trace
Definition: globals.c:36
int * var2
Definition: espresso.h:285
unsigned int debug
Definition: globals.c:19
if(last==0)
Definition: sparse_int.h:34
int * var1
Definition: espresso.h:284
#define MINCOV
Definition: espresso.h:362
ppair pair_save(ppair pair, int n)
Definition: pair.c:660
static int ** cost_array
Definition: pair.c:367
static int best_cost
Definition: pair.c:366
static ppair best_pair
Definition: pair.c:368
void find_optimal_pairing ( pPLA  PLA,
int  strategy 
)

Definition at line 226 of file pair.c.

229 {
230  int i, j, **cost_array;
231 
232  cost_array = find_pairing_cost(PLA, strategy);
233 
234  if (summary) {
235  printf(" ");
236  for(i = 0; i < cube.num_binary_vars; i++)
237  printf("%3d ", i+1);
238  printf("\n");
239  for(i = 0; i < cube.num_binary_vars; i++) {
240  printf("%3d ", i+1);
241  for(j = 0; j < cube.num_binary_vars; j++)
242  printf("%3d ", cost_array[i][j]);
243  printf("\n");
244  }
245  }
246 
247  if (cube.num_binary_vars <= 14) {
248  PLA->pair = pair_best_cost(cost_array);
249  } else {
250  (void) greedy_best_cost(cost_array, &(PLA->pair));
251  }
252  printf("# ");
253  print_pair(PLA->pair);
254 
255  for(i = 0; i < cube.num_binary_vars; i++)
256  FREE(cost_array[i]);
257  FREE(cost_array);
258 
259  set_pair(PLA);
260  EXEC_S(PLA->F=espresso(PLA->F,PLA->D,PLA->R),"ESPRESSO ",PLA->F);
261 }
void print_pair(ppair pair)
Definition: pair.c:375
ppair pair
Definition: espresso.h:320
ABC_NAMESPACE_IMPL_START pcover espresso(pcover F, pcover D1, pcover R)
Definition: espresso.c:53
ppair pair_best_cost(int **cost_array_local)
Definition: pair.c:429
bool summary
Definition: globals.c:35
int greedy_best_cost(int **cost_array_local, ppair *pair_p)
Definition: pair.c:387
ABC_NAMESPACE_IMPL_START void set_pair(pPLA PLA)
Definition: pair.c:15
#define EXEC_S(fct, name, S)
Definition: espresso.h:420
#define FREE(obj)
Definition: avl.h:31
pcover F
Definition: espresso.h:316
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
static int ** cost_array
Definition: pair.c:367
int ** find_pairing_cost(pPLA PLA, int strategy)
Definition: pair.c:263
int** find_pairing_cost ( pPLA  PLA,
int  strategy 
)

Definition at line 263 of file pair.c.

266 {
267  int var1, var2, **cost_array;
268  int i, j;
269  int xnum_binary_vars = 0, xnum_vars = 0, *xpart_size = NULL, cost = 0; // Suppress "might be used uninitialized"
270  pcover T;
271  pcover Fsave = NULL, Dsave = NULL, Rsave = NULL; // Suppress "might be used uninitialized"
272  pset mask;
273 /* char *s;*/
274 
275  /* data is returned in the cost array */
276  cost_array = ALLOC(int *, cube.num_binary_vars);
277  for(i = 0; i < cube.num_binary_vars; i++)
278  cost_array[i] = ALLOC(int, cube.num_binary_vars);
279  for(i = 0; i < cube.num_binary_vars; i++)
280  for(j = 0; j < cube.num_binary_vars; j++)
281  cost_array[i][j] = 0;
282 
283  /* Setup the pair structure for pairing variables together */
284  PLA->pair = pair_new(1);
285  PLA->pair->cnt = 1;
286 
287  for(var1 = 0; var1 < cube.num_binary_vars-1; var1++) {
288  for(var2 = var1+1; var2 < cube.num_binary_vars; var2++) {
289  /* if anything but simple strategy, perform setup */
290  if (strategy > 0) {
291  /* save the original covers */
292  Fsave = sf_save(PLA->F);
293  Dsave = sf_save(PLA->D);
294  Rsave = sf_save(PLA->R);
295 
296  /* save the original cube structure */
297  xnum_binary_vars = cube.num_binary_vars;
298  xnum_vars = cube.num_vars;
299  xpart_size = ALLOC(int, cube.num_vars);
300  for(i = 0; i < cube.num_vars; i++)
301  xpart_size[i] = cube.part_size[i];
302 
303  /* pair two variables together */
304  PLA->pair->var1[0] = var1 + 1;
305  PLA->pair->var2[0] = var2 + 1;
306  set_pair1(PLA, /* adjust_labels */ FALSE);
307  }
308 
309 
310  /* decide how to best estimate worth of this pairing */
311  switch(strategy) {
312  case 3:
313  /*s = "exact minimization";*/
314  PLA->F = minimize_exact(PLA->F, PLA->D, PLA->R, 1);
315  cost = Fsave->count - PLA->F->count;
316  break;
317  case 2:
318  /*s = "full minimization";*/
319  PLA->F = espresso(PLA->F, PLA->D, PLA->R);
320  cost = Fsave->count - PLA->F->count;
321  break;
322  case 1:
323  /*s = "strong division";*/
324  PLA->F = reduce(PLA->F, PLA->D);
325  PLA->F = expand(PLA->F, PLA->R, FALSE);
326  PLA->F = irredundant(PLA->F, PLA->D);
327  cost = Fsave->count - PLA->F->count;
328  break;
329  case 0:
330  /*s = "weak division";*/
331  mask = new_cube();
332  set_or(mask, cube.var_mask[var1], cube.var_mask[var2]);
333  T = dist_merge(sf_save(PLA->F), mask);
334  cost = PLA->F->count - T->count;
335  sf_free(T);
336  set_free(mask);
337  }
338 
339  cost_array[var1][var2] = cost;
340 
341  if (strategy > 0) {
342  /* restore the original cube structure -- free the new ones */
343  setdown_cube();
344  FREE(cube.part_size);
345  cube.num_binary_vars = xnum_binary_vars;
346  cube.num_vars = xnum_vars;
347  cube.part_size = xpart_size;
348  cube_setup();
349 
350  /* restore the original cover(s) -- free the new ones */
351  sf_free(PLA->F);
352  sf_free(PLA->D);
353  sf_free(PLA->R);
354  PLA->F = Fsave;
355  PLA->D = Dsave;
356  PLA->R = Rsave;
357  }
358  }
359  }
360 
361  pair_free(PLA->pair);
362  PLA->pair = NULL;
363  return cost_array;
364 }
pset set_or()
static const int var1
Definition: satSolver.c:77
ppair pair
Definition: espresso.h:320
#define set_free(r)
Definition: espresso.h:167
#define FALSE
Definition: cudd.h:91
ABC_NAMESPACE_IMPL_START pcover espresso(pcover F, pcover D1, pcover R)
Definition: espresso.c:53
#define new_cube()
Definition: espresso.h:262
#define pcover
Definition: espresso.h:264
void set_pair1(pPLA PLA, bool adjust_labels)
Definition: pair.c:21
pset_family dist_merge(INOUT pset_family A, IN pset mask)
Definition: contain.c:141
ABC_NAMESPACE_IMPL_START void cube_setup()
Definition: cubestr.c:27
void sf_free()
int * var2
Definition: espresso.h:285
pcover expand()
#define ALLOC(type, num)
Definition: avl.h:27
pcover irredundant()
void setdown_cube()
Definition: cubestr.c:95
#define FREE(obj)
Definition: avl.h:31
unsigned int * pset
Definition: espresso.h:73
pcover reduce()
pcover F
Definition: espresso.h:316
int * var1
Definition: espresso.h:284
ppair pair_new(int n)
Definition: pair.c:647
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
pcover minimize_exact()
static int ** cost_array
Definition: pair.c:367
void pair_free(ppair pair)
Definition: pair.c:677
pset_family sf_save()
void generate_all_pairs ( ppair  pair,
int  n,
pset  candidate,
int (*)()  action 
)

Definition at line 593 of file pair.c.

598 {
599  int i, j;
600  pset recur_candidate;
601  ppair recur_pair;
602 
603  if (set_ord(candidate) < 2) {
604  (*action)(pair);
605  return;
606  }
607 
608  recur_pair = pair_save(pair, n);
609  recur_candidate = set_save(candidate);
610 
611  /* Find first variable still in the candidate set */
612  for(i = 0; i < n; i++)
613  if (is_in_set(candidate, i))
614  break;
615 
616  /* Try all pairs of i with other variables */
617  for(j = i+1; j < n; j++)
618  if (is_in_set(candidate, j)) {
619  /* pair (i j) -- remove from candidate set for future pairings */
620  set_remove(recur_candidate, i);
621  set_remove(recur_candidate, j);
622 
623  /* add to the pair array */
624  recur_pair->var1[recur_pair->cnt] = i+1;
625  recur_pair->var2[recur_pair->cnt] = j+1;
626  recur_pair->cnt++;
627 
628  /* recur looking for the end ... */
629  generate_all_pairs(recur_pair, n, recur_candidate, action);
630 
631  /* now break this pair, and restore candidate set */
632  recur_pair->cnt--;
633  set_insert(recur_candidate, i);
634  set_insert(recur_candidate, j);
635  }
636 
637  /* if odd, generate all pairs which do NOT include i */
638  if ((set_ord(candidate) % 2) == 1) {
639  set_remove(recur_candidate, i);
640  generate_all_pairs(recur_pair, n, recur_candidate, action);
641  }
642 
643  pair_free(recur_pair);
644  set_free(recur_candidate);
645 }
#define set_free(r)
Definition: espresso.h:167
#define set_save(r)
Definition: espresso.h:166
void generate_all_pairs(ppair pair, int n, pset candidate, int(*action)())
Definition: pair.c:593
int * var2
Definition: espresso.h:285
#define is_in_set(set, e)
Definition: espresso.h:170
unsigned int * pset
Definition: espresso.h:73
int * var1
Definition: espresso.h:284
#define set_remove(set, e)
Definition: espresso.h:171
#define set_insert(set, e)
Definition: espresso.h:172
ppair pair_save(ppair pair, int n)
Definition: pair.c:660
void pair_free(ppair pair)
Definition: pair.c:677
int set_ord()
int greedy_best_cost ( int **  cost_array_local,
ppair pair_p 
)

Definition at line 387 of file pair.c.

390 {
391  int i, j;
392  int besti = 0, bestj = 0;
393  int maxcost, total_cost;
394  pset cand;
395  ppair pair;
396 
397  pair = pair_new(cube.num_binary_vars);
398  cand = set_full(cube.num_binary_vars);
399  total_cost = 0;
400 
401  while (set_ord(cand) >= 2) {
402  maxcost = -1;
403  for(i = 0; i < cube.num_binary_vars; i++) {
404  if (is_in_set(cand, i)) {
405  for(j = i+1; j < cube.num_binary_vars; j++) {
406  if (is_in_set(cand, j)) {
407  if (cost_array_local[i][j] > maxcost) {
408  maxcost = cost_array_local[i][j];
409  besti = i;
410  bestj = j;
411  }
412  }
413  }
414  }
415  }
416  pair->var1[pair->cnt] = besti+1;
417  pair->var2[pair->cnt] = bestj+1;
418  pair->cnt++;
419  set_remove(cand, besti);
420  set_remove(cand, bestj);
421  total_cost += maxcost;
422  }
423  set_free(cand);
424  *pair_p = pair;
425  return total_cost;
426 }
#define set_free(r)
Definition: espresso.h:167
int * var2
Definition: espresso.h:285
#define set_full(size)
Definition: espresso.h:165
#define is_in_set(set, e)
Definition: espresso.h:170
unsigned int * pset
Definition: espresso.h:73
int * var1
Definition: espresso.h:284
#define set_remove(set, e)
Definition: espresso.h:171
ppair pair_new(int n)
Definition: pair.c:647
int set_ord()
void minimize_pair ( ppair  pair)

Definition at line 518 of file pair.c.

520 {
521  pcover Fsave, Dsave, Rsave;
522  int i, xnum_binary_vars, xnum_vars, *xpart_size;
523 
524  /* save the original covers */
525  Fsave = sf_save(global_PLA->F);
526  Dsave = sf_save(global_PLA->D);
527  Rsave = sf_save(global_PLA->R);
528 
529  /* save the original cube structure */
530  xnum_binary_vars = cube.num_binary_vars;
531  xnum_vars = cube.num_vars;
532  xpart_size = ALLOC(int, cube.num_vars);
533  for(i = 0; i < cube.num_vars; i++)
534  xpart_size[i] = cube.part_size[i];
535 
536  /* setup the paired variables */
537  global_PLA->pair = pair;
538  set_pair1(global_PLA, /* adjust_labels */ FALSE);
539 
540  /* call the minimizer */
541  if (summary)
542  print_pair(pair);
543  switch(pair_minim_strategy) {
544  case 2:
546  if (summary)
547  printf("# phase is %s\n", pc1(global_PLA->phase));
548  break;
549  case 1:
551  global_PLA->R, 1), "EXACT ", global_PLA->F);
552  break;
553  case 0:
555  global_PLA->R), "ESPRESSO ", global_PLA->F);
556  break;
557  default:
558  break;
559  }
560 
561  /* see if we have a new best solution */
562  if (global_PLA->F->count < best_cost) {
563  best_cost = global_PLA->F->count;
564  best_pair = pair_save(pair, pair->cnt);
566  if (best_F != NULL) sf_free(best_F);
567  if (best_D != NULL) sf_free(best_D);
568  if (best_R != NULL) sf_free(best_R);
572  }
573 
574  /* restore the original cube structure -- free the new ones */
575  setdown_cube();
576  FREE(cube.part_size);
577  cube.num_binary_vars = xnum_binary_vars;
578  cube.num_vars = xnum_vars;
579  cube.part_size = xpart_size;
580  cube_setup();
581 
582  /* restore the original cover(s) -- free the new ones */
583  sf_free(global_PLA->F);
584  sf_free(global_PLA->D);
585  sf_free(global_PLA->R);
586  global_PLA->F = Fsave;
587  global_PLA->D = Dsave;
588  global_PLA->R = Rsave;
589  global_PLA->pair = NULL;
590  global_PLA->phase = NULL;
591 }
void print_pair(ppair pair)
Definition: pair.c:375
ppair pair
Definition: espresso.h:320
#define FALSE
Definition: cudd.h:91
ABC_NAMESPACE_IMPL_START pcover espresso(pcover F, pcover D1, pcover R)
Definition: espresso.c:53
char * pc1(pcube c)
Definition: cvrout.c:379
#define pcover
Definition: espresso.h:264
#define set_save(r)
Definition: espresso.h:166
static int pair_minim_strategy
Definition: pair.c:372
void set_pair1(pPLA PLA, bool adjust_labels)
Definition: pair.c:21
bool summary
Definition: globals.c:35
ABC_NAMESPACE_IMPL_START void cube_setup()
Definition: cubestr.c:27
void sf_free()
static pcover best_D
Definition: pair.c:371
#define ALLOC(type, num)
Definition: avl.h:27
void setdown_cube()
Definition: cubestr.c:95
void phase_assignment()
#define EXEC_S(fct, name, S)
Definition: espresso.h:420
#define FREE(obj)
Definition: avl.h:31
pcover F
Definition: espresso.h:316
pcube phase
Definition: espresso.h:319
static pPLA global_PLA
Definition: pair.c:370
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
static pcover best_R
Definition: pair.c:371
ppair pair_save(ppair pair, int n)
Definition: pair.c:660
static pset best_phase
Definition: pair.c:369
static pcover best_F
Definition: pair.c:371
pcover minimize_exact()
static int best_cost
Definition: pair.c:366
static ppair best_pair
Definition: pair.c:368
pset_family sf_save()
void pair_all ( pPLA  PLA,
int  pair_strategy 
)

Definition at line 475 of file pair.c.

478 {
479  ppair pair;
480  pset candidate;
481 
482  global_PLA = PLA;
483  pair_minim_strategy = pair_strategy;
484  best_cost = PLA->F->count + 1;
485  best_pair = NULL;
486  best_phase = NULL;
487  best_F = best_D = best_R = NULL;
488  pair = pair_new(cube.num_binary_vars);
489  candidate = set_fill(set_new(cube.num_binary_vars), cube.num_binary_vars);
490 
491  generate_all_pairs(pair, cube.num_binary_vars, candidate, minimize_pair);
492 
493  pair_free(pair);
494  set_free(candidate);
495 
496  PLA->pair = best_pair;
497  PLA->phase = best_phase;
498 /* not really necessary
499  if (phase != NULL)
500  (void) set_phase(PLA->phase);
501 */
502  set_pair(PLA);
503  printf("# ");
504  print_pair(PLA->pair);
505 
506  sf_free(PLA->F);
507  sf_free(PLA->D);
508  sf_free(PLA->R);
509  PLA->F = best_F;
510  PLA->D = best_D;
511  PLA->R = best_R;
512 }
void print_pair(ppair pair)
Definition: pair.c:375
ppair pair
Definition: espresso.h:320
#define set_free(r)
Definition: espresso.h:167
static int pair_minim_strategy
Definition: pair.c:372
void generate_all_pairs(ppair pair, int n, pset candidate, int(*action)())
Definition: pair.c:593
void minimize_pair(ppair pair)
Definition: pair.c:518
void sf_free()
static pcover best_D
Definition: pair.c:371
ABC_NAMESPACE_IMPL_START void set_pair(pPLA PLA)
Definition: pair.c:15
unsigned int * pset
Definition: espresso.h:73
pcover F
Definition: espresso.h:316
#define set_new(size)
Definition: espresso.h:164
pset set_fill()
pcube phase
Definition: espresso.h:319
ppair pair_new(int n)
Definition: pair.c:647
static pPLA global_PLA
Definition: pair.c:370
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
static pcover best_R
Definition: pair.c:371
static pset best_phase
Definition: pair.c:369
static pcover best_F
Definition: pair.c:371
void pair_free(ppair pair)
Definition: pair.c:677
static int best_cost
Definition: pair.c:366
static ppair best_pair
Definition: pair.c:368
ppair pair_best_cost ( int **  cost_array_local)

Definition at line 429 of file pair.c.

431 {
432  ppair pair;
433  pset candidate;
434 
435  best_cost = -1;
436  best_pair = NULL;
437  cost_array = cost_array_local;
438 
439  pair = pair_new(cube.num_binary_vars);
440  candidate = set_full(cube.num_binary_vars);
441  generate_all_pairs(pair, cube.num_binary_vars, candidate, find_best_cost);
442  pair_free(pair);
443  set_free(candidate);
444  return best_pair;
445 }
#define set_free(r)
Definition: espresso.h:167
void generate_all_pairs(ppair pair, int n, pset candidate, int(*action)())
Definition: pair.c:593
void find_best_cost(ppair pair)
Definition: pair.c:448
#define set_full(size)
Definition: espresso.h:165
unsigned int * pset
Definition: espresso.h:73
ppair pair_new(int n)
Definition: pair.c:647
static int ** cost_array
Definition: pair.c:367
void pair_free(ppair pair)
Definition: pair.c:677
static int best_cost
Definition: pair.c:366
static ppair best_pair
Definition: pair.c:368
void pair_free ( ppair  pair)

Definition at line 677 of file pair.c.

679 {
680  FREE(pair->var1);
681  FREE(pair->var2);
682  FREE(pair);
683 }
int * var2
Definition: espresso.h:285
#define FREE(obj)
Definition: avl.h:31
int * var1
Definition: espresso.h:284
ppair pair_new ( int  n)

Definition at line 647 of file pair.c.

649 {
650  register ppair pair1;
651 
652  pair1 = ALLOC(pair_t, 1);
653  pair1->cnt = 0;
654  pair1->var1 = ALLOC(int, n);
655  pair1->var2 = ALLOC(int, n);
656  return pair1;
657 }
int * var2
Definition: espresso.h:285
#define ALLOC(type, num)
Definition: avl.h:27
int * var1
Definition: espresso.h:284
ppair pair_save ( ppair  pair,
int  n 
)

Definition at line 660 of file pair.c.

663 {
664  register int k;
665  register ppair pair1;
666 
667  pair1 = pair_new(n);
668  pair1->cnt = pair->cnt;
669  for(k = 0; k < pair->cnt; k++) {
670  pair1->var1[k] = pair->var1[k];
671  pair1->var2[k] = pair->var2[k];
672  }
673  return pair1;
674 }
int * var2
Definition: espresso.h:285
int * var1
Definition: espresso.h:284
ppair pair_new(int n)
Definition: pair.c:647
pcover pairvar ( pcover  A,
ppair  pair 
)

Definition at line 124 of file pair.c.

127 {
128  register pcube last, p;
129  register int val, p1, p2, b1, b0;
130  int insert_col, pairnum;
131 
132  insert_col = cube.first_part[cube.num_vars - 1];
133 
134  /* stretch the cover matrix to make room for the paired variables */
135  A = sf_delcol(A, insert_col, -4*pair->cnt);
136 
137  /* compute the paired values */
138  foreach_set(A, last, p) {
139  for(pairnum = 0; pairnum < pair->cnt; pairnum++) {
140  p1 = cube.first_part[pair->var1[pairnum] - 1];
141  p2 = cube.first_part[pair->var2[pairnum] - 1];
142  b1 = is_in_set(p, p2+1);
143  b0 = is_in_set(p, p2);
144  val = insert_col + pairnum * 4;
145  if (/* a0 */ is_in_set(p, p1)) {
146  if (b0)
147  set_insert(p, val + 3);
148  if (b1)
149  set_insert(p, val + 2);
150  }
151  if (/* a1 */ is_in_set(p, p1+1)) {
152  if (b0)
153  set_insert(p, val + 1);
154  if (b1)
155  set_insert(p, val);
156  }
157  }
158  }
159  return A;
160 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
#define b1
Definition: extraBdd.h:76
#define foreach_set(R, last, p)
Definition: espresso.h:135
int * var2
Definition: espresso.h:285
pset_family sf_delcol()
#define is_in_set(set, e)
Definition: espresso.h:170
int * var1
Definition: espresso.h:284
#define set_insert(set, e)
Definition: espresso.h:172
#define b0
Definition: extraBdd.h:75
#define pcube
Definition: espresso.h:261
void print_pair ( ppair  pair)

Definition at line 375 of file pair.c.

377 {
378  int i;
379 
380  printf("pair is");
381  for(i = 0; i < pair->cnt; i++)
382  printf (" (%d %d)", pair->var1[i], pair->var2[i]);
383  printf("\n");
384 }
int * var2
Definition: espresso.h:285
int * var1
Definition: espresso.h:284
ABC_NAMESPACE_IMPL_START void set_pair ( pPLA  PLA)

Definition at line 15 of file pair.c.

17 {
18  set_pair1(PLA, TRUE);
19 }
void set_pair1(pPLA PLA, bool adjust_labels)
Definition: pair.c:21
#define TRUE
Definition: cudd.h:88
void set_pair1 ( pPLA  PLA,
bool  adjust_labels 
)

Definition at line 21 of file pair.c.

24 {
25  int i, var, *paired, newvar;
26  int old_num_vars, old_num_binary_vars, old_size, old_mv_start;
27  int *new_part_size, new_num_vars, new_num_binary_vars, new_mv_start;
28  ppair pair = PLA->pair;
29  char scratch[1000], **oldlabel, *var1, *var1bar, *var2, *var2bar;
30 
31  if (adjust_labels)
32  makeup_labels(PLA);
33 
34  /* Check the pair structure for valid entries and see which binary
35  variables are left unpaired
36  */
37  paired = ALLOC(bool, cube.num_binary_vars);
38  for(var = 0; var < cube.num_binary_vars; var++)
39  paired[var] = FALSE;
40  for(i = 0; i < pair->cnt; i++)
41  if ((pair->var1[i] > 0 && pair->var1[i] <= cube.num_binary_vars) &&
42  (pair->var2[i] > 0 && pair->var2[i] <= cube.num_binary_vars)) {
43  paired[pair->var1[i]-1] = TRUE;
44  paired[pair->var2[i]-1] = TRUE;
45  } else
46  fatal("can only pair binary-valued variables");
47 
48  PLA->F = delvar(pairvar(PLA->F, pair), paired);
49  PLA->R = delvar(pairvar(PLA->R, pair), paired);
50  PLA->D = delvar(pairvar(PLA->D, pair), paired);
51 
52  /* Now painfully adjust the cube size */
53  old_size = cube.size;
54  old_num_vars = cube.num_vars;
55  old_num_binary_vars = cube.num_binary_vars;
56  old_mv_start = cube.first_part[cube.num_binary_vars];
57  /* Create the new cube.part_size vector and setup the cube structure */
58  new_num_binary_vars = 0;
59  for(var = 0; var < old_num_binary_vars; var++)
60  new_num_binary_vars += (paired[var] == FALSE);
61  new_num_vars = new_num_binary_vars + pair->cnt;
62  new_num_vars += old_num_vars - old_num_binary_vars;
63  new_part_size = ALLOC(int, new_num_vars);
64  for(var = 0; var < pair->cnt; var++)
65  new_part_size[new_num_binary_vars + var] = 4;
66  for(var = 0; var < old_num_vars - old_num_binary_vars; var++)
67  new_part_size[new_num_binary_vars + pair->cnt + var] =
68  cube.part_size[old_num_binary_vars + var];
69  setdown_cube();
70  FREE(cube.part_size);
71  cube.num_vars = new_num_vars;
72  cube.num_binary_vars = new_num_binary_vars;
73  cube.part_size = new_part_size;
74  cube_setup();
75 
76  /* hack with the labels to get them correct */
77  if (adjust_labels) {
78  oldlabel = PLA->label;
79  PLA->label = ALLOC(char *, cube.size);
80  for(var = 0; var < pair->cnt; var++) {
81  newvar = cube.num_binary_vars*2 + var*4;
82  var1 = oldlabel[ (pair->var1[var]-1) * 2 + 1];
83  var2 = oldlabel[ (pair->var2[var]-1) * 2 + 1];
84  var1bar = oldlabel[ (pair->var1[var]-1) * 2];
85  var2bar = oldlabel[ (pair->var2[var]-1) * 2];
86  (void) sprintf(scratch, "%s+%s", var1bar, var2bar);
87  PLA->label[newvar] = util_strsav(scratch);
88  (void) sprintf(scratch, "%s+%s", var1bar, var2);
89  PLA->label[newvar+1] = util_strsav(scratch);
90  (void) sprintf(scratch, "%s+%s", var1, var2bar);
91  PLA->label[newvar+2] = util_strsav(scratch);
92  (void) sprintf(scratch, "%s+%s", var1, var2);
93  PLA->label[newvar+3] = util_strsav(scratch);
94  }
95  /* Copy the old labels for the unpaired binary vars */
96  i = 0;
97  for(var = 0; var < old_num_binary_vars; var++) {
98  if (paired[var] == FALSE) {
99  PLA->label[2*i] = oldlabel[2*var];
100  PLA->label[2*i+1] = oldlabel[2*var+1];
101  oldlabel[2*var] = oldlabel[2*var+1] = (char *) NULL;
102  i++;
103  }
104  }
105  /* Copy the old labels for the remaining unpaired vars */
106  new_mv_start = cube.num_binary_vars*2 + pair->cnt*4;
107  for(i = old_mv_start; i < old_size; i++) {
108  PLA->label[new_mv_start + i - old_mv_start] = oldlabel[i];
109  oldlabel[i] = (char *) NULL;
110  }
111  /* free remaining entries in oldlabel */
112  for(i = 0; i < old_size; i++)
113  if (oldlabel[i] != (char *) NULL)
114  FREE(oldlabel[i]);
115  FREE(oldlabel);
116  }
117 
118  /* the paired variables should not be sparse (cf. mv_reduce/raise_in)*/
119  for(var = 0; var < pair->cnt; var++)
120  cube.sparse[cube.num_binary_vars + var] = 0;
121  FREE(paired);
122 }
static const int var1
Definition: satSolver.c:77
ppair pair
Definition: espresso.h:320
void fatal(char *s)
Definition: cvrmisc.c:140
#define FALSE
Definition: cudd.h:91
pcover pairvar(pcover A, ppair pair)
Definition: pair.c:124
int var(Lit p)
Definition: SolverTypes.h:62
ABC_NAMESPACE_IMPL_START void cube_setup()
Definition: cubestr.c:27
int * var2
Definition: espresso.h:285
#define ALLOC(type, num)
Definition: avl.h:27
void setdown_cube()
Definition: cubestr.c:95
#define FREE(obj)
Definition: avl.h:31
char * sprintf()
pcover F
Definition: espresso.h:316
int * var1
Definition: espresso.h:284
pcover delvar(pcover A, paired)
Definition: pair.c:164
#define TRUE
Definition: cudd.h:88
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
void makeup_labels(pPLA PLA)
Definition: cvrout.c:434
char ** label
Definition: espresso.h:321

Variable Documentation

int best_cost
static

Definition at line 366 of file pair.c.

pcover best_D
static

Definition at line 371 of file pair.c.

pcover best_F
static

Definition at line 371 of file pair.c.

ppair best_pair
static

Definition at line 368 of file pair.c.

pset best_phase
static

Definition at line 369 of file pair.c.

pcover best_R
static

Definition at line 371 of file pair.c.

int** cost_array
static

Definition at line 367 of file pair.c.

pPLA global_PLA
static

Definition at line 370 of file pair.c.

int pair_minim_strategy
static

Definition at line 372 of file pair.c.