Commit c022cea2 authored by David Speck's avatar David Speck

progress with axioms. Still errors occur. PSR: plans with 0 costs. MICONIC: plan…

progress with axioms. Still errors occur. PSR: plans with 0 costs. MICONIC: plan reconsturction fails (sdac_plan_mgr is problematic and selcting_any state while reconstruction...)
parent fd6c7bb2
#include "axiom_evaluator.h"
#include <limits>
#include <queue>
#include <set>
#include "../../Meddly/operations_extension/userOperations.h"
......@@ -9,10 +10,16 @@ namespace symple {
// Some helper functions
bool SymAxiomEvaluator::is_primary(int var) const {
bool SymAxiomEvaluator::is_primary(int var,
std::shared_ptr<AbstractTask> task) {
return task->get_variable_axiom_layer(var) == -1;
}
bool SymAxiomEvaluator::is_secondary(int var,
std::shared_ptr<AbstractTask> task) {
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;
}
......@@ -46,7 +53,7 @@ MEDDLY::dd_edge SymAxiomEvaluator::get_body_evmdd(int axiom_id) const {
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)) {
if (is_primary(pre_var, task)) {
MEDDLY::apply(USER_OPS::UNIONMIN, res,
sym_vars->get_predicate_edge(pre_var, pre_value), res);
} else {
......@@ -91,12 +98,14 @@ void SymAxiomEvaluator::create_primary_representation(int layer) {
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;
MEDDLY::apply(USER_OPS::INTERSECTIONMAX,
primary_representation[get_axiom_head(ax_id)], body,
primary_representation[get_axiom_head(ax_id)]);
}
}
// add vars of this layer to queue
std::queue<int> open_vars;
for (auto &pr_evmdd : primary_representation) {
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;
......@@ -141,7 +150,7 @@ 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)) {
if (!is_primary(var, task)) {
primary_representation[var] = sym_vars->get_constant_edge(0);
num_axiom_layers =
std::max(num_axiom_layers, task->get_variable_axiom_layer(var));
......@@ -149,9 +158,20 @@ void SymAxiomEvaluator::create_primary_representation() {
}
// Call for each layer the recursive procedure
for (int i = 0; i < num_axiom_layers; i++) {
for (int i = 0; i <= num_axiom_layers; i++) {
create_primary_representation(i);
}
// Flip them and set them to infinity
for (auto& p : primary_representation) {
MEDDLY::apply(USER_OPS::MINUS, sym_vars->get_constant_edge(1), p.second,
p.second);
MEDDLY::apply(
USER_OPS::MULTIPLY,
sym_vars->get_constant_edge(std::numeric_limits<float>::infinity()),
p.second, p.second);
USER_OPS::to_dot(p.second, task->get_variable_name(p.first) + ".dot");
}
}
SymAxiomEvaluator::SymAxiomEvaluator(std::shared_ptr<SymVariables> sym_vars,
......@@ -164,7 +184,14 @@ MEDDLY::dd_edge SymAxiomEvaluator::get_primary_representation(int 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);
MEDDLY::apply(
USER_OPS::LESSTHAN, res,
sym_vars->get_constant_edge(std::numeric_limits<float>::infinity()),
res);
MEDDLY::apply(
USER_OPS::MULTIPLY, res,
sym_vars->get_constant_edge(std::numeric_limits<float>::infinity()),
res);
}
return res;
}
......
......@@ -18,7 +18,6 @@ class SymAxiomEvaluator {
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;
......@@ -27,13 +26,16 @@ class SymAxiomEvaluator {
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);
void create_primary_representation();
MEDDLY::dd_edge get_primary_representation(int var, int val) const;
static bool is_primary(int var, std::shared_ptr<AbstractTask> task);
static bool is_secondary(int var, std::shared_ptr<AbstractTask> task);
};
} // namespace symple
......
#include "plan_reconstruction.h"
#include "../Meddly/operations_extension/userOperations.h"
#include "../abstract_task.h"
#include "axioms/axiom_evaluator.h"
#include "closed_list.h"
#include "sym_variables.h"
#include "transition_relation.h"
......@@ -119,7 +120,8 @@ MEDDLY::dd_edge PlanReconstruction::select_any_state(const MEDDLY::dd_edge &in,
// Set don't cares to 0 values
for (size_t i = 0; i < state_vals_full.size(); i++) {
// Value don't care => we set it to a value which always exists
if (i % 2 == 1 && state_vals_full[i] == -1) {
if (i % 2 == 1 && state_vals_full[i] == -1 &&
SymAxiomEvaluator::is_primary(sym_vars->get_fd_index(i), task)) {
state_vals_full[i] = 0;
}
}
......
......@@ -5,6 +5,7 @@
#include <queue>
#include "../Meddly/operations_extension/userOperations.h"
#include "../utils/system.h"
#include "axioms/axiom_evaluator.h"
#include "sdac_parser/catamorph/interpreters/create_evmdd.h"
#include "symple_search.h"
#include "variable_order/variable_order.h"
......@@ -13,6 +14,7 @@ namespace symple {
SymVariables::SymVariables(const std::shared_ptr<AbstractTask> task)
: task(task),
evmdd_creator(nullptr),
sym_axioms(nullptr),
domain(nullptr),
forest(nullptr),
nVars(-1) {}
......@@ -37,6 +39,11 @@ void SymVariables::init(const SympleParams &params) {
evmdd_creator =
std::make_shared<EvmddCreator>(std::make_shared<SymVariables>(*this));
std::cout << "done!" << std::endl;
sym_axioms = std::make_shared<SymAxiomEvaluator>(
std::make_shared<SymVariables>(*this), task);
if (task->get_num_axioms()) {
sym_axioms->create_primary_representation();
}
}
void SymVariables::createDomain() {
......@@ -82,6 +89,9 @@ MEDDLY::dd_edge SymVariables::get_constant_edge(float constant) const {
}
MEDDLY::dd_edge SymVariables::get_var_edge(int var_id, bool primed) const {
if (SymAxiomEvaluator::is_secondary(var_id, task)) {
return sym_axioms->get_primary_representation(var_id, 1);
}
MEDDLY::dd_edge res(forest);
int level = 1 + 2 * get_level(var_id);
if (!primed) {
......@@ -109,6 +119,9 @@ MEDDLY::dd_edge SymVariables::get_var_edge(const std::string &var_name,
MEDDLY::dd_edge SymVariables::get_predicate_edge(int var_id, int val,
bool primed) const {
if (SymAxiomEvaluator::is_secondary(var_id, task)) {
return sym_axioms->get_primary_representation(var_id, val);
}
MEDDLY::dd_edge res(forest);
int level = 1 + 2 * get_level(var_id);
if (!primed) {
......@@ -122,14 +135,19 @@ MEDDLY::dd_edge SymVariables::get_predicate_edge(int var_id, int val,
}
MEDDLY::dd_edge SymVariables::get_state_edge(
const std::vector<int> &state_values, int cost) const {
const std::vector<int> &state_values, int cost, bool axiom_aware) const {
// Add entries for primed variables
bool with_primed = (state_values.size() == nVars);
MEDDLY::dd_edge res = this->get_constant_edge(0);
for (size_t i = 0; i < state_values.size(); i++) {
// -1 := ignore value
if (state_values[i] == -1) {
continue;
}
// only continue if axiom aware an secondary
if (!axiom_aware && SymAxiomEvaluator::is_secondary(i, task)) {
continue;
}
bool is_primed = with_primed && (i % 2) == 0;
int var_id = with_primed ? i / 2 : i;
MEDDLY::dd_edge var_edge =
......
......@@ -9,6 +9,7 @@ class EvmddCreator;
namespace symple {
struct SympleParams;
class SymAxiomEvaluator;
class SymVariables {
public:
......@@ -22,7 +23,7 @@ class SymVariables {
MEDDLY::dd_edge get_predicate_edge(int var_id, int val,
bool primed = false) const;
MEDDLY::dd_edge get_state_edge(const std::vector<int> &state_values,
int cost = 0) const;
int cost = 0, bool axiom_aware = false) const;
MEDDLY::dd_edge get_biimp_edge(int var_id);
MEDDLY::dd_edge min_abstract(const MEDDLY::dd_edge &from, int var_id,
......@@ -42,8 +43,9 @@ class SymVariables {
int get_fd_index(int level) const;
protected:
const std::shared_ptr<AbstractTask> task;
std::shared_ptr<AbstractTask> task;
std::shared_ptr<EvmddCreator> evmdd_creator;
std::shared_ptr<SymAxiomEvaluator> sym_axioms;
MEDDLY::domain *domain;
MEDDLY::forest *forest;
size_t nVars; // number of variables (unprimed+primed)
......
#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"
......@@ -35,7 +34,7 @@ SympleSearch::SympleSearch(const Options &opts)
SympleSearch::~SympleSearch() {}
void SympleSearch::print_statistics() const {
std::cout << "print some staticstics" << std::endl;
// std::cout << "print some staticstics" << std::endl;
}
void SympleSearch::initialize() {
......@@ -56,7 +55,7 @@ void SympleSearch::initialize() {
void SympleSearch::initialize_intial_state() {
std::cout << "init initial state..." << std::flush;
init_state = sym_vars->get_state_edge(task->get_initial_state_values());
// USER_OPS::to_dot(init_state, "init_state.dot");
USER_OPS::to_dot(init_state, "init_state.dot");
std::cout << "done!" << std::endl;
}
......@@ -66,9 +65,14 @@ void SympleSearch::initialize_goal_states() {
for (int i = 0; i < task->get_num_goals(); i++) {
auto fact = task->get_goal_fact(i);
goal_values[fact.var] = fact.value;
std::cout << task->get_variable_name(fact.var) << " : " << fact.value
<< std::endl;
USER_OPS::to_dot(
sym_vars->get_predicate_edge(fact.var, fact.value),
std::to_string(fact.var) + "_" + std::to_string(fact.value) + ".dot");
}
goal_states = sym_vars->get_state_edge(goal_values);
// USER_OPS::to_dot(goal_states, "goal_states.dot");
goal_states = sym_vars->get_state_edge(goal_values, 0, true);
USER_OPS::to_dot(goal_states, "goal_states.dot");
std::cout << "done!" << std::endl;
}
......
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