DEBUG flags cleanup, some dead code removal

This commit is contained in:
2021-01-26 15:02:04 +01:00
parent c1d0085217
commit 157c64bd6e
7 changed files with 110 additions and 102 deletions

80
lceb.c
View File

@@ -20,9 +20,19 @@
static char *cmd;
static int treetype=TREE_CATALAN;
extern int displaytimer, displayintermediate, displaytype;
extern int displaytimer, displayintermediate, displaytype, firstonly;
int displaysummary=1;
void print_results()
{
struct timespec end;
print_bests();
set_timer(&end);
if (displaysummary)
printf("Total time elapsed: %.5f secs, nodes/leaves evaluated:%'d/%'d\n",
get_timer(end), get_totnodes(), get_totleaves());
}
void usage()
{
fprintf(stderr, "usage: %s [options] target n1 n2 [...n%d]\n", cmd, MAXINPUT);
@@ -32,6 +42,7 @@ void help()
{
usage();
fprintf(stderr, "Countdown game solver.\n");
fprintf(stderr, " -1: Stops immediately when one solution is found\n");
fprintf(stderr, " -c: Show solutions timer\n");
fprintf(stderr, " -d TYPE: Solutions display type. TYPE can be:\n");
fprintf(stderr, " r: RPN (default)\n");
@@ -64,10 +75,9 @@ int main(ac, av)
TREE *tree;
char intarray[1024];
char *comb;
struct timespec end;
char *options="thcisd:";
char *options="1thcisd:";
int option;
# ifdef DEBUG_MAIN
# ifdef DEBUG_MAINLOOP
int eval;
# endif
@@ -76,6 +86,9 @@ int main(ac, av)
while ((option = getopt(ac, av, options)) != -1) {
//printf("opt: %c\n", option);
switch (option) {
case '1':
firstonly=1;
break;
case 'd':
switch(*optarg) {
case 'r':
@@ -135,50 +148,30 @@ int main(ac, av)
nops=stacksize-1;
gen_combinations(nops);
//ncombs=ncombinations(len_ops, nops);
ncombs=n_combs();
//print_combs();
printf("target=%d\nstacksize=%d ", target, stacksize);
set_target(target);
//printf("len_ops=%d\nnops=%d\nops_comb=%d\n", len_ops, nops, ncombs);
//stack=new_stack(stacksize, "Main Stack", 1);
//strcpy(inputstack.name, "initial");
for (i=optind+1; i<ac; ++i) {
val=atoi(av[i]);
push_stack(&inputstack, val);
}
print_stack(&inputstack, 0);
//print_stack(stack, 1);
gen_stacks(&inputstack); // printf("sorting stack...\n");
//print_stacks();
//mergesort_stack(stack->stack, 0, stack->last-1);
//print_stack(stack, 1);
/*i=1;
do {
printf("permutation %2d: ", i++);
print_stack(stack, 0);
} while (permute_stack(stack->stack, stack->last));
*/
gen_stacks(&inputstack);
if (treetype==TREE_CATALAN) {
gen_tree(intarray, nops, 0, 0);
} else {
gen_reduced_trees(nops);
}
set_target(target);
set_intr();
nstacks=n_stacks();
ntrees=n_trees();
# ifdef DEBUG_MAIN
printf("stacks :%'15d\n", nstacks);
printf("ops combinations:%'15d\n", ncombs);
printf("trees :%'15d\n", ntrees);
printf("max evaluations :%'15d\n", nstacks*ncombs*ntrees*stacksize);
//for (k=0; k<nstacks; ++k) {
// stack=nth_stack(k);
// printf("%%%%%%%%%%%%%%%%%%\n");
// print_stack(stack, 0);
// printf("%%%%%%%%%%%%%%%%%%\n");
//}
# endif
for (i=0; i<ntrees; ++i) {
tree=nth_tree(i);
for (j=0; j<ncombs; ++j) {
@@ -186,21 +179,20 @@ int main(ac, av)
for (k=0; k<nstacks; ++k) {
int ncalcs=0;
stack=nth_stack(k);
//printf("%%%%%%%%%%%%%%%%%%\n");
//print_stack(stack, 0);
//printf("%%%%%%%%%%%%%%%%%%\n");
# ifdef DEBUG_MAIN
# ifdef DEBUG_MAINLOOP
eval=eval_node(tree->head, 0, stack->stack, comb, &ncalcs);
if (eval > 0) {
printf("============================== %d, %d, %d\n", i, j, k);
print_tree(tree, 0);
print_comb(j);
print_stack(stack, 0);
printf("eval=%d - calcs=%d\n", eval, ncalcs);
printf("================= mainloop tree=%d, comb=%d, stack=%d\n", i, j, k);
printf("mainloop: ");print_tree(tree, 0);
printf("mainloop: ");print_comb(j);
printf("mainloop: "); print_stack(stack, 0);
printf("mainloop: eval=%d - calcs=%d\n", eval, ncalcs);
}
# else
eval_node(tree->head, 0, stack->stack, comb, &ncalcs);
# endif
# ifdef DEBUG_MAINSLEEP
sleep(1);
# endif
}
}
@@ -214,11 +206,7 @@ int main(ac, av)
//res=eval_stack(stack);
//printf("EVAL=%d\n", res);
}
printf("\n");
print_bests();
set_timer(&end);
if (displaysummary)
printf("Total time elapsed: %.5f secs, nodes/leaves evaluated:%'d/%'d\n",
get_timer(end), get_totnodes(), get_totleaves());
//printf("\n");
print_results();
exit(0);
}