80 #define JUMP_UP_PROB 0.36
81 #define MAXGEN_RATIO 15.0
99 static char rcsid[]
DD_UNUSED =
"$Id: cuddAnneal.c,v 1.14 2004/08/13 18:04:46 fabio Exp $";
104 extern int ddTotalNISwaps;
106 static int acceptances;
170 double NewTemp, temp;
172 int innerloop, maxGen;
173 int ecount, ucount, dcount;
175 nvars = upper - lower + 1;
179 (void) fprintf(table->
out,
"\n");
181 if (result == 0)
return(0);
188 if (BestOrder == NULL) {
201 ecount = ucount = dcount = 0;
205 (void) fprintf(table->
out,
"temp=%f\tsize=%d\tgen=%d\t",
207 tosses = acceptances = 0;
209 for (innerloop = 0; innerloop < maxGen; innerloop++) {
229 (void) fprintf(table->
out,
230 "Exchange of %d and %d: size = %d\n",
237 (void) fprintf(table->
out,
238 "Jump up of %d to %d: size = %d\n",
245 (void) fprintf(table->
out,
246 "Jump down of %d to %d: size = %d\n",
257 if (size < BestCost) {
266 NewTemp =
ALPHA * temp;
267 if (NewTemp >= 1.0) {
268 maxGen = (int)(log(NewTemp) / log(temp) * maxGen);
272 (void) fprintf(table->
out,
"uphill = %d\taccepted = %d\n",
280 if (!result)
return(0);
282 fprintf(table->
out,
"#:N_EXCHANGE %8d : total exchanges\n",ecount);
283 fprintf(table->
out,
"#:N_JUMPUP %8d : total jumps up\n",ucount);
284 fprintf(table->
out,
"#:N_JUMPDOWN %8d : total jumps down",dcount);
318 }
else if ((c1 == c2) && (c1 == c3) && (c1 == c4)) {
370 int initial_size, limit_size;
378 initial_size = limit_size = table->
keys - table->
isolated;
381 if (x_next == y_next) {
383 if (size == 0)
goto ddExchangeOutOfMem;
385 if (move == NULL)
goto ddExchangeOutOfMem;
392 if (size == 0)
goto ddExchangeOutOfMem;
394 if (move == NULL)
goto ddExchangeOutOfMem;
401 if (size == 0)
goto ddExchangeOutOfMem;
403 if (move == NULL)
goto ddExchangeOutOfMem;
413 }
else if (x == y_next) {
415 if (size == 0)
goto ddExchangeOutOfMem;
417 if (move == NULL)
goto ddExchangeOutOfMem;
428 if (size == 0)
goto ddExchangeOutOfMem;
430 if (move == NULL)
goto ddExchangeOutOfMem;
437 if (size == 0)
goto ddExchangeOutOfMem;
439 if (move == NULL)
goto ddExchangeOutOfMem;
451 if (x_next > y_ref)
break;
455 }
else if (size < limit_size) {
462 if (size == 0)
goto ddExchangeOutOfMem;
464 if (move == NULL)
goto ddExchangeOutOfMem;
474 if (!result)
goto ddExchangeOutOfMem;
476 while (moves != NULL) {
484 while (moves != NULL) {
532 if (moves == NULL)
goto ddJumpingAuxOutOfMem;
535 if (!result)
goto ddJumpingAuxOutOfMem;
539 if (moves == NULL)
goto ddJumpingAuxOutOfMem;
542 if (!result)
goto ddJumpingAuxOutOfMem;
544 (void) fprintf(table->
err,
"Unexpected condition in ddJumping\n");
545 goto ddJumpingAuxOutOfMem;
547 while (moves != NULL) {
554 ddJumpingAuxOutOfMem:
555 while (moves != NULL) {
589 int limit_size = initial_size;
595 if (size == 0)
goto ddJumpingUpOutOfMem;
597 if (move == NULL)
goto ddJumpingUpOutOfMem;
603 if ((
double) size > table->
maxGrowth * (double) limit_size) {
605 }
else if (size < limit_size) {
614 while (moves != NULL) {
648 int limit_size = initial_size;
652 while (y <= x_high) {
654 if (size == 0)
goto ddJumpingDownOutOfMem;
656 if (move == NULL)
goto ddJumpingDownOutOfMem;
662 if ((
double) size > table->
maxGrowth * (double) limit_size) {
664 }
else if (size < limit_size) {
672 ddJumpingDownOutOfMem:
673 while (moves != NULL) {
706 int best_size =
size;
707 double coin, threshold;
710 for (move = moves; move != NULL; move = move->
next) {
711 if (move->
size < best_size) {
712 best_size = move->
size;
720 if (best_size == size) {
725 threshold = exp(-((
double)(table->
keys - table->
isolated - size))/temp);
726 if (coin < threshold) {
738 for (move = moves; move != NULL; move = move->
next) {
739 if (res == best_size)
return(1);
771 nvars = upper - lower + 1;
772 for (i = 0; i < nvars; i++) {
773 array[i] = table->
invperm[i+lower];
799 int nvars = upper - lower + 1;
801 for (i = 0; i < nvars; i++) {
802 x = table->
perm[array[i]];
804 assert(x >= lower && x <= upper);
807 while (y >= i + lower) {
809 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)
#define ABC_ALLOC(type, num)
static int restoreOrder(DdManager *table, int *array, int lower, int upper)
static int ddExchange(DdManager *table, int x, int y, double temp)
int ddTotalNumberSwapping
#define ABC_NAMESPACE_IMPL_END
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)
#define ABC_NAMESPACE_IMPL_START
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)