Commit b5776df9 authored by danfis's avatar danfis

Operator mutex section for FD output.

parent 8a3b2060
......@@ -152,7 +152,8 @@ static int options(int argc, char *argv[])
if (!opt.op_mutex_fam
&& !opt.op_mutex_op_fact
&& !opt.op_mutex_op_all
&& !opt.op_mutex_single_fact){
&& !opt.op_mutex_single_fact
&& !opt.disable_op_mutex){
opt.op_mutex_fam = 1;
opt.op_mutex_op_fact = 1;
opt.op_mutex_op_all = 1;
......@@ -231,13 +232,15 @@ static void computeSymmetry(const plan_strips_t *strips,
planSymInitPDG(sym, strips);
BOR_INFO(err, " --> symmetry generators: %d", sym->gen_size);
//planSymPrintDebug(&sym, stdout);
for (int i = 0; i < sym->gen_size; ++i){
const plan_sym_gen_t *gen = sym->gen + i;
for (int j = 0; j < gen->op_cycle_size; ++j)
borISetUnion(sym_ops, &gen->op_cycle[j]);
if (sym_ops != NULL){
for (int i = 0; i < sym->gen_size; ++i){
const plan_sym_gen_t *gen = sym->gen + i;
for (int j = 0; j < gen->op_cycle_size; ++j)
borISetUnion(sym_ops, &gen->op_cycle[j]);
}
BOR_INFO(err, " --> non-identity symmetry operators: %d",
borISetSize(sym_ops));
}
BOR_INFO(err, " --> non-identity symmetry operators: %d",
borISetSize(sym_ops));
}
static int inferOpMutexes(const plan_strips_t *strips,
......@@ -249,6 +252,11 @@ static int inferOpMutexes(const plan_strips_t *strips,
plan_mgroups_t mgroup;
planMGroupsInit(&mgroup);
if (opt.disable_op_mutex){
BOR_INFO2(err, "Inference of op-mutexes disabled.");
return 0;
}
if (opt.op_mutex_fam){
BOR_INFO2(err, "Inference of fam-groups:");
unsigned fam_flags = PLAN_FAMGROUP_MAXIMAL;
......@@ -457,20 +465,28 @@ static int sym_reduce(plan_strips_t *strips, bor_err_t *err)
static int translateToFD(const plan_strips_t *strips, bor_err_t *err)
{
plan_mutex_pairs_t mutex;
plan_op_mutex_pairs_t op_mutex;
plan_sym_t sym;
plan_mgroups_t mgroup;
plan_fdr_t fdr;
unsigned var_flags = PLAN_FDR_VARS_ESSENTIAL_FIRST;
int ret;
bor_timer_t timer;
BOR_INFO2(err, "Translate STRIPS to FDR:");
borTimerStart(&timer);
planMutexPairsInitStrips(&mutex, strips);
ret = planH2ReachabilityOnlyMutex(&mutex, strips);
if (ret != 0)
return -1;
BOR_ERR_RET2(err, -1, "Could not compute h^2");
BOR_INFO(err, "Found %d h^2 mutex pairs.", mutex.num_mutex_pairs);
computeSymmetry(strips, &sym, NULL, err);
planOpMutexPairsInit(&op_mutex, strips);
if (inferOpMutexes(strips, &mutex, &sym, &op_mutex, err) != 0)
BOR_TRACE_RET(err, -1);
planMGroupsInit(&mgroup);
unsigned fam_flags = PLAN_FAMGROUP_MAXIMAL;
fam_flags |= PLAN_FAMGROUP_PRIORITIZE_UNCOVERED;
......@@ -482,18 +498,20 @@ static int translateToFD(const plan_strips_t *strips, bor_err_t *err)
ret = planFDRInitFromStrips(&fdr, strips, &mgroup, &mutex, var_flags);
if (ret != 0)
return -1;
BOR_ERR_RET2(err, -1, "Could not translate STRIPS to FDR");
BOR_INFO(err, "STRIPS translated to FDR (vars: %d, ops: %d)",
fdr.var.var_size, fdr.op.op_size);
FILE *fout;
if ((fout = fopen(opt.fd_output, "w")) != NULL){
planFDRPrintAsFD(&fdr, fout);
planFDRPrintAsFDWithMutex(&fdr, &op_mutex, fout);
fclose(fout);
}else{
fprintf(stderr, "Error: Could not open '%s'\n", opt.fd_output);
}
planSymFree(&sym);
planOpMutexPairsFree(&op_mutex);
planMutexPairsFree(&mutex);
planMGroupsFree(&mgroup);
planFDRFree(&fdr);
......@@ -529,8 +547,12 @@ int main(int argc, char *argv[])
return -1;
}
if (opt.fd_output != NULL)
translateToFD(&strips, &err);
if (opt.fd_output != NULL){
if (translateToFD(&strips, &err) != 0){
borErrPrint(&err, 1, stderr);
return -1;
}
}
planStripsFree(&strips);
maxTimeWatchdogJoin();
......
......@@ -29,6 +29,7 @@
#include <plan/part_state.h>
#include <plan/op.h>
#include <plan/app_op.h>
#include <plan/op_mutex_pair.h>
#ifdef __cplusplus
extern "C" {
......@@ -57,6 +58,14 @@ void planFDRCopy(plan_fdr_t *dst, const plan_fdr_t *src);
*/
void planFDRPrintAsFD(const plan_fdr_t *fdr, FILE *fout);
/**
* TODO: Add also plan_mutex_pairs and print out also mutex pairs to FD
* format.
*/
void planFDRPrintAsFDWithMutex(const plan_fdr_t *fdr,
const plan_op_mutex_pairs_t *op_mutex,
FILE *fout);
void planFDRPrintDebug(const plan_fdr_t *fdr, FILE *fout);
#ifdef __cplusplus
......
......@@ -207,6 +207,28 @@ void planFDRPrintAsFD(const plan_fdr_t *fdr, FILE *fout)
fprintf(fout, "0\n");
}
void planFDRPrintAsFDWithMutex(const plan_fdr_t *fdr,
const plan_op_mutex_pairs_t *op_mutex,
FILE *fout)
{
planFDRPrintAsFD(fdr, fout);
if (op_mutex != NULL){
fprintf(fout, "begin_op_mutex_pairs\n");
fprintf(fout, "%d\n", planOpMutexPairsSize(op_mutex));
int o1, o2;
PLAN_OP_MUTEX_PAIRS_FOR_EACH_SORTED(op_mutex, o1, o2)
fprintf(fout, "%d %d\n", o1, o2);
fprintf(fout, "end_op_mutex_pairs\n");
}else{
fprintf(fout, "begin_op_mutex_pairs\n0\n");
fprintf(fout, "end_op_mutex_pairs\n");
}
fflush(fout);
}
void planFDRPrintDebug(const plan_fdr_t *fdr, FILE *fout)
{
planFDRVarsPrintDebug(&fdr->var, fout);
......
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