77 #define ZDD_MV_OOM (Move *)1 92 static char rcsid[]
DD_UNUSED =
"$Id: cuddZddSymm.c,v 1.31 2012/02/05 01:07:19 fabio Exp $";
148 int TotalSymmGroups = 0;
150 for (i = lower; i < upper; i++) {
153 (void) fprintf(table->
out,
"Group:");
155 (void) fprintf(table->
out,
" %d", table->
invpermZ[x]);
165 (void) fprintf(table->
out,
"\n");
168 (void) fprintf(table->
out,
"Total Symmetric = %d\n", TotalSymm);
169 (void) fprintf(table->
out,
"Total Groups = %d\n", TotalSymmGroups);
199 DdNode *f, *f0, *f1, *f01, *f00, *f11, *f10;
204 int TotalRefCount = 0;
216 if ((
int) f1->
index == yindex) {
222 if ((
int) f0->
index != yindex) {
228 if ((
int) f0->
index == yindex) {
241 if ((xsymmy == 0) && (xsymmyp == 0))
254 if (
cuddE(f) != empty)
255 TotalRefCount += f->
ref;
260 symm_found = (arccount == TotalRefCount);
261 #if defined(DD_DEBUG) && defined(DD_VERBOSE) 264 (void) fprintf(table->
out,
265 "Found symmetry! x =%d\ty = %d\tPos(%d,%d)\n",
315 nvars = table->
sizeZ;
322 goto cuddZddSymmSiftingOutOfMem;
324 var =
ALLOC(
int, nvars);
327 goto cuddZddSymmSiftingOutOfMem;
330 for (i = 0; i < nvars; i++) {
339 for (i = lower; i <= upper; i++)
343 for (i = 0; i < iteration; i++) {
350 x = table->
permZ[var[i]];
352 previousSize = table->
keysZ;
354 if (x < lower || x > upper)
continue;
358 goto cuddZddSymmSiftingOutOfMem;
360 if (table->
keysZ < (
unsigned) previousSize) {
361 (void) fprintf(table->
out,
"-");
362 }
else if (table->
keysZ > (
unsigned) previousSize) {
363 (void) fprintf(table->
out,
"+");
365 (void) fprintf(table->
out,
"\nSize increased from %d to %d while sifting variable %d\n", previousSize, table->
keysZ, var[i]);
368 (void) fprintf(table->
out,
"=");
381 (void) fprintf(table->
out,
"\n#:S_SIFTING %8d: symmetric variables\n",symvars);
382 (void) fprintf(table->
out,
"#:G_SIFTING %8d: symmetric groups\n",symgroups);
387 cuddZddSymmSiftingOutOfMem:
442 initialSize = table->
keysZ;
444 nvars = table->
sizeZ;
451 goto cuddZddSymmSiftingConvOutOfMem;
453 var =
ALLOC(
int, nvars);
456 goto cuddZddSymmSiftingConvOutOfMem;
459 for (i = 0; i < nvars; i++) {
470 for (i = lower; i <= upper; i++)
474 for (i = 0; i < iteration; i++) {
481 x = table->
permZ[var[i]];
482 if (x < lower || x > upper)
continue;
486 previousSize = table->
keysZ;
490 goto cuddZddSymmSiftingConvOutOfMem;
492 if (table->
keysZ < (
unsigned) previousSize) {
493 (void) fprintf(table->
out,
"-");
494 }
else if (table->
keysZ > (
unsigned) previousSize) {
495 (void) fprintf(table->
out,
"+");
497 (void) fprintf(table->
out,
"\nSize increased from %d to %d while sifting variable %d\n", previousSize, table->
keysZ, var[i]);
500 (void) fprintf(table->
out,
"=");
508 while ((
unsigned) initialSize > table->
keysZ) {
509 initialSize = table->
keysZ;
511 (void) fprintf(table->
out,
"\n");
514 for (x = lower, classes = 0; x <= upper; x++, classes++) {
526 qsort((
void *)var,classes,
sizeof(
int),(
DD_QSFP)cuddZddUniqueCompare);
530 for (i = 0; i < iteration; i++) {
537 x = table->
permZ[var[i]];
540 previousSize = table->
keysZ;
544 goto cuddZddSymmSiftingConvOutOfMem;
546 if (table->
keysZ < (
unsigned) previousSize) {
547 (void) fprintf(table->
out,
"-");
548 }
else if (table->
keysZ > (
unsigned) previousSize) {
549 (void) fprintf(table->
out,
"+");
551 (void) fprintf(table->
out,
"\nSize increased from %d to %d while sifting variable %d\n", previousSize, table->
keysZ, var[i]);
554 (void) fprintf(table->
out,
"=");
565 (void) fprintf(table->
out,
"\n#:S_SIFTING %8d: symmetric variables\n",
567 (void) fprintf(table->
out,
"#:G_SIFTING %8d: symmetric groups\n",
576 cuddZddSymmSiftingConvOutOfMem:
622 int init_group_size, final_group_size;
624 initial_size = table->
keysZ;
630 for (i = x; i > x_low; i--) {
642 for (i = x; i < x_high; i++) {
647 while ((
unsigned) topbot < table->subtableZ[topbot].next)
659 while ((
unsigned) x < table->subtableZ[x].next)
663 init_group_size = x - i + 1;
669 goto cuddZddSymmSiftingAuxOutOfMem;
671 if (move_down == NULL ||
675 if (move_down != NULL)
680 while ((
unsigned) i < table->subtableZ[i].next) {
683 final_group_size = i - x + 1;
685 if (init_group_size == final_group_size) {
689 move_down, initial_size);
692 initial_size = table->
keysZ;
705 goto cuddZddSymmSiftingAuxOutOfMem;
707 else if (x == x_high) {
709 while ((
unsigned) x < table->subtableZ[x].next)
714 while ((
unsigned) i < table->subtableZ[i].next) {
717 init_group_size = i - x + 1;
722 goto cuddZddSymmSiftingAuxOutOfMem;
724 if (move_up == NULL ||
731 while ((
unsigned) x < table->subtableZ[x].next)
735 final_group_size = x - i + 1;
737 if (init_group_size == final_group_size) {
744 initial_size = table->
keysZ;
757 goto cuddZddSymmSiftingAuxOutOfMem;
759 else if ((x - x_low) > (x_high - x)) {
762 while ((
unsigned) x < table->subtableZ[x].next)
769 goto cuddZddSymmSiftingAuxOutOfMem;
771 if (move_down != NULL) {
778 while ((
unsigned) i < table->subtableZ[i].next) {
781 init_group_size = i - x + 1;
785 goto cuddZddSymmSiftingAuxOutOfMem;
787 if (move_up == NULL ||
791 if (move_up != NULL) {
795 while ((
unsigned) x < table->subtableZ[x].next)
799 final_group_size = x - i + 1;
801 if (init_group_size == final_group_size) {
808 while (move_down != NULL) {
809 move = move_down->
next;
813 initial_size = table->
keysZ;
826 goto cuddZddSymmSiftingAuxOutOfMem;
830 while ((
unsigned) x < table->subtableZ[x].next)
837 goto cuddZddSymmSiftingAuxOutOfMem;
839 if (move_up != NULL) {
843 while ((
unsigned) x < table->subtableZ[x].next)
847 init_group_size = x - i + 1;
852 goto cuddZddSymmSiftingAuxOutOfMem;
854 if (move_down == NULL ||
858 if (move_down != NULL) {
865 while ((
unsigned) i < table->subtableZ[i].next) {
868 final_group_size = i - x + 1;
870 if (init_group_size == final_group_size) {
877 while (move_up != NULL) {
878 move = move_up->
next;
882 initial_size = table->
keysZ;
895 goto cuddZddSymmSiftingAuxOutOfMem;
898 while (move_down != NULL) {
899 move = move_down->
next;
903 while (move_up != NULL) {
904 move = move_up->
next;
911 cuddZddSymmSiftingAuxOutOfMem:
913 while (move_down != NULL) {
914 move = move_down->
next;
920 while (move_up != NULL) {
921 move = move_up->
next;
961 int init_group_size, final_group_size;
963 initial_size = table->
keysZ;
970 init_group_size = x - i + 1;
976 goto cuddZddSymmSiftingConvAuxOutOfMem;
978 if (move_down == NULL ||
982 if (move_down != NULL)
985 while ((
unsigned) x < table->subtableZ[x].next)
990 while ((
unsigned) i < table->subtableZ[i].next) {
993 final_group_size = i - x + 1;
995 if (init_group_size == final_group_size) {
1002 initial_size = table->
keysZ;
1015 goto cuddZddSymmSiftingConvAuxOutOfMem;
1017 else if (x == x_high) {
1019 while ((
unsigned) x < table->subtableZ[x].next)
1024 while ((
unsigned) i < table->subtableZ[i].next) {
1027 init_group_size = i - x + 1;
1032 goto cuddZddSymmSiftingConvAuxOutOfMem;
1034 if (move_up == NULL ||
1038 if (move_up != NULL)
1041 while ((
unsigned) x < table->subtableZ[x].next)
1045 final_group_size = x - i + 1;
1047 if (init_group_size == final_group_size) {
1054 initial_size = table->
keysZ;
1067 goto cuddZddSymmSiftingConvAuxOutOfMem;
1069 else if ((x - x_low) > (x_high - x)) {
1075 goto cuddZddSymmSiftingConvAuxOutOfMem;
1077 if (move_down != NULL) {
1081 while ((
unsigned) x < table->subtableZ[x].next)
1086 while ((
unsigned) i < table->subtableZ[i].next) {
1089 init_group_size = i - x + 1;
1093 goto cuddZddSymmSiftingConvAuxOutOfMem;
1095 if (move_up == NULL ||
1099 if (move_up != NULL) {
1103 while ((
unsigned) x < table->subtableZ[x].next)
1107 final_group_size = x - i + 1;
1109 if (init_group_size == final_group_size) {
1116 while (move_down != NULL) {
1117 move = move_down->
next;
1121 initial_size = table->
keysZ;
1134 goto cuddZddSymmSiftingConvAuxOutOfMem;
1143 goto cuddZddSymmSiftingConvAuxOutOfMem;
1145 if (move_up != NULL) {
1149 while ((
unsigned) x < table->subtableZ[x].next)
1153 init_group_size = x - i + 1;
1158 goto cuddZddSymmSiftingConvAuxOutOfMem;
1160 if (move_down == NULL ||
1164 if (move_down != NULL) {
1168 while ((
unsigned) x < table->subtableZ[x].next)
1173 while ((
unsigned) i < table->subtableZ[i].next) {
1176 final_group_size = i - x + 1;
1178 if (init_group_size == final_group_size) {
1185 while (move_up != NULL) {
1186 move = move_up->
next;
1190 initial_size = table->
keysZ;
1203 goto cuddZddSymmSiftingConvAuxOutOfMem;
1206 while (move_down != NULL) {
1207 move = move_down->
next;
1211 while (move_up != NULL) {
1212 move = move_up->
next;
1219 cuddZddSymmSiftingConvAuxOutOfMem:
1221 while (move_down != NULL) {
1222 move = move_down->
next;
1228 while (move_up != NULL) {
1229 move = move_up->
next;
1268 int limit_size = initial_size;
1273 while (y >= x_low) {
1288 goto cuddZddSymmSifting_upOutOfMem;
1291 goto cuddZddSymmSifting_upOutOfMem;
1300 if (size < limit_size)
1308 if (size < limit_size)
1317 cuddZddSymmSifting_upOutOfMem:
1318 while (moves != NULL) {
1356 int limit_size = initial_size;
1357 int i, gxtop, gybot;
1361 while (y <= x_high) {
1379 goto cuddZddSymmSifting_downOutOfMem;
1382 goto cuddZddSymmSifting_downOutOfMem;
1391 if (size < limit_size)
1401 if (size < limit_size)
1410 cuddZddSymmSifting_downOutOfMem:
1411 while (moves != NULL) {
1448 for (move = moves, i = 0; move != NULL; move = move->
next, i++) {
1449 if (move->
size < size) {
1455 for (move = moves, i = 0; move != NULL; move = move->
next, i++) {
1456 if (i == i_best)
break;
1460 if (!res)
return(0);
1465 if (i_best == -1 && res == size)
1497 int i, temp, gxtop, gxbot, gybot, yprev;
1541 goto zdd_group_moveOutOfMem;
1562 goto zdd_group_moveOutOfMem;
1566 move->
next = *moves;
1569 return(table->
keysZ);
1571 zdd_group_moveOutOfMem:
1572 while (*moves != NULL) {
1573 move = (*moves)->
next;
1602 int i, temp, gxtop, gxbot, gybot, yprev;
1688 int TotalSymmGroups = 0;
1690 for (i = lower; i <= upper; i++) {
1705 *symvars = TotalSymm;
1706 *symgroups = TotalSymmGroups;
static char rcsid [] DD_UNUSED
#define cuddDeallocMove(unique, node)
int(* DD_QSFP)(const void *, const void *)
int cuddZddSymmCheck(DdManager *table, int x, int y)
int cuddZddSwapInPlace(DdManager *table, int x, int y)
int cuddZddSymmSifting(DdManager *table, int lower, int upper)
static Move * cuddZddSymmSifting_down(DdManager *table, int x, int x_high, int initial_size)
static int cuddZddSymmSiftingBackward(DdManager *table, Move *moves, int size)
int zddTotalNumberSwapping
void Cudd_zddSymmProfile(DdManager *table, int lower, int upper)
static int zdd_group_move(DdManager *table, int x, int y, Move **moves)
int cuddZddNextHigh(DdManager *table, int x)
DdNode * cuddDynamicAllocNode(DdManager *table)
int cuddZddSymmSiftingConv(DdManager *table, int lower, int upper)
static void cuddZddSymmSummary(DdManager *table, int lower, int upper, int *symvars, int *symgroups)
static Move * cuddZddSymmSifting_up(DdManager *table, int x, int x_low, int initial_size)
static int cuddZddSymmSiftingAux(DdManager *table, int x, int x_low, int x_high)
static int cuddZddSymmSiftingConvAux(DdManager *table, int x, int x_low, int x_high)
int cuddZddUniqueCompare(int *ptr_x, int *ptr_y)
int cuddZddNextLow(DdManager *table, int x)
static int zdd_group_move_backward(DdManager *table, int x, int y)