87 #define DD_MAX_SUBTABLE_SPARSITY 8
88 #define DD_SHRINK_FACTOR 2
105 static char rcsid[]
DD_UNUSED =
"$Id: cuddZddReord.c,v 1.47 2004/08/13 18:04:53 fabio Exp $";
178 unsigned int nextDyn;
180 unsigned int initialSize;
181 unsigned int finalSize;
186 if (table->
keysZ - table->
deadZ < (
unsigned) minsize)
206 while (hook != NULL) {
207 int res = (hook->
f)(table,
"ZDD", (
void *)heuristic);
208 if (res == 0)
return(0);
217 initialSize = table->
keysZ;
222 (void) fprintf(table->
out,
"#:I_RANDOM ");
228 (void) fprintf(table->
out,
"#:I_SIFTING ");
232 (void) fprintf(table->
out,
"#:I_LINSIFT ");
235 (void) fprintf(table->
err,
"Unsupported ZDD reordering method\n");
238 (void) fprintf(table->
out,
"%8d: initial size",initialSize);
244 (void) fprintf(table->
out,
"\n");
245 finalSize = table->
keysZ;
246 (void) fprintf(table->
out,
"#:F_REORDER %8d: final size\n",finalSize);
247 (void) fprintf(table->
out,
"#:T_REORDER %8g: total time (sec)\n",
249 (void) fprintf(table->
out,
"#:N_REORDER %8d: total swaps\n",
274 while (hook != NULL) {
275 int res = (hook->
f)(table,
"ZDD", (
void *)localTime);
276 if (res == 0)
return(0);
361 if (table->
sizeZ == 0)
373 if (invpermZ == NULL) {
377 for (i = 0; i < table->
size; i++) {
379 int indexZ = index *
M;
380 int levelZ = table->
permZ[indexZ];
381 levelZ = (levelZ /
M) * M;
382 for (j = 0; j <
M; j++) {
383 invpermZ[M * i + j] = table->
invpermZ[levelZ + j];
493 int oldxkeys, oldykeys;
494 int newxkeys, newykeys;
497 DdNode *f, *f1, *f0, *f11, *f10, *f01, *f00;
498 DdNode *newf1=NULL, *newf0, *next;
535 for (i = 0; i < xslots; i++) {
536 previousP = &(xlist[i]);
545 previousP = &(f->
next);
559 table->swapSteps += oldxkeys - newxkeys;
570 if ((
int) f1->
index == yindex) {
573 f11 =
empty; f10 = f1;
576 if ((
int) f0->
index == yindex) {
579 f01 =
empty; f00 = f0;
598 while (newf1 != NULL) {
599 if (
cuddT(newf1) == f11 &&
cuddE(newf1) == f01) {
608 goto zddSwapOutOfMem;
609 newf1->
index = xindex; newf1->
ref = 1;
616 newf1->
next = xlist[posn];
636 while (newf0 != NULL) {
637 if (
cuddT(newf0) == f10 &&
cuddE(newf0) == f00) {
646 goto zddSwapOutOfMem;
647 newf0->index = xindex; newf0->ref = 1;
653 newf0->
next = xlist[posn];
667 f->
next = ylist[posn];
675 for (i = 0; i < yslots; i++) {
676 previousP = &(ylist[i]);
687 previousP = &(f->
next);
707 table->
permZ[xindex] = y; table->
permZ[yindex] = x;
710 table->
keysZ += newxkeys + newykeys - oldxkeys - oldykeys;
715 return (table->
keysZ);
718 (void) fprintf(table->
err,
"Error: cuddZddSwapInPlace out of memory\n");
765 assert(lower >= 0 && upper < table->sizeZ && lower <= upper);
768 nvars = upper - lower + 1;
771 for (i = 0; i < iterate; i++) {
774 for (max = -1, j = lower; j <= upper; j++) {
781 modulo = upper - pivot;
789 modulo = pivot - lower - 1;
806 previousSize = table->
keysZ;
809 goto cuddZddSwappingOutOfMem;
813 goto cuddZddSwappingOutOfMem;
815 while (moves != NULL) {
821 if (table->
keysZ < (
unsigned) previousSize) {
822 (void) fprintf(table->
out,
"-");
823 }
else if (table->
keysZ > (
unsigned) previousSize) {
824 (void) fprintf(table->
out,
"+");
826 (void) fprintf(table->
out,
"=");
834 cuddZddSwappingOutOfMem:
835 while (moves != NULL) {
888 goto cuddZddSiftingOutOfMem;
893 goto cuddZddSiftingOutOfMem;
896 for (i = 0; i <
size; i++) {
908 x = table->
permZ[var[i]];
909 if (x < lower || x > upper)
continue;
911 previousSize = table->
keysZ;
915 goto cuddZddSiftingOutOfMem;
917 if (table->
keysZ < (
unsigned) previousSize) {
918 (void) fprintf(table->
out,
"-");
919 }
else if (table->
keysZ > (
unsigned) previousSize) {
920 (void) fprintf(table->
out,
"+");
921 (void) fprintf(table->
out,
"\nSize increased from %d to %d while sifting variable %d\n", previousSize, table->
keysZ , var[i]);
923 (void) fprintf(table->
out,
"=");
934 cuddZddSiftingOutOfMem:
973 tmp = x; x = y; y = tmp;
976 x_ref = x; y_ref = y;
981 limit_size = table->
keysZ;
984 if (x_next == y_next) {
987 goto zddSwapAnyOutOfMem;
990 goto zddSwapAnyOutOfMem;
999 goto zddSwapAnyOutOfMem;
1002 goto zddSwapAnyOutOfMem;
1011 goto zddSwapAnyOutOfMem;
1014 goto zddSwapAnyOutOfMem;
1021 tmp = x; x = y; y = tmp;
1023 }
else if (x == y_next) {
1026 goto zddSwapAnyOutOfMem;
1029 goto zddSwapAnyOutOfMem;
1036 tmp = x; x = y; y = tmp;
1040 goto zddSwapAnyOutOfMem;
1043 goto zddSwapAnyOutOfMem;
1052 goto zddSwapAnyOutOfMem;
1055 goto zddSwapAnyOutOfMem;
1062 x = x_next; y = y_next;
1070 if ((
double) size > table->
maxGrowth * (
double) limit_size)
1072 if (size < limit_size)
1075 if (y_next >= x_ref) {
1078 goto zddSwapAnyOutOfMem;
1081 goto zddSwapAnyOutOfMem;
1092 while (moves != NULL) {
1130 initial_size = table->
keysZ;
1142 if (moveDown == NULL)
1143 goto cuddZddSiftingAuxOutOfMem;
1148 goto cuddZddSiftingAuxOutOfMem;
1151 else if (x == x_high) {
1155 goto cuddZddSiftingAuxOutOfMem;
1159 goto cuddZddSiftingAuxOutOfMem;
1161 else if ((x - x_low) > (x_high - x)) {
1165 if (moveDown == NULL)
1166 goto cuddZddSiftingAuxOutOfMem;
1170 goto cuddZddSiftingAuxOutOfMem;
1174 goto cuddZddSiftingAuxOutOfMem;
1180 goto cuddZddSiftingAuxOutOfMem;
1184 if (moveDown == NULL)
1185 goto cuddZddSiftingAuxOutOfMem;
1190 goto cuddZddSiftingAuxOutOfMem;
1193 while (moveDown != NULL) {
1194 move = moveDown->
next;
1198 while (moveUp != NULL) {
1199 move = moveUp->
next;
1206 cuddZddSiftingAuxOutOfMem:
1207 while (moveDown != NULL) {
1208 move = moveDown->
next;
1212 while (moveUp != NULL) {
1213 move = moveUp->
next;
1247 int limit_size = initial_size;
1251 while (y >= x_low) {
1254 goto cuddZddSiftingUpOutOfMem;
1257 goto cuddZddSiftingUpOutOfMem;
1264 if ((
double)size > (double)limit_size * table->
maxGrowth)
1266 if (size < limit_size)
1274 cuddZddSiftingUpOutOfMem:
1275 while (moves != NULL) {
1310 int limit_size = initial_size;
1314 while (y <= x_high) {
1317 goto cuddZddSiftingDownOutOfMem;
1320 goto cuddZddSiftingDownOutOfMem;
1327 if ((
double)size > (double)limit_size * table->
maxGrowth)
1329 if (size < limit_size)
1337 cuddZddSiftingDownOutOfMem:
1338 while (moves != NULL) {
1376 for (move = moves, i = 0; move != NULL; move = move->
next, i++) {
1377 if (move->
size < size) {
1383 for (move = moves, i = 0; move != NULL; move = move->
next, i++) {
1389 if (i_best == -1 && res == size)
1445 unsigned int slots, oldslots;
1450 (void) fflush(table->
out);
1462 for (i = 0; i < table->
sizeZ; i++) {
1466 oldslots <= table->initSlots)
continue;
1468 slots = oldslots >> 1;
1472 MMoutOfMemory = saveHandler;
1473 if (nodelist == NULL) {
1481 (void) fprintf(table->
err,
1482 "shrunk layer %d (%d keys) from %d to %d slots\n",
1486 for (j = 0; (unsigned) j < slots; j++) {
1490 for (j = 0; (unsigned) j < oldslots; j++) {
1491 node = oldnodelist[j];
1492 while (node != NULL) {
1495 node->
next = nodelist[posn];
1496 nodelist[posn] = node;
1503 table->
slots += slots - oldslots;
1553 initialSize = table->
keysZ;
1554 (void) fprintf(table->
out,
"#:I_SHUFFLE %8d: initial size\n",
1558 numvars = table->
sizeZ;
1560 for (level = 0; level <
numvars; level++) {
1561 index = permutation[level];
1562 position = table->
permZ[index];
1564 previousSize = table->
keysZ;
1566 result =
zddSiftUp(table,position,level);
1567 if (!result)
return(0);
1569 if (table->
keysZ < (
unsigned) previousSize) {
1570 (void) fprintf(table->
out,
"-");
1571 }
else if (table->
keysZ > (
unsigned) previousSize) {
1572 (void) fprintf(table->
out,
"+");
1574 (void) fprintf(table->
out,
"=");
1581 (void) fprintf(table->
out,
"\n");
1582 finalSize = table->
keysZ;
1583 (void) fprintf(table->
out,
"#:F_SHUFFLE %8d: final size\n",finalSize);
1584 (void) fprintf(table->
out,
"#:T_SHUFFLE %8g: total time (sec)\n",
1586 (void) fprintf(table->
out,
"#:N_SHUFFLE %8d: total swaps\n",
1649 if (treenode == NULL)
return;
1652 if (treenode->
child != NULL) {
1655 if (treenode->
younger != NULL)
static Move * cuddZddSiftingUp(DdManager *table, int x, int x_low, int initial_size)
void cuddCacheFlush(DdManager *table)
unsigned short DdHalfWord
int cuddZddSwapping(DdManager *table, int lower, int upper, Cudd_ReorderingType heuristic)
void Cudd_OutOfMem(long size)
#define cuddDeallocMove(unique, node)
static char rcsid[] DD_UNUSED
DdHook * preReorderingHook
static Move * cuddZddSiftingDown(DdManager *table, int x, int x_high, int initial_size)
static void zddReorderPreprocess(DdManager *table)
int(* DD_QSFP)(const void *, const void *)
unsigned int maxCacheHard
int cuddZddNextHigh(DdManager *table, int x)
int cuddZddSwapInPlace(DdManager *table, int x, int y)
#define ABC_ALLOC(type, num)
Cudd_ReorderingType autoMethodZ
word M(word f1, word f2, int n)
#define DD_MAX_SUBTABLE_DENSITY
int cuddZddNextLow(DdManager *table, int x)
int cuddGarbageCollect(DdManager *unique, int clearCache)
#define DD_MAX_SUBTABLE_SPARSITY
static int cuddZddSiftingAux(DdManager *table, int x, int x_low, int x_high)
DdHook * postReorderingHook
int zddTotalNumberSwapping
int cuddZddSifting(DdManager *table, int lower, int upper)
#define ABC_NAMESPACE_IMPL_END
static Move * zddSwapAny(DdManager *table, int x, int y)
static int zddReorderPostprocess(DdManager *table)
#define DD_MAX_CACHE_TO_SLOTS_RATIO
int cuddZddUniqueCompare(int *ptr_x, int *ptr_y)
DdNode * cuddDynamicAllocNode(DdManager *table)
static int zddSiftUp(DdManager *table, int x, int xLow)
#define cuddDeallocNode(unique, node)
#define ABC_NAMESPACE_IMPL_START
int cuddZddAlignToBdd(DdManager *table)
static int cuddZddSiftingBackward(DdManager *table, Move *moves, int size)
int cuddZddTreeSifting(DdManager *table, Cudd_ReorderingType method)
static void zddFixTree(DdManager *table, MtrNode *treenode)
int cuddBddAlignToZdd(DdManager *table)
static int zddShuffle(DdManager *table, int *permutation)
int Cudd_zddShuffleHeap(DdManager *table, int *permutation)
int Cudd_zddReduceHeap(DdManager *table, Cudd_ReorderingType heuristic, int minsize)