76 #define JUMP_UP_PROB 0.36 77 #define MAXGEN_RATIO 15.0 95 static char rcsid[]
DD_UNUSED =
"$Id: cuddAnneal.c,v 1.15 2012/02/05 01:07:18 fabio Exp $";
100 extern int ddTotalNISwaps;
102 static int acceptances;
166 double NewTemp, temp;
168 int innerloop, maxGen;
169 int ecount, ucount, dcount;
171 nvars = upper - lower + 1;
175 (void) fprintf(table->
out,
"\n");
177 if (result == 0)
return(0);
183 BestOrder =
ALLOC(
int,nvars);
184 if (BestOrder == NULL) {
197 ecount = ucount = dcount = 0;
201 (void) fprintf(table->
out,
"temp=%f\tsize=%d\tgen=%d\t",
203 tosses = acceptances = 0;
205 for (innerloop = 0; innerloop < maxGen; innerloop++) {
225 (void) fprintf(table->
out,
226 "Exchange of %d and %d: size = %d\n",
233 (void) fprintf(table->
out,
234 "Jump up of %d to %d: size = %d\n",
241 (void) fprintf(table->
out,
242 "Jump down of %d to %d: size = %d\n",
253 if (size < BestCost) {
262 NewTemp =
ALPHA * temp;
263 if (NewTemp >= 1.0) {
264 maxGen = (int)(log(NewTemp) / log(temp) * maxGen);
268 (void) fprintf(table->
out,
"uphill = %d\taccepted = %d\n",
276 if (!result)
return(0);
278 fprintf(table->
out,
"#:N_EXCHANGE %8d : total exchanges\n",ecount);
279 fprintf(table->
out,
"#:N_JUMPUP %8d : total jumps up\n",ucount);
280 fprintf(table->
out,
"#:N_JUMPDOWN %8d : total jumps down",dcount);
314 }
else if ((c1 == c2) && (c1 == c3) && (c1 == c4)) {
366 int initial_size, limit_size;
374 initial_size = limit_size = table->
keys - table->
isolated;
377 if (x_next == y_next) {
379 if (size == 0)
goto ddExchangeOutOfMem;
381 if (move == NULL)
goto ddExchangeOutOfMem;
388 if (size == 0)
goto ddExchangeOutOfMem;
390 if (move == NULL)
goto ddExchangeOutOfMem;
397 if (size == 0)
goto ddExchangeOutOfMem;
399 if (move == NULL)
goto ddExchangeOutOfMem;
409 }
else if (x == y_next) {
411 if (size == 0)
goto ddExchangeOutOfMem;
413 if (move == NULL)
goto ddExchangeOutOfMem;
424 if (size == 0)
goto ddExchangeOutOfMem;
426 if (move == NULL)
goto ddExchangeOutOfMem;
433 if (size == 0)
goto ddExchangeOutOfMem;
435 if (move == NULL)
goto ddExchangeOutOfMem;
447 if (x_next > y_ref)
break;
451 }
else if (size < limit_size) {
458 if (size == 0)
goto ddExchangeOutOfMem;
460 if (move == NULL)
goto ddExchangeOutOfMem;
470 if (!result)
goto ddExchangeOutOfMem;
472 while (moves != NULL) {
480 while (moves != NULL) {
528 if (moves == NULL)
goto ddJumpingAuxOutOfMem;
531 if (!result)
goto ddJumpingAuxOutOfMem;
535 if (moves == NULL)
goto ddJumpingAuxOutOfMem;
538 if (!result)
goto ddJumpingAuxOutOfMem;
540 (void) fprintf(table->
err,
"Unexpected condition in ddJumping\n");
541 goto ddJumpingAuxOutOfMem;
543 while (moves != NULL) {
550 ddJumpingAuxOutOfMem:
551 while (moves != NULL) {
585 int limit_size = initial_size;
591 if (size == 0)
goto ddJumpingUpOutOfMem;
593 if (move == NULL)
goto ddJumpingUpOutOfMem;
599 if ((
double) size > table->
maxGrowth * (double) limit_size) {
601 }
else if (size < limit_size) {
610 while (moves != NULL) {
644 int limit_size = initial_size;
648 while (y <= x_high) {
650 if (size == 0)
goto ddJumpingDownOutOfMem;
652 if (move == NULL)
goto ddJumpingDownOutOfMem;
658 if ((
double) size > table->
maxGrowth * (double) limit_size) {
660 }
else if (size < limit_size) {
668 ddJumpingDownOutOfMem:
669 while (moves != NULL) {
702 int best_size = size;
703 double coin, threshold;
706 for (move = moves; move != NULL; move = move->
next) {
707 if (move->
size < best_size) {
708 best_size = move->
size;
716 if (best_size == size) {
721 threshold = exp(-((
double)(table->
keys - table->
isolated - size))/temp);
722 if (coin < threshold) {
734 for (move = moves; move != NULL; move = move->
next) {
735 if (res == best_size)
return(1);
767 nvars = upper - lower + 1;
768 for (i = 0; i < nvars; i++) {
769 array[i] = table->
invperm[i+lower];
795 int nvars = upper - lower + 1;
797 for (i = 0; i < nvars; i++) {
798 x = table->
perm[array[i]];
800 assert(x >= lower && x <= upper);
803 while (y >= i + lower) {
805 if (size == 0)
return(0);
#define cuddDeallocMove(unique, node)
static int stopping_criterion(int c1, int c2, int c3, int c4, double temp)
static void copyOrder(DdManager *table, int *array, int lower, int upper)
static double random_generator(void)
int cuddNextLow(DdManager *table, int x)
int cuddSifting(DdManager *table, int lower, int upper)
static int restoreOrder(DdManager *table, int *array, int lower, int upper)
static int ddExchange(DdManager *table, int x, int y, double temp)
int ddTotalNumberSwapping
static int ddJumpingAux(DdManager *table, int x, int x_low, int x_high, double temp)
DdNode * cuddDynamicAllocNode(DdManager *table)
static char rcsid [] DD_UNUSED
static Move * ddJumpingUp(DdManager *table, int x, int x_low, int initial_size)
int cuddNextHigh(DdManager *table, int x)
int cuddSwapInPlace(DdManager *table, int x, int y)
static int siftBackwardProb(DdManager *table, Move *moves, int size, double temp)
int cuddAnnealing(DdManager *table, int lower, int upper)
#define DD_MAX_REORDER_GROWTH
static Move * ddJumpingDown(DdManager *table, int x, int x_high, int initial_size)