bdf8a1279a233e248563418f291790971a1bc5f9
13 #define DPRINT(fmt, as...) if(VERBOSE) fprintf(stderr, fmt, ## as);
14 #define REPORT(s, end, start) DPRINT(s, ((double)(end-start))/CLOCKS_PER_SEC);
22 "\t%s [opts] [FILE]\n"
25 // "\t-l LURD lURD verification strategy\n"
26 // "\t-r show all positions that are a valid solution\n"
28 "\t-v enable verbose output\n"
29 "\t-h show this help\n"
31 "Positional arguments:\n"
32 "\tFILE zero or one sokoban screens\n"
33 "\t when no file is specified stdin will be used\n", prg
);
36 BDD
subsolve(trans_t
*t
, BDD
new){
39 new = sylvan_or(new, sylvan_relnext(new, t
->bdd
, t
->varset
.varset
));
45 int solve(FILE *inputstream
)
47 clock_t time_start_read
, time_end_read
, time_start_scr
, time_end_scr
,
48 time_start_goal
, time_end_goal
, time_start_rel
, time_end_rel
,
49 time_start_solve
, time_end_solve
;
52 time_start_read
= clock();
53 sokoban_screen
*screen
= parse_screen(inputstream
, false);
55 printf("Something went wrong encoding the screen\n");
58 time_end_read
= clock();
60 //Lace and sylvan blork
61 lace_init(0, 1000000);
62 lace_startup(0, NULL
, NULL
);
64 sylvan_init_package(1LL<<21, 1LL<<27, 1LL<<20, 1LL<<26);
68 time_start_scr
= clock();
69 state
*init
= encode_screen(screen
);
70 time_end_scr
= clock();
73 time_start_goal
= clock();
74 state
*goal
= encode_goal(screen
);
75 time_end_goal
= clock();
78 time_start_rel
= clock();
79 rels
*rls
= encode_rel(screen
);
80 time_end_rel
= clock();
83 time_start_solve
= clock();
84 BDD old
= sylvan_false
;
89 DPRINT("Iteration %d\n", iteration
++);
91 if(sylvan_satcount(sylvan_and(goal
->bdd
, new), init
->vars
.varset
) > 0){
96 //Left, Up, Right, Down moves
97 new = subsolve(rls
->rell
, new);
98 new = subsolve(rls
->relu
, new);
99 new = subsolve(rls
->relr
, new);
100 new = subsolve(rls
->reld
, new);
102 time_end_solve
= clock();
104 //Free and print stats
105 sokoban_free(screen
);
106 REPORT("Reading: %fs\n", time_end_read
, time_start_read
);
107 REPORT("Screen encoding: %fs\n", time_end_scr
, time_start_scr
);
108 REPORT("Goal encoding: %fs\n", time_end_goal
, time_start_goal
);
109 REPORT("Relation encoding: %fs\n", time_end_rel
, time_start_rel
);
110 REPORT("Solving encoding: %fs\n", time_end_solve
, time_start_solve
);
113 printf("no solution\n");
119 int main(int argc
, char **argv
)
123 while((optchar
= getopt(argc
, argv
, "vh")) != -1){
127 DPRINT("Debug enabled\n");
134 DPRINT("Skipping unknown option `-%c'.\n", optopt
);
136 DPRINT("Skipping unknown option char `-\\x%x'.\n", optopt
);
145 DPRINT("You have not specified a file, reading from stdin\n");
148 DPRINT("Processing: %s\n", argv
[optind
]);
149 DPRINT("Thus skipping the other %d files\n", argc
-optind
);
150 FILE *currentfile
= fopen(argv
[optind
], "r");
151 DPRINT("Opening file\n");
152 return solve(currentfile
);
153 DPRINT("Closing file\n");