SIGINT handler, for partial result.

This commit is contained in:
2021-01-23 15:26:00 +01:00
parent 0931d679fa
commit 5025303e18
3 changed files with 20 additions and 1 deletions

16
best.c
View File

@@ -3,6 +3,7 @@
#include <string.h>
#include <malloc.h>
#include <values.h>
#include <signal.h>
#include "lceb.h"
static int target=0;
@@ -12,13 +13,26 @@ static int bestops=MAXINT;
static BEST bests[1024*10]; /* TODO: should be dynamic */
static int nbests=0;
static int sigint=0;
#define DIFF(a, b) ((a)>(b)?(a)-(b):(b)-(a))
void stopall()
{
printf("SIGINT RECEIVED: aborting eval\n");
sigint=1;
}
int stopped()
{
return sigint;
}
void set_target(n)
int n;
{
target=n;
signal(SIGINT, stopall);
}
int check_best(res, nops, node, values, ops)
@@ -104,7 +118,7 @@ void print_bests()
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);
print_node(bests[i].root, TREE_TOP, 0, 0);
print_node(bests[i].root, TREE_TOP, 0, 4);
putchar('\n');
//printf("%3d: %d = ", i, bests[i].res);
//print_node(bests[i].root, TREE_TOP, 0, 1);

4
eval.c
View File

@@ -80,6 +80,10 @@ int eval_node(node, depth, pvals, pops, ncalcs)
if (!check_best(res, *ncalcs, node, val_zero, ops_zero))
res=-1;
}
if (stopped()) {
print_bests();
exit(1);
}
# ifdef DEBUG1
for (i=0; i<=depth; ++i)
printf(" ");

1
lceb.h
View File

@@ -105,6 +105,7 @@ extern char *nth_comb(int n);
extern int eval_node(NODE *node, int depth, int *pvals, char *pops, int *ncalcs);
/* best.c */
extern int stopped();
extern void set_target (int n);
extern int check_best(int res, int nops, NODE *node, int *values, char *ops);
extern void print_best(NODE *node, int *values, char *pops, int depth);