Commit b61d5987 authored by danfis's avatar danfis

bin/reversibility: Refactor basic/iterative methods.

parent 6be31a07
......@@ -34,6 +34,7 @@ struct options {
const char *out;
int use_mutex;
int max_depth;
int iterative;
int list_ops;
} opt;
......@@ -49,7 +50,6 @@ pddl_ground_config_t ground_cfg = PDDL_GROUND_CONFIG_INIT;
pddl_strips_t strips;
pddl_mgroups_t mgroups;
pddl_mutex_pairs_t mutex;
int max_depth;
static FILE *openFile(const char *fn)
{
......@@ -75,6 +75,8 @@ static int readOpts(int *argc, char *argv[])
opt.lifted_mgroup_max_candidates = 10000;
opt.lifted_mgroup_max_mgroups = 10000;
opt.out = "-";
opt.max_depth = -1;
opt.iterative = -1;
pddl_cfg.force_adl = 1;
......@@ -154,18 +156,18 @@ static int readOpts(int *argc, char *argv[])
optsAddDesc("use-mutex", 'm', OPTS_NONE, &opt.use_mutex, NULL,
"Use mutexes in inference of reverse plans.");
optsAddDesc("iterivate", 'i', OPTS_NONE, &opt.iterative, NULL,
"Iterative variant.");
optsAddDesc("max-depth", 'd', OPTS_INT, &opt.max_depth, NULL,
"Basic variant -- max depth.");
optsAddDesc("iterivate", 'i', OPTS_INT, &opt.iterative, NULL,
"Iterative variant -- max depth.");
optsAddDesc("list-ops", 'l', OPTS_NONE, &opt.list_ops, NULL,
"List all operators.");
if (opts(argc, argv) != 0 || opt.help || (*argc != 4 && *argc != 3)){
if (opts(argc, argv) != 0 || opt.help || (*argc != 3 && *argc != 2)){
if (*argc <= 1)
fprintf(stderr, "Error: Missing max-depth and input file(s)\n\n");
if (*argc <= 2)
fprintf(stderr, "Error: Missing input file(s)\n\n");
if (*argc > 4){
if (*argc > 3){
for (int i = 0; i < *argc; ++i){
if (argv[i][0] == '-'){
fprintf(stderr, "Error: Unrecognized option '%s'\n",
......@@ -174,10 +176,9 @@ static int readOpts(int *argc, char *argv[])
}
}
fprintf(stderr, "pddl-fdr is a program for translating PDDL into"
" FDR.\n");
fprintf(stderr, "Usage: %s [OPTIONS] max-depth"
" domain.pddl problem.pddl\n",
fprintf(stderr, "pddl-reversibility is a program for computing"
" uniform reversibility.\n");
fprintf(stderr, "Usage: %s [OPTIONS] domain.pddl problem.pddl\n",
argv[0]);
fprintf(stderr, " OPTIONS:\n");
optsPrint(stderr, " ");
......@@ -209,20 +210,28 @@ static int readOpts(int *argc, char *argv[])
if (opt.no_ground_prune_pre && opt.no_ground_prune_dead_end)
opt.no_ground_prune = 1;
max_depth = atoi(argv[1]);
if (max_depth <= 0){
fprintf(stderr, "Error: max-depth must be >= 1.\n");
if (opt.max_depth >= 0){
BOR_INFO(&err, "Max Depth: %d", opt.max_depth);
}
if (opt.iterative >= 0){
BOR_INFO(&err, "Iterative Max Depth: %d", opt.iterative);
}
if (opt.max_depth < 0
&& opt.iterative < 0
&& !opt.list_ops){
fprintf(stderr, "Error: One of -d/-i/-l must be specified.\n");
return -1;
}
BOR_INFO(&err, "Max Depth: %d", max_depth);
if (*argc == 3){
if (*argc == 2){
BOR_INFO(&err, "Input file: '%s'", argv[2]);
if (pddlFiles1(&files, argv[2], &err) != 0)
if (pddlFiles1(&files, argv[1], &err) != 0)
BOR_TRACE_RET(&err, -1);
}else{ // *argc == 4
}else{ // *argc == 3
BOR_INFO(&err, "Input files: '%s' and '%s'", argv[2], argv[3]);
if (pddlFiles(&files, argv[2], argv[3], &err) != 0)
if (pddlFiles(&files, argv[1], argv[2], &err) != 0)
BOR_TRACE_RET(&err, -1);
}
......@@ -1000,17 +1009,19 @@ static void reversibilityIterativeDepth(int *skip, int max_depth, FILE *fout)
}
}
static void reversibilityIterative(FILE *fout)
static void reversibilityIterative(FILE *fout, int max_depth)
{
BOR_INFO2(&err, "Computing reverse plans for all operators...");
int *skip = BOR_CALLOC_ARR(int, strips.op.op_size);
for (int depth = 1; depth <= max_depth; ++depth)
for (int depth = 1; depth <= max_depth; ++depth){
BOR_INFO(&err, "Computing for max-depth: %d", depth);
reversibilityIterativeDepth(skip, depth, fout);
}
BOR_FREE(skip);
BOR_INFO2(&err, "Reverse plans computed.");
}
static void reversibilitySimple(FILE *fout)
static void reversibilitySimple(FILE *fout, int max_depth)
{
BOR_INFO2(&err, "Computing reverse plans for all operators...");
for (int op_id = 0; op_id < strips.op.op_size; ++op_id){
......@@ -1044,10 +1055,10 @@ static int reversibility(void)
FILE *fout = openFile(opt.out);
if (opt.list_ops){
listOps(fout);
}else if (opt.iterative){
reversibilityIterative(fout);
}else{
reversibilitySimple(fout);
}else if (opt.iterative >= 0){
reversibilityIterative(fout, opt.iterative);
}else if (opt.max_depth >= 0){
reversibilitySimple(fout, opt.max_depth);
}
closeFile(fout);
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment