94 static char rcsid[]
DD_UNUSED =
"$Id: cuddZddGroup.c,v 1.20 2009/02/19 16:25:36 fabio Exp $";
100 static int extsymmcalls;
102 static int secdiffcalls;
104 static int secdiffmisfire;
178 level = (low < (
unsigned int) dd->
sizeZ) ? dd->
permZ[low] : low;
245 tempTree = table->
treeZ == NULL;
250 nvars = table->
sizeZ;
253 if (pr > 0 && !tempTree)
254 (void) fprintf(table->
out,
"cuddZddTreeSifting:");
260 (void) fprintf(table->
out,
"\n");
263 for (i = 0; i < table->
size; i++) {
264 (void) fprintf(table->
out,
"%s%d",
265 (i == 0) ?
"" :
",", table->
invperm[i]);
267 (void) fprintf(table->
out,
"\n");
268 for (i = 0; i < table->
size; i++) {
269 (void) fprintf(table->
out,
"%s%d",
270 (i == 0) ?
"" :
",", table->
perm[i]);
272 (void) fprintf(table->
out,
"\n\n");
275 for (i = 0; i < table->
sizeZ; i++) {
276 (void) fprintf(table->
out,
"%s%d",
277 (i == 0) ?
"" :
",", table->
invpermZ[i]);
279 (void) fprintf(table->
out,
"\n");
280 for (i = 0; i < table->
sizeZ; i++) {
281 (void) fprintf(table->
out,
"%s%d",
282 (i == 0) ?
"" :
",", table->
permZ[i]);
284 (void) fprintf(table->
out,
"\n");
295 (void) fprintf(table->
out,
"\n");
297 (void) fprintf(table->
out,
"#:IM_NODES %8d: group tree nodes\n",
298 zddCountInternalMtrNodes(table,table->
treeZ));
305 for (i = 0; i < nvars; i++)
315 (void) fprintf(table->
out,
"\nextsymmcalls = %d\n",extsymmcalls);
316 (void) fprintf(table->
out,
"extsymm = %d",extsymm);
320 (void) fprintf(table->
out,
"\nsecdiffcalls = %d\n",secdiffcalls);
321 (void) fprintf(table->
out,
"secdiff = %d\n",secdiff);
322 (void) fprintf(table->
out,
"secdiffmisfire = %d",secdiffmisfire);
362 while (auxnode != NULL) {
363 if (auxnode->
child != NULL) {
369 }
else if (auxnode->
size > 1) {
393 zddCountInternalMtrNodes(
403 while (auxnode != NULL) {
406 count = zddCountInternalMtrNodes(table,auxnode->
child);
441 unsigned int initialSize;
452 (void) fprintf(table->
out,
" ");
464 initialSize = table->
keysZ;
466 if (initialSize <= table->keysZ)
470 (
void) fprintf(table->
out,
"\n");
472 }
while (result != 0);
488 initialSize = table->
keysZ;
490 if (initialSize <= table->keysZ)
494 (
void) fprintf(table->
out,
"\n");
496 }
while (result != 0);
510 if (pr > 0) (void) fprintf(table->
out,
"zddReorderChildren:");
547 if ((
int) treenode->
low >= table->
sizeZ) {
548 *lower = table->
sizeZ;
553 *lower = low = (
unsigned int) table->
permZ[treenode->
index];
554 high = (
int) (low + treenode->
size - 1);
556 if (high >= table->
sizeZ) {
565 if (auxnode == NULL) {
566 *upper = (
unsigned int) table->
sizeZ - 1;
573 while (auxnode != NULL) {
574 int thisLower = table->
permZ[auxnode->
low];
575 int thisUpper = thisLower + auxnode->
size - 1;
576 if (thisUpper >= table->
sizeZ && thisLower < table->sizeZ)
577 *upper = (
unsigned int) thisLower - 1;
583 *upper = (
unsigned int) high;
588 assert(treenode->
size >= *upper - *lower + 1);
615 return((*ptrX) - (*ptrY));
649 unsigned previousSize;
653 nvars = table->
sizeZ;
661 goto zddGroupSiftingOutOfMem;
666 goto zddGroupSiftingOutOfMem;
669 if (sifted == NULL) {
671 goto zddGroupSiftingOutOfMem;
675 for (i = 0, classes = 0; i < nvars; i++) {
692 if (sifted[xindex] == 1)
694 x = table->
permZ[xindex];
695 if (x < lower || x > upper)
698 previousSize = table->
keysZ;
705 if (!result)
goto zddGroupSiftingOutOfMem;
708 if (table->
keysZ < previousSize) {
709 (void) fprintf(table->
out,
"-");
710 }
else if (table->
keysZ > previousSize) {
711 (void) fprintf(table->
out,
"+");
713 (void) fprintf(table->
out,
"=");
719 x = table->
permZ[xindex];
726 }
while (x != xInit);
730 if (pr > 0) (void) fprintf(table->
out,
"zddGroupSifting:");
740 zddGroupSiftingOutOfMem:
743 if (sifted != NULL)
ABC_FREE(sifted);
779 if (pr > 0) (void) fprintf(table->
out,
"zddGroupSiftingAux from %d to %d\n",xLow,xHigh);
783 initialSize = table->
keysZ;
791 if (x == xHigh)
return(1);
794 goto zddGroupSiftingAuxOutOfMem;
802 if (!result)
goto zddGroupSiftingAuxOutOfMem;
813 goto zddGroupSiftingAuxOutOfMem;
821 if (!result)
goto zddGroupSiftingAuxOutOfMem;
823 }
else if (x - xLow > xHigh - x) {
825 goto zddGroupSiftingAuxOutOfMem;
832 while ((
unsigned) x < table->subtableZ[x].next)
837 assert((
unsigned) x <= table->subtableZ[x].next);
841 goto zddGroupSiftingAuxOutOfMem;
848 if (!result)
goto zddGroupSiftingAuxOutOfMem;
855 goto zddGroupSiftingAuxOutOfMem;
861 while ((
unsigned) x < table->subtableZ[x].next)
869 goto zddGroupSiftingAuxOutOfMem;
876 if (!result)
goto zddGroupSiftingAuxOutOfMem;
879 while (moves != NULL) {
887 zddGroupSiftingAuxOutOfMem:
888 while (moves != NULL) {
927 limitSize = table->
keysZ;
940 if (size == 0)
goto zddGroupSiftingUpOutOfMem;
942 if (move == NULL)
goto zddGroupSiftingUpOutOfMem;
951 if (pr > 0) (void) fprintf(table->
out,
"zddGroupSiftingUp (2 single groups):\n");
953 if ((
double) size > (double) limitSize * table->
maxGrowth)
955 if (size < limitSize) limitSize =
size;
958 if (size == 0)
goto zddGroupSiftingUpOutOfMem;
959 if ((
double) size > (
double) limitSize * table->
maxGrowth)
961 if (size < limitSize) limitSize =
size;
969 zddGroupSiftingUpOutOfMem:
970 while (*moves != NULL) {
971 move = (*moves)->
next;
1006 limitSize = size = table->
keysZ;
1008 while (y <= xHigh) {
1022 if (size == 0)
goto zddGroupSiftingDownOutOfMem;
1026 if (move == NULL)
goto zddGroupSiftingDownOutOfMem;
1031 move->
next = *moves;
1035 if (pr > 0) (void) fprintf(table->
out,
"zddGroupSiftingDown (2 single groups):\n");
1037 if ((
double) size > (double) limitSize * table->
maxGrowth)
1039 if (size < limitSize) limitSize =
size;
1044 if (size == 0)
goto zddGroupSiftingDownOutOfMem;
1045 if ((
double) size > (
double) limitSize * table->
maxGrowth)
1047 if (size < limitSize) limitSize =
size;
1055 zddGroupSiftingDownOutOfMem:
1056 while (*moves != NULL) {
1057 move = (*moves)->
next;
1086 int i,j,xtop,xbot,xsize,ytop,ybot,ysize,newxtop;
1087 int swapx=-1,swapy=-1;
1088 #if defined(DD_DEBUG) && defined(DD_VERBOSE)
1089 int initialSize,bestSize;
1099 xsize = xbot - xtop + 1;
1101 while ((
unsigned) ybot < table->subtableZ[ybot].next)
1104 ysize = ybot - ytop + 1;
1106 #if defined(DD_DEBUG) && defined(DD_VERBOSE)
1107 initialSize = bestSize = table->
keysZ;
1110 for (i = 1; i <= ysize; i++) {
1111 for (j = 1; j <= xsize; j++) {
1113 if (size == 0)
goto zddGroupMoveOutOfMem;
1114 #if defined(DD_DEBUG) && defined(DD_VERBOSE)
1115 if (size < bestSize)
1118 swapx = x; swapy = y;
1125 #if defined(DD_DEBUG) && defined(DD_VERBOSE)
1126 if ((bestSize < initialSize) && (bestSize < size))
1127 (void) fprintf(table->
out,
"Missed local minimum: initialSize:%d bestSize:%d finalSize:%d\n",initialSize,bestSize,size);
1132 for (i = 0; i < ysize - 1; i++) {
1140 for (i = 0; i < xsize - 1; i++) {
1147 if (pr > 0) (void) fprintf(table->
out,
"zddGroupMove:\n");
1152 if (move == NULL)
goto zddGroupMoveOutOfMem;
1157 move->
next = *moves;
1160 return(table->
keysZ);
1162 zddGroupMoveOutOfMem:
1163 while (*moves != NULL) {
1164 move = (*moves)->
next;
1190 int i,j,xtop,xbot,xsize,ytop,ybot,ysize,newxtop;
1201 xsize = xbot - xtop + 1;
1203 while ((
unsigned) ybot < table->subtableZ[ybot].next)
1206 ysize = ybot - ytop + 1;
1209 for (i = 1; i <= ysize; i++) {
1210 for (j = 1; j <= xsize; j++) {
1223 for (i = 0; i < ysize - 1; i++) {
1231 for (i = 0; i < xsize - 1; i++) {
1238 if (pr > 0) (void) fprintf(table->
out,
"zddGroupMoveBackward:\n");
1267 for (move = moves; move != NULL; move = move->
next) {
1268 if (move->
size < size) {
1273 for (move = moves; move != NULL; move = move->
next) {
1274 if (move->
size == size)
return(1);
1278 if (!res)
return(0);
1280 if (pr > 0) (void) fprintf(table->
out,
"zddGroupSiftingBackward:\n");
1286 if (!res)
return(0);
1320 if (treenode != table->
treeZ) {
1321 for (i = low; i < high; i++)
1328 saveindex = treenode->
index;
1332 auxnode->
index = newindex;
1333 if (auxnode->
parent == NULL ||
1336 auxnode = auxnode->
parent;
Cudd_AggregationType groupcheck
static int zddGroupMove(DdManager *table, int x, int y, Move **moves)
unsigned short MtrHalfWord
void cuddPrintVarGroups(DdManager *dd, MtrNode *root, int zdd, int silent)
int zddTotalNumberSwapping
static int zddGroupSifting(DdManager *table, int lower, int upper)
#define cuddDeallocMove(unique, node)
static int zddReorderChildren(DdManager *table, MtrNode *treenode, Cudd_ReorderingType method)
int(* DD_QSFP)(const void *, const void *)
int cuddZddSwapInPlace(DdManager *table, int x, int y)
#define ABC_ALLOC(type, num)
static void zddFindNodeHiLo(DdManager *table, MtrNode *treenode, int *lower, int *upper)
static int zddGroupSiftingUp(DdManager *table, int y, int xLow, Move **moves)
#define MTR_TEST(node, flag)
int cuddZddSymmSiftingConv(DdManager *table, int lower, int upper)
int cuddZddLinearSifting(DdManager *table, int lower, int upper)
static int zddGroupSiftingBackward(DdManager *table, Move *moves, int size)
static int zddUniqueCompareGroup(int *ptrX, int *ptrY)
#define ABC_NAMESPACE_IMPL_END
MtrNode * Cudd_MakeZddTreeNode(DdManager *dd, unsigned int low, unsigned int size, unsigned int type)
static int zddGroupSiftingDown(DdManager *table, int x, int xHigh, Move **moves)
int cuddZddSifting(DdManager *table, int lower, int upper)
int cuddZddNextHigh(DdManager *table, int x)
DdNode * cuddDynamicAllocNode(DdManager *table)
#define ABC_NAMESPACE_IMPL_START
void Mtr_PrintGroups(MtrNode *root, int silent)
int cuddZddSymmSifting(DdManager *table, int lower, int upper)
static int zddGroupSiftingAux(DdManager *table, int x, int xLow, int xHigh)
MtrNode * Mtr_InitGroupTree(int lower, int size)
int cuddZddTreeSifting(DdManager *table, Cudd_ReorderingType method)
int cuddZddSwapping(DdManager *table, int lower, int upper, Cudd_ReorderingType heuristic)
static int zddTreeSiftingAux(DdManager *table, MtrNode *treenode, Cudd_ReorderingType method)
static ABC_NAMESPACE_IMPL_START char rcsid[] DD_UNUSED
void Cudd_FreeZddTree(DdManager *dd)
static void zddMergeGroups(DdManager *table, MtrNode *treenode, int low, int high)
MtrNode * Mtr_MakeGroup(MtrNode *root, unsigned int low, unsigned int high, unsigned int flags)
static int zddGroupMoveBackward(DdManager *table, int x, int y)
int cuddZddNextLow(DdManager *table, int x)