Commit 68ac1499 authored by danfis's avatar danfis

h^1 and h^3

parent cdd9c167
......@@ -39,7 +39,9 @@ OBJS += mutex_pair
OBJS += pddl_file
OBJS += plan_file
OBJS += irrelevance
OBJS += h1
OBJS += h2
OBJS += h3
OBJS += disambiguation
OBJS += bitset
OBJS += fdr_var
......
......@@ -30,7 +30,16 @@ extern "C" {
struct pddl_strips;
/**
* TODO
* Compute h^1 (i.e., a simple relaxed) reachability.
*/
int pddlH1(const pddl_strips_t *strips,
bor_iset_t *unreachable_facts,
bor_iset_t *unreachable_ops,
bor_err_t *err);
/**
* Compute h^2 reachability.
* unreachable_facts and unreachable_ops can be set to NULL.
*/
int pddlH2(const pddl_strips_t *strips,
pddl_mutex_pairs_t *m,
......@@ -39,7 +48,11 @@ int pddlH2(const pddl_strips_t *strips,
bor_err_t *err);
/**
* TODO
* Compute h^2 reachability in forward/backward.
* unreachable_facts and unreachable_ops can be set to NULL.
*
* See Alcázar, V., and Torralba, Á. 2015. A reminder about the importance
* of computing and exploiting invariants in planning. In Proc. ICAPS’15, 2–6.
*/
int pddlH2FwBw(const pddl_strips_t *strips,
const pddl_mgroups_t *mgroup,
......@@ -48,6 +61,19 @@ int pddlH2FwBw(const pddl_strips_t *strips,
bor_iset_t *unreachable_ops,
bor_err_t *err);
/**
* Compute h^3 reachability in forward/backward.
* unreachable_facts and unreachable_ops can be set to NULL.
* time_limit is disabled by setting it to <= 0.
*/
int pddlH3(const pddl_strips_t *strips,
pddl_mutex_pairs_t *m,
bor_iset_t *unreachable_facts,
bor_iset_t *unreachable_ops,
float time_limit,
size_t excess_memory,
bor_err_t *err);
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
......
......@@ -77,5 +77,6 @@
#include <pddl/op_mutex_pair.h>
#include <pddl/op_mutex_infer.h>
#include <pddl/op_mutex_sym_redundant.h>
#include <pddl/time_limit.h>
#endif /* __PDDL_H__ */
/***
* cpddl
* -------
* Copyright (c)2018 Daniel Fiser <[email protected]>,
* Faculty of Electrical Engineering, Czech Technical University in Prague.
* All rights reserved.
*
* This file is part of cpddl.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#ifndef __PLAN_TIME_LIMIT_H__
#define __PLAN_TIME_LIMIT_H__
#include <boruvka/timer.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct pddl_time_limit {
bor_timer_t timer;
bor_real_t limit;
};
typedef struct pddl_time_limit pddl_time_limit_t;
/**
* Initializes time limit as "unlimited".
*/
_bor_inline void pddlTimeLimitInit(pddl_time_limit_t *tm)
{
borTimerStart(&tm->timer);
tm->limit = 1E100;
}
/**
* Sets the time limit in seconds and starts counting.
*/
_bor_inline void pddlTimeLimitSet(pddl_time_limit_t *tm, bor_real_t limit)
{
borTimerStart(&tm->timer);
if (limit > 0.){
tm->limit = limit;
}else{
tm->limit = 1E100;
}
}
/**
* Checks the time limit.
* Returns 0 if we are still withing time limit, -1 otherwise.
*/
_bor_inline int pddlTimeLimitCheck(pddl_time_limit_t *tm)
{
if (tm->limit >= 1E100)
return 0;
borTimerStop(&tm->timer);
if (borTimerElapsedInSF(&tm->timer) > tm->limit)
return -1;
return 0;
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* __PLAN_TIME_LIMIT_H__ */
/***
* cpddl
* -------
* Copyright (c)2020 Daniel Fiser <[email protected]>,
* AIC, Department of Computer Science,
* Faculty of Electrical Engineering, Czech Technical University in Prague.
* All rights reserved.
*
* This file is part of cpddl.
*
* Distributed under the OSI-approved BSD License (the "License");
* see accompanying file BDS-LICENSE for details or see
* <http://www.opensource.org/licenses/bsd-license.php>.
*
* This software is distributed WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the License for more information.
*/
#include <boruvka/alloc.h>
#include <boruvka/iarr.h>
#include "pddl/critical_path.h"
#include "pddl/strips.h"
int pddlH1(const pddl_strips_t *strips,
bor_iset_t *unreachable_facts,
bor_iset_t *unreachable_ops,
bor_err_t *err)
{
if (strips->has_cond_eff){
BOR_ERR_RET2(err, -1, "pddlH1: Conditional effects are not supported!");
}
int *facts = BOR_CALLOC_ARR(int, strips->fact.fact_size);
int *ops = BOR_CALLOC_ARR(int, strips->op.op_size);
bor_iset_t *fact_to_op = BOR_CALLOC_ARR(bor_iset_t, strips->fact.fact_size);
BOR_IARR(queue);
BOR_INFO(err, "h^1. facts: %d, ops: %d",
strips->fact.fact_size,
strips->op.op_size);
int fact;
BOR_ISET_FOR_EACH(&strips->init, fact){
facts[fact] = 1;
borIArrAdd(&queue, fact);
}
for (int op_id = 0; op_id < strips->op.op_size; ++op_id){
const pddl_strips_op_t *op = strips->op.op[op_id];
ops[op_id] = borISetSize(&op->pre);
int fact;
BOR_ISET_FOR_EACH(&op->pre, fact)
borISetAdd(fact_to_op + fact, op_id);
if (ops[op_id] == 0){
int fact;
BOR_ISET_FOR_EACH(&op->add_eff, fact){
if (facts[fact] == 0){
facts[fact] = 1;
borIArrAdd(&queue, fact);
}
}
}
}
while (borIArrSize(&queue) > 0){
int cur = borIArrGet(&queue, borIArrSize(&queue) - 1);
borIArrRmLast(&queue);
int op_id;
BOR_ISET_FOR_EACH(fact_to_op + cur, op_id){
if (--ops[op_id] == 0){
const pddl_strips_op_t *op = strips->op.op[op_id];
int fact;
BOR_ISET_FOR_EACH(&op->add_eff, fact){
if (facts[fact] == 0){
facts[fact] = 1;
borIArrAdd(&queue, fact);
}
}
}
}
}
for (int fid = 0;
unreachable_facts != NULL && fid < strips->fact.fact_size; ++fid){
if (facts[fid] == 0)
borISetAdd(unreachable_facts, fid);
}
for (int op_id = 0;
unreachable_ops != NULL && op_id < strips->op.op_size; ++op_id){
if (ops[op_id] > 0)
borISetAdd(unreachable_ops, op_id);
}
borIArrFree(&queue);
for (int fid = 0; fid < strips->fact.fact_size; ++fid)
borISetFree(fact_to_op + fid);
if (fact_to_op != NULL)
BOR_FREE(fact_to_op);
if (facts != NULL)
BOR_FREE(facts);
if (ops != NULL)
BOR_FREE(ops);
BOR_INFO(err, "h^1 DONE. unreachable facts: %d, unreachable ops: %d",
(unreachable_facts != NULL ? borISetSize(unreachable_facts) : -1),
(unreachable_ops != NULL ? borISetSize(unreachable_ops) : -1));
return 0;
}
This diff is collapsed.
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