Added timer for bests solutions
This commit is contained in:
34
best.c
34
best.c
@@ -13,19 +13,19 @@ static int bestops=MAXINT;
|
||||
|
||||
static BEST bests[1024*10]; /* TODO: should be dynamic */
|
||||
static int nbests=0;
|
||||
static int sigint=0;
|
||||
int sigint_received=0;
|
||||
|
||||
#define DIFF(a, b) ((a)>(b)?(a)-(b):(b)-(a))
|
||||
|
||||
void stopall()
|
||||
{
|
||||
printf("SIGINT RECEIVED: aborting eval\n");
|
||||
sigint=1;
|
||||
sigint_received=1;
|
||||
}
|
||||
|
||||
int stopped()
|
||||
{
|
||||
return sigint;
|
||||
return sigint_received;
|
||||
}
|
||||
|
||||
void set_target(n)
|
||||
@@ -45,17 +45,10 @@ int check_best(res, nops, node, values, ops)
|
||||
int diff, found=0, i=0;
|
||||
|
||||
diff=DIFF(target, res);
|
||||
# ifdef DEBUG1
|
||||
# ifdef DEBUG_BEST1
|
||||
printf("check_best: res=%d diff=%d nops=%d\n", res, diff, nops);
|
||||
# endif
|
||||
if (diff < bestdiff || (diff == bestdiff && nops < bestops)) {
|
||||
# ifdef DEBUG
|
||||
// printf("NEW BEST! res=%d diff=%d nops=%d\n", res, diff, nops);
|
||||
printf("diff=%d nops=%d %d=", diff, nops, res);
|
||||
print_node(node, TREE_TOP, 0, 4);
|
||||
putchar('\n');
|
||||
//printf("check_best: res=%d diff=%d nops=%d\n", res, diff, nops);
|
||||
# endif
|
||||
//best=res;
|
||||
// clear old bests
|
||||
for (i=0; i<nbests; ++i)
|
||||
@@ -65,20 +58,29 @@ int check_best(res, nops, node, values, ops)
|
||||
nbests=0;
|
||||
found=1;
|
||||
//return 1;
|
||||
} else if (diff == bestdiff && nops == bestops) {
|
||||
# ifdef DEBUG1
|
||||
}/* else if (diff == bestdiff && nops == bestops) {
|
||||
# ifdef DEBUG_BEST
|
||||
printf("NEW BEST SOLUTION (%d): res=%d diff=%d nops=%d\n", nbests+1, res, diff, nops);
|
||||
print_node(node, TREE_TOP, 0, 0);
|
||||
# endif
|
||||
found=2;
|
||||
}
|
||||
}*/
|
||||
if (found==1) {
|
||||
set_timer(&(bests[nbests].timer));
|
||||
bests[nbests].res=res;
|
||||
bests[nbests].diff=diff;
|
||||
bests[nbests].nops=nops;
|
||||
bests[nbests].oper=ops;
|
||||
bests[nbests].root=dup_node(node);
|
||||
bests[nbests].values=values;
|
||||
# ifdef DEBUG_BEST
|
||||
// printf("NEW BEST! res=%d diff=%d nops=%d\n", res, diff, nops);
|
||||
printf("%.5f: diff=%d nops=%d %d=", get_timer(bests[nbests].timer),
|
||||
diff, nops, res);
|
||||
print_node(node, TREE_TOP, 0, 4);
|
||||
putchar('\n');
|
||||
//printf("check_best: res=%d diff=%d nops=%d\n", res, diff, nops);
|
||||
# endif
|
||||
nbests++;
|
||||
return diff;
|
||||
}
|
||||
@@ -114,10 +116,10 @@ void print_best(node, values, pops, depth)
|
||||
void print_bests()
|
||||
{
|
||||
int i;
|
||||
printf("BESTS: diff=%d solutions=%d nops=%d\n", bestdiff, nbests, bestops);
|
||||
printf("BEST SOLUTION: diff=%d ops=%d\n", bestdiff, bestops);
|
||||
for (i=0; i<nbests; ++i) {
|
||||
//print_best(bests[i].root, bests[i].values, bests[i].oper, 0);
|
||||
printf("%3d: %d = ", i, bests[i].res);
|
||||
printf("%.5f secs: %5d = ", get_timer(bests[i].timer), bests[i].res);
|
||||
print_node(bests[i].root, TREE_TOP, 0, 4);
|
||||
putchar('\n');
|
||||
//printf("%3d: %d = ", i, bests[i].res);
|
||||
|
Reference in New Issue
Block a user