81 #define ZDD_MV_OOM (Move *)1
96 static char rcsid[]
DD_UNUSED =
"$Id: cuddZddSymm.c,v 1.29 2004/08/13 18:04:54 fabio Exp $";
152 int TotalSymmGroups = 0;
154 for (i = lower; i < upper; i++) {
157 (void) fprintf(table->
out,
"Group:");
159 (void) fprintf(table->
out,
" %d", table->
invpermZ[x]);
169 (void) fprintf(table->
out,
"\n");
172 (void) fprintf(table->
out,
"Total Symmetric = %d\n", TotalSymm);
173 (void) fprintf(table->
out,
"Total Groups = %d\n", TotalSymmGroups);
203 DdNode *f, *f0, *f1, *f01, *f00, *f11, *f10;
208 int TotalRefCount = 0;
220 if ((
int) f1->
index == yindex) {
226 if ((
int) f0->
index != yindex) {
232 if ((
int) f0->
index == yindex) {
245 if ((xsymmy == 0) && (xsymmyp == 0))
258 if (
cuddE(f) != empty)
259 TotalRefCount += f->
ref;
264 symm_found = (arccount == TotalRefCount);
265 #if defined(DD_DEBUG) && defined(DD_VERBOSE)
268 (void) fprintf(table->
out,
269 "Found symmetry! x =%d\ty = %d\tPos(%d,%d)\n",
319 nvars = table->
sizeZ;
326 goto cuddZddSymmSiftingOutOfMem;
331 goto cuddZddSymmSiftingOutOfMem;
334 for (i = 0; i < nvars; i++) {
343 for (i = lower; i <= upper; i++)
347 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;
456 goto cuddZddSymmSiftingConvOutOfMem;
459 for (i = 0; i < nvars; i++) {
470 for (i = lower; i <= upper; i++)
474 for (i = 0; i < iteration; i++) {
477 x = table->
permZ[var[i]];
478 if (x < lower || x > upper)
continue;
482 previousSize = table->
keysZ;
486 goto cuddZddSymmSiftingConvOutOfMem;
488 if (table->
keysZ < (
unsigned) previousSize) {
489 (void) fprintf(table->
out,
"-");
490 }
else if (table->
keysZ > (
unsigned) previousSize) {
491 (void) fprintf(table->
out,
"+");
493 (void) fprintf(table->
out,
"\nSize increased from %d to %d while sifting variable %d\n", previousSize, table->
keysZ, var[i]);
496 (void) fprintf(table->
out,
"=");
504 while ((
unsigned) initialSize > table->
keysZ) {
505 initialSize = table->
keysZ;
507 (void) fprintf(table->
out,
"\n");
510 for (x = lower, classes = 0; x <= upper; x++, classes++) {
522 qsort((
void *)var,classes,
sizeof(
int),(
DD_QSFP)cuddZddUniqueCompare);
526 for (i = 0; i < iteration; i++) {
529 x = table->
permZ[var[i]];
532 previousSize = table->
keysZ;
536 goto cuddZddSymmSiftingConvOutOfMem;
538 if (table->
keysZ < (
unsigned) previousSize) {
539 (void) fprintf(table->
out,
"-");
540 }
else if (table->
keysZ > (
unsigned) previousSize) {
541 (void) fprintf(table->
out,
"+");
543 (void) fprintf(table->
out,
"\nSize increased from %d to %d while sifting variable %d\n", previousSize, table->
keysZ, var[i]);
546 (void) fprintf(table->
out,
"=");
557 (void) fprintf(table->
out,
"\n#:S_SIFTING %8d: symmetric variables\n",
559 (void) fprintf(table->
out,
"#:G_SIFTING %8d: symmetric groups\n",
568 cuddZddSymmSiftingConvOutOfMem:
614 int init_group_size, final_group_size;
616 initial_size = table->
keysZ;
622 for (i = x; i > x_low; i--) {
634 for (i = x; i < x_high; i++) {
639 while ((
unsigned) topbot < table->subtableZ[topbot].next)
651 while ((
unsigned) x < table->subtableZ[x].next)
655 init_group_size = x - i + 1;
661 goto cuddZddSymmSiftingAuxOutOfMem;
663 if (move_down == NULL ||
667 if (move_down != NULL)
672 while ((
unsigned) i < table->subtableZ[i].next) {
675 final_group_size = i - x + 1;
677 if (init_group_size == final_group_size) {
681 move_down, initial_size);
684 initial_size = table->
keysZ;
697 goto cuddZddSymmSiftingAuxOutOfMem;
699 else if (x == x_high) {
701 while ((
unsigned) x < table->subtableZ[x].next)
706 while ((
unsigned) i < table->subtableZ[i].next) {
709 init_group_size = i - x + 1;
714 goto cuddZddSymmSiftingAuxOutOfMem;
716 if (move_up == NULL ||
723 while ((
unsigned) x < table->subtableZ[x].next)
727 final_group_size = x - i + 1;
729 if (init_group_size == final_group_size) {
736 initial_size = table->
keysZ;
749 goto cuddZddSymmSiftingAuxOutOfMem;
751 else if ((x - x_low) > (x_high - x)) {
754 while ((
unsigned) x < table->subtableZ[x].next)
761 goto cuddZddSymmSiftingAuxOutOfMem;
763 if (move_down != NULL) {
770 while ((
unsigned) i < table->subtableZ[i].next) {
773 init_group_size = i - x + 1;
777 goto cuddZddSymmSiftingAuxOutOfMem;
779 if (move_up == NULL ||
783 if (move_up != NULL) {
787 while ((
unsigned) x < table->subtableZ[x].next)
791 final_group_size = x - i + 1;
793 if (init_group_size == final_group_size) {
800 while (move_down != NULL) {
801 move = move_down->
next;
805 initial_size = table->
keysZ;
818 goto cuddZddSymmSiftingAuxOutOfMem;
822 while ((
unsigned) x < table->subtableZ[x].next)
829 goto cuddZddSymmSiftingAuxOutOfMem;
831 if (move_up != NULL) {
835 while ((
unsigned) x < table->subtableZ[x].next)
839 init_group_size = x - i + 1;
844 goto cuddZddSymmSiftingAuxOutOfMem;
846 if (move_down == NULL ||
850 if (move_down != NULL) {
857 while ((
unsigned) i < table->subtableZ[i].next) {
860 final_group_size = i - x + 1;
862 if (init_group_size == final_group_size) {
869 while (move_up != NULL) {
870 move = move_up->
next;
874 initial_size = table->
keysZ;
887 goto cuddZddSymmSiftingAuxOutOfMem;
890 while (move_down != NULL) {
891 move = move_down->
next;
895 while (move_up != NULL) {
896 move = move_up->
next;
903 cuddZddSymmSiftingAuxOutOfMem:
905 while (move_down != NULL) {
906 move = move_down->
next;
912 while (move_up != NULL) {
913 move = move_up->
next;
953 int init_group_size, final_group_size;
955 initial_size = table->
keysZ;
962 init_group_size = x - i + 1;
968 goto cuddZddSymmSiftingConvAuxOutOfMem;
970 if (move_down == NULL ||
974 if (move_down != NULL)
977 while ((
unsigned) x < table->subtableZ[x].next)
982 while ((
unsigned) i < table->subtableZ[i].next) {
985 final_group_size = i - x + 1;
987 if (init_group_size == final_group_size) {
994 initial_size = table->
keysZ;
1007 goto cuddZddSymmSiftingConvAuxOutOfMem;
1009 else if (x == x_high) {
1011 while ((
unsigned) x < table->subtableZ[x].next)
1016 while ((
unsigned) i < table->subtableZ[i].next) {
1019 init_group_size = i - x + 1;
1024 goto cuddZddSymmSiftingConvAuxOutOfMem;
1026 if (move_up == NULL ||
1030 if (move_up != NULL)
1033 while ((
unsigned) x < table->subtableZ[x].next)
1037 final_group_size = x - i + 1;
1039 if (init_group_size == final_group_size) {
1046 initial_size = table->
keysZ;
1059 goto cuddZddSymmSiftingConvAuxOutOfMem;
1061 else if ((x - x_low) > (x_high - x)) {
1067 goto cuddZddSymmSiftingConvAuxOutOfMem;
1069 if (move_down != NULL) {
1073 while ((
unsigned) x < table->subtableZ[x].next)
1078 while ((
unsigned) i < table->subtableZ[i].next) {
1081 init_group_size = i - x + 1;
1085 goto cuddZddSymmSiftingConvAuxOutOfMem;
1087 if (move_up == NULL ||
1091 if (move_up != NULL) {
1095 while ((
unsigned) x < table->subtableZ[x].next)
1099 final_group_size = x - i + 1;
1101 if (init_group_size == final_group_size) {
1108 while (move_down != NULL) {
1109 move = move_down->
next;
1113 initial_size = table->
keysZ;
1126 goto cuddZddSymmSiftingConvAuxOutOfMem;
1135 goto cuddZddSymmSiftingConvAuxOutOfMem;
1137 if (move_up != NULL) {
1141 while ((
unsigned) x < table->subtableZ[x].next)
1145 init_group_size = x - i + 1;
1150 goto cuddZddSymmSiftingConvAuxOutOfMem;
1152 if (move_down == NULL ||
1156 if (move_down != NULL) {
1160 while ((
unsigned) x < table->subtableZ[x].next)
1165 while ((
unsigned) i < table->subtableZ[i].next) {
1168 final_group_size = i - x + 1;
1170 if (init_group_size == final_group_size) {
1177 while (move_up != NULL) {
1178 move = move_up->
next;
1182 initial_size = table->
keysZ;
1195 goto cuddZddSymmSiftingConvAuxOutOfMem;
1198 while (move_down != NULL) {
1199 move = move_down->
next;
1203 while (move_up != NULL) {
1204 move = move_up->
next;
1211 cuddZddSymmSiftingConvAuxOutOfMem:
1213 while (move_down != NULL) {
1214 move = move_down->
next;
1220 while (move_up != NULL) {
1221 move = move_up->
next;
1260 int limit_size = initial_size;
1265 while (y >= x_low) {
1280 goto cuddZddSymmSifting_upOutOfMem;
1283 goto cuddZddSymmSifting_upOutOfMem;
1292 if (size < limit_size)
1300 if (size < limit_size)
1309 cuddZddSymmSifting_upOutOfMem:
1310 while (moves != NULL) {
1348 int limit_size = initial_size;
1349 int i, gxtop, gybot;
1353 while (y <= x_high) {
1371 goto cuddZddSymmSifting_downOutOfMem;
1374 goto cuddZddSymmSifting_downOutOfMem;
1383 if (size < limit_size)
1393 if (size < limit_size)
1402 cuddZddSymmSifting_downOutOfMem:
1403 while (moves != NULL) {
1440 for (move = moves, i = 0; move != NULL; move = move->
next, i++) {
1441 if (move->
size < size) {
1447 for (move = moves, i = 0; move != NULL; move = move->
next, i++) {
1448 if (i == i_best)
break;
1452 if (!res)
return(0);
1457 if (i_best == -1 && res == size)
1489 int i, temp, gxtop, gxbot, gybot, yprev;
1490 int swapx = -1, swapy = -1;
1533 goto zdd_group_moveOutOfMem;
1554 goto zdd_group_moveOutOfMem;
1558 move->
next = *moves;
1561 return(table->
keysZ);
1563 zdd_group_moveOutOfMem:
1564 while (*moves != NULL) {
1565 move = (*moves)->
next;
1594 int i, temp, gxtop, gxbot, gybot, yprev;
1680 int TotalSymmGroups = 0;
1682 for (i = lower; i <= upper; i++) {
1697 *symvars = TotalSymm;
1698 *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)
#define ABC_ALLOC(type, num)
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)
#define ABC_NAMESPACE_IMPL_END
int cuddZddNextHigh(DdManager *table, int x)
DdNode * cuddDynamicAllocNode(DdManager *table)
#define ABC_NAMESPACE_IMPL_START
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)