Commit 60029883 authored by David Speck's avatar David Speck

fixed a bug where invalid plans are generated

parent 81c1d8ee
......@@ -215,6 +215,20 @@ void condEffVarsEdge(MEDDLY::forest *f, Operator &op, MEDDLY::dd_edge &res) {
if (op.get_pre_post()[i].cond.size() > 0) {
// We have a conditional effect:
int var = op.get_pre_post()[i].var;
int val = op.get_pre_post()[i].pre;
bool inconsistent = false;
for (int c = 0; c < op.get_pre_post()[i].cond.size(); c++) {
int var_c = op.get_pre_post()[i].cond[c].var;
int val_c = op.get_pre_post()[i].cond[c].prev;
if (var == var_c && val != val_c) {
inconsistent = true;
break;
}
}
if (inconsistent) {
continue;
}
if (cEffVars.find(var) == cEffVars.end()) {
cEffVars[var] = std::vector<PrePost>();
......
......@@ -92,14 +92,14 @@ Operator *AStarBwd::reconstructPlanStep(MEDDLY::dd_edge &targetState) {
MEDDLY::apply(INTERSECTIONMAX, tmp, *closedLists[c_i], targetState);
// create dummy op with correct cost
// Operator *dummy = new Operator(g_operators[op_i].get_name(),
// costAfter - minVal(targetState));
// dummy->set_cost_function(g_operators[op_i].get_SDAC_cost_function());
Operator *dummy = new Operator(g_operators[op_i].get_name(),
costAfter - minVal(targetState));
dummy->set_cost_function(g_operators[op_i].get_SDAC_cost_function());
// targetState.show(out, 3);
// std::cout << "-----------------------" << std::endl;
// std::cout << "\n" << curClosedList << std::endl;
curClosedList = c_i;
return &g_operators[op_i];
return dummy;
}
}
}
......
......@@ -138,7 +138,10 @@ int symple::step() {
if (!astarBwd.reconstructSolution(collisionFound, plan)) {
return FAILED;
}
setCorrectCosts(plan);
if (!validatePlan(plan)) {
std::cerr << "Plan not valid!" << std::endl;
return FAILED;
}
save_plan(plan, plan_id);
std::cout << "Plan reconstruction took: " << g_timer() - startRec
......@@ -159,7 +162,10 @@ int symple::step() {
if (!astarBwd.reconstructSolution(collisionFound, plan)) {
return FAILED;
}
setCorrectCosts(plan);
if (!validatePlan(plan)) {
std::cerr << "Plan not valid!" << std::endl;
return FAILED;
}
// if (sat_planning)
// save_plan(plan, plan_id);
......@@ -199,7 +205,10 @@ int symple::step() {
if (!astarBwd.reconstructSolution(collisionFound, plan)) {
return FAILED;
}
setCorrectCosts(plan);
if (!validatePlan(plan)) {
std::cerr << "Plan not valid!" << std::endl;
return FAILED;
}
// if (sat_planning)
// save_plan(plan, plan_id);
......@@ -387,23 +396,34 @@ void symple::backwardStep() {
lastStepFwd = false;
}
void symple::setCorrectCosts(std::vector<const Operator *> &plan) {
bool symple::validatePlan(std::vector<const Operator *> &plan) {
State cur = *g_initial_state;
// cur.dump_fdr();
int step = 0;
for (auto op : plan) {
for (auto dummy_op : plan) {
Operator op("dummy", 0);
for (auto real_op : g_operators) {
if (real_op.get_name() == dummy_op->get_name()) {
op = real_op;
break;
}
}
if (!op.is_applicable(cur)) {
return false;
}
// Build up the cost functions and dummy operator
Operator *dummy = new Operator(op->get_name(), 0);
dummy->set_cost_function(op->get_SDAC_cost_function());
Operator *dummy = new Operator(op.get_name(), op.get_cost());
dummy->set_cost_function(op.get_SDAC_cost_function());
createOperationCostFunction(forest, dummy);
int cost = dummy->get_cost(cur);
dummy = new Operator(op->get_name(), cost);
dummy = new Operator(op.get_name(), cost);
plan[step] = dummy;
cur = State(cur, *op);
cur = State(cur, op);
step++;
// cur.dump_fdr();
}
return test_goal(cur);
}
void symple::dumpPlannerInformation() {
......
......@@ -39,7 +39,7 @@ protected:
void forwardStep();
void backwardStep();
void setCorrectCosts(std::vector<const Operator *> &plan);
bool validatePlan(std::vector<const Operator *> &plan);
/** Option of different transition relations for operators.
* -1 = One big relation for all operators
......
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