Commit fd6c7bb2 authored by David Speck's avatar David Speck

stated to implement sym compilation

parent 552e1fdc
......@@ -749,6 +749,7 @@ fast_downward_plugin(
symple/sdac_parser/catamorph/interpreters/dependencies
symple/sdac_parser/catamorph/interpreters/variable_ordering
symple/sdac_parser/utils/string_utils
symple/axioms/axiom_evaluator
DEPENDS
)
......
#include "axiom_evaluator.h"
#include <queue>
#include <set>
#include "../../Meddly/operations_extension/userOperations.h"
#include "../../abstract_task.h"
#include "../sym_variables.h"
namespace symple {
// Some helper functions
bool SymAxiomEvaluator::is_primary(int var) const {
return task->get_variable_axiom_layer(var) == -1;
}
int SymAxiomEvaluator::get_axiom_head(int axiom_id) const {
return task->get_operator_effect(axiom_id, 0, true).var;
}
bool SymAxiomEvaluator::is_in_body(int var, int axiom_id) const {
for (int cond = 0;
cond < task->get_num_operator_effect_conditions(axiom_id, 0, true);
cond++) {
int pre_var =
task->get_operator_effect_condition(axiom_id, 0, cond, true).var;
if (pre_var == var) {
return true;
}
}
return false;
}
// Axiom sets head variable to default => not necessary!
bool SymAxiomEvaluator::is_trivial(int axiom_id) const {
int head = get_axiom_head(axiom_id);
return task->get_variable_default_axiom_value(head) ==
task->get_operator_effect(axiom_id, 0, true).value;
}
MEDDLY::dd_edge SymAxiomEvaluator::get_body_evmdd(int axiom_id) const {
MEDDLY::dd_edge res = sym_vars->get_constant_edge(1);
for (int cond = 0;
cond < task->get_num_operator_effect_conditions(axiom_id, 0, true);
cond++) {
int pre_var =
task->get_operator_effect_condition(axiom_id, 0, cond, true).var;
int pre_value =
task->get_operator_effect_condition(axiom_id, 0, cond, true).value;
if (is_primary(pre_var)) {
MEDDLY::apply(USER_OPS::UNIONMIN, res,
sym_vars->get_predicate_edge(pre_var, pre_value), res);
} else {
MEDDLY::dd_edge cur = primary_representation.at(pre_var);
if (task->get_variable_default_axiom_value(pre_var) == pre_value) {
MEDDLY::apply(USER_OPS::MINUS, sym_vars->get_constant_edge(1), cur,
cur);
}
MEDDLY::apply(USER_OPS::UNIONMIN, res, cur, res);
}
}
return res;
}
void SymAxiomEvaluator::create_axiom_body_layer() {
std::set<int> effs;
for (int ax_id = 0; ax_id < task->get_num_axioms(); ax_id++) {
int body_level = -1;
int eff_var = task->get_operator_effect(ax_id, 0, true).var;
effs.insert(eff_var);
for (int cond = 0;
cond < task->get_num_operator_effect_conditions(ax_id, 0, true);
cond++) {
int pre_var =
task->get_operator_effect_condition(ax_id, 0, cond, true).var;
body_level =
std::max(body_level, task->get_variable_axiom_layer(pre_var));
}
axiom_body_layer.push_back(body_level);
}
}
void SymAxiomEvaluator::create_primary_representation(int layer) {
std::cout << "LAYER " << layer << "..." << std::flush;
std::vector<int> rules_in_layer;
// add all "unproblematic" axioms to var bdd
for (int ax_id = 0; ax_id < task->get_num_axioms(); ax_id++) {
if (is_trivial(ax_id)) {
continue;
}
if (task->get_variable_axiom_layer(get_axiom_head(ax_id)) == layer &&
axiom_body_layer.at(ax_id) < layer) {
MEDDLY::dd_edge body = get_body_evmdd(ax_id);
primary_representation[get_axiom_head(ax_id)] += body;
}
}
// add vars of this layer to queue
std::queue<int> open_vars;
for (auto &pr_evmdd : primary_representation) {
int var = pr_evmdd.first;
if (task->get_variable_axiom_layer(var) == layer) {
// std::cout << g_variable_name[var] << std::endl;
open_vars.push(var);
}
}
// Recursively evaluate var evmdd
while (!open_vars.empty()) {
int var = open_vars.front();
open_vars.pop();
for (int ax_id = 0; ax_id < task->get_num_axioms(); ax_id++) {
if (is_trivial(ax_id) ||
task->get_variable_axiom_layer(get_axiom_head(ax_id)) != layer) {
continue;
}
if (is_in_body(var, ax_id)) {
int head = get_axiom_head(ax_id);
/*if (axioms_layers[head] != layer) {
g_axioms[i].dump();
}*/
assert(task->get_variable_axiom_layer(head) == layer);
MEDDLY::dd_edge res = primary_representation[head];
MEDDLY::dd_edge body = get_body_evmdd(ax_id);
MEDDLY::apply(USER_OPS::UNIONMIN, body, primary_representation[var],
body);
MEDDLY::apply(USER_OPS::INTERSECTIONMAX, res, body, res);
if (res != primary_representation[head]) {
open_vars.push(head);
}
primary_representation[head] = res;
// std::cout << g_variable_name[head] << " updated" << std::endl;
}
}
}
std::cout << "done!" << std::endl;
}
void SymAxiomEvaluator::create_primary_representation() {
create_axiom_body_layer();
int num_axiom_layers = -1;
for (int var = 0; var < task->get_num_variables(); var++) {
if (!is_primary(var)) {
primary_representation[var] = sym_vars->get_constant_edge(0);
num_axiom_layers =
std::max(num_axiom_layers, task->get_variable_axiom_layer(var));
}
}
// Call for each layer the recursive procedure
for (int i = 0; i < num_axiom_layers; i++) {
create_primary_representation(i);
}
}
SymAxiomEvaluator::SymAxiomEvaluator(std::shared_ptr<SymVariables> sym_vars,
std::shared_ptr<AbstractTask> task)
: sym_vars(sym_vars), task(task) {}
MEDDLY::dd_edge SymAxiomEvaluator::get_primary_representation(int var,
int val) const {
MEDDLY::dd_edge res = primary_representation.at(var);
// Negation if derived variable has default value
if (task->get_variable_default_axiom_value(var) == val) {
MEDDLY::apply(USER_OPS::MINUS, sym_vars->get_constant_edge(1), res, res);
}
return res;
}
} // namespace symple
#ifndef SEARCH_SYMPLE_AXIOMS_AXIOM_EVALUATOR_H_
#define SEARCH_SYMPLE_AXIOMS_AXIOM_EVALUATOR_H_
#include <meddly.h>
#include <map>
#include <memory>
#include <vector>
class AbstractTask;
namespace symple {
class SymVariables;
class SymAxiomEvaluator {
protected:
std::shared_ptr<SymVariables> sym_vars;
std::shared_ptr<AbstractTask> task;
std::vector<int> axiom_body_layer; // max. layer of vars in the body
std::map<int, MEDDLY::dd_edge> primary_representation;
bool is_primary(int var) const;
bool is_in_body(int var, int axiom_id) const;
bool is_trivial(int axiom_id) const;
int get_axiom_head(int axiom_id) const;
MEDDLY::dd_edge get_body_evmdd(int axiom_id) const;
void create_axiom_body_layer();
void create_primary_representation(int layer);
void create_primary_representation();
public:
SymAxiomEvaluator(std::shared_ptr<SymVariables> sym_vars,
std::shared_ptr<AbstractTask> task);
MEDDLY::dd_edge get_primary_representation(int var, int val) const;
};
} // namespace symple
#endif /* SEARCH_SYMPLE_AXIOMS_AXIOM_EVALUATOR_H_ */
#include "symple_search.h"
#include "../Meddly/operations_extension/userOperations.h"
#include "axioms/axiom_evaluator.h"
#include "closed_list.h"
#include "heuristics/bidirectional_potential.h"
#include "open_list.h"
......@@ -41,6 +42,7 @@ void SympleSearch::initialize() {
sym_vars = std::make_shared<SymVariables>(task);
sym_vars->init(params);
plan_manager = std::make_shared<SdacPlanManager>(sym_vars, task);
initialize_intial_state();
initialize_goal_states();
initialize_trs();
......
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