SIGINT handler, for partial result.
This commit is contained in:
16
best.c
16
best.c
@@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <values.h>
|
#include <values.h>
|
||||||
|
#include <signal.h>
|
||||||
#include "lceb.h"
|
#include "lceb.h"
|
||||||
|
|
||||||
static int target=0;
|
static int target=0;
|
||||||
@@ -12,13 +13,26 @@ static int bestops=MAXINT;
|
|||||||
|
|
||||||
static BEST bests[1024*10]; /* TODO: should be dynamic */
|
static BEST bests[1024*10]; /* TODO: should be dynamic */
|
||||||
static int nbests=0;
|
static int nbests=0;
|
||||||
|
static int sigint=0;
|
||||||
|
|
||||||
#define DIFF(a, b) ((a)>(b)?(a)-(b):(b)-(a))
|
#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)
|
void set_target(n)
|
||||||
int n;
|
int n;
|
||||||
{
|
{
|
||||||
target=n;
|
target=n;
|
||||||
|
signal(SIGINT, stopall);
|
||||||
}
|
}
|
||||||
|
|
||||||
int check_best(res, nops, node, values, ops)
|
int check_best(res, nops, node, values, ops)
|
||||||
@@ -104,7 +118,7 @@ void print_bests()
|
|||||||
for (i=0; i<nbests; ++i) {
|
for (i=0; i<nbests; ++i) {
|
||||||
//print_best(bests[i].root, bests[i].values, bests[i].oper, 0);
|
//print_best(bests[i].root, bests[i].values, bests[i].oper, 0);
|
||||||
printf("%3d: %d = ", i, bests[i].res);
|
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');
|
putchar('\n');
|
||||||
//printf("%3d: %d = ", i, bests[i].res);
|
//printf("%3d: %d = ", i, bests[i].res);
|
||||||
//print_node(bests[i].root, TREE_TOP, 0, 1);
|
//print_node(bests[i].root, TREE_TOP, 0, 1);
|
||||||
|
4
eval.c
4
eval.c
@@ -80,6 +80,10 @@ int eval_node(node, depth, pvals, pops, ncalcs)
|
|||||||
if (!check_best(res, *ncalcs, node, val_zero, ops_zero))
|
if (!check_best(res, *ncalcs, node, val_zero, ops_zero))
|
||||||
res=-1;
|
res=-1;
|
||||||
}
|
}
|
||||||
|
if (stopped()) {
|
||||||
|
print_bests();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
# ifdef DEBUG1
|
# ifdef DEBUG1
|
||||||
for (i=0; i<=depth; ++i)
|
for (i=0; i<=depth; ++i)
|
||||||
printf(" ");
|
printf(" ");
|
||||||
|
1
lceb.h
1
lceb.h
@@ -105,6 +105,7 @@ extern char *nth_comb(int n);
|
|||||||
extern int eval_node(NODE *node, int depth, int *pvals, char *pops, int *ncalcs);
|
extern int eval_node(NODE *node, int depth, int *pvals, char *pops, int *ncalcs);
|
||||||
|
|
||||||
/* best.c */
|
/* best.c */
|
||||||
|
extern int stopped();
|
||||||
extern void set_target (int n);
|
extern void set_target (int n);
|
||||||
extern int check_best(int res, int nops, NODE *node, int *values, char *ops);
|
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);
|
extern void print_best(NODE *node, int *values, char *pops, int depth);
|
||||||
|
Reference in New Issue
Block a user