13 #define ERRPRINT(fmt, as...) fprintf(stderr, fmt, ## as);
14 #define DPRINT(fmt, as...) if(DEBUG) ERRPRINT(fmt, ## as);
16 typedef enum {OBJECT
, COORD
, HYBRID
} strategy
;
20 strategy strat
= HYBRID
;
25 "\t%s [opts] [FILE [FILE [...]]]\n"
28 "\tAll strategies are mutually exclusive\n"
29 "\t-c coordinate based strategy\n"
30 "\t-o object based strategy\n"
31 "\t-y hybrid strategy\n"
32 // "\t-l LURD lURD verification strategy\n"
33 // "\t-r show all positions that are a valid solution\n"
35 "\t-d enable verbose debug output\n"
36 "\t-h show this help\n"
38 "Positional arguments:\n"
39 "\tFILE zero or more sokoban screens\n"
40 "\t when no file is specified stdin will be used\n", prg
);
43 void solve(FILE *inputstream
)
45 clock_t time_start_read
, time_end_read
;
46 clock_t time_start_encode
, time_end_encode
;
48 time_start_read
= clock();
49 sokoban_screen
*screen
= parse_screen(inputstream
);
50 if (screen
== NULL
) printf("Something went wrong...\n");
51 //sokoban_print(screen);
52 time_end_read
= clock();
54 time_start_encode
= clock();
56 lace_init(0, 1000000);
57 lace_startup(0, NULL
, NULL
);
59 sylvan_init_package(1LL<<21, 1LL<<27, 1LL<<20, 1LL<<26);
62 state
*init
= encode_screen(screen
);
63 rels
*rls
= encode_rel(screen
);
65 BDD old
= sylvan_false
;
69 ERRPRINT("Iteration %d\n", iteration
++);
71 //WRONG! each trans relation (LEFT,UP,RIGHT,DOWN) contains a linked list of trans relations (not just
72 //only one), so to compute a transition for a single direction, we need to iterate through a relevant linked list
73 //taking disjunction of results (for a single direction there will be falses and only one screen change among the
75 new = sylvan_or(new, sylvan_relnext(new, rls
->rell
->bdd
, rls
->rell
->varset
.varset
));
76 new = sylvan_or(new, sylvan_relnext(new, rls
->relu
->bdd
, rls
->relu
->varset
.varset
));
77 new = sylvan_or(new, sylvan_relnext(new, rls
->relr
->bdd
, rls
->relr
->varset
.varset
));
78 new = sylvan_or(new, sylvan_relnext(new, rls
->reld
->bdd
, rls
->reld
->varset
.varset
));
80 //sylvan_printdot_nc(old);
83 // DPRINT("Encoding coordinate based\n");
86 // DPRINT("Encoding object based\n");
87 // solve_object(screen);
90 // DPRINT("Encoding hybrid based\n");
91 // DPRINT("Not implemented yet...\n");
97 time_end_encode
= clock();
101 sokoban_free(screen
);
102 ERRPRINT("Reading: %fs\n",
103 ((double) (time_end_read
-time_start_read
))/CLOCKS_PER_SEC
);
104 ERRPRINT("Encoding: %fs\n",
105 ((double) (time_end_encode
-time_start_encode
))/CLOCKS_PER_SEC
);
108 int main(int argc
, char **argv
)
112 while((optchar
= getopt(argc
, argv
, "cdhoy")) != -1){
116 DPRINT("Strategy changed to Coordinate based\n");
120 DPRINT("Debug enabled\n");
127 DPRINT("Strategy changed to Object based\n");
131 DPRINT("Strategy changed to Hybrid\n");
135 ERRPRINT("Unknown option `-%c'.\n", optopt
);
137 ERRPRINT("Unknown option char `-\\x%x'.\n", optopt
);
146 ERRPRINT("You have not specified a file, reading from stdin\n");
150 for(int filepathindex
= optind
; filepathindex
< argc
; filepathindex
++){
151 char *currentfilepath
= argv
[filepathindex
];
152 ERRPRINT("Processing: %s\n", currentfilepath
);
153 FILE *currentfile
= fopen(currentfilepath
, "r");
154 DPRINT("Opening file\n");
156 DPRINT("Closing file\n");