Commit 697a315c authored by David Speck's avatar David Speck

implemented feature: plan with ignoring sdac cost => it's assumed that all actions have unit costs

parent 3ad48d26
#! /bin/bash
if [ $# -lt 2 ] || [ $# -gt 2 ]; then
echo "usage: $(basename "$0") PROBLEM PLAN_FILE" 1>&2
exit 1
fi
BASEDIR="$(dirname "$0")"
PLANNER="symple(transition=100000,ignore_costs=true)"
SEARCH="$BASEDIR/src/search/downward"
$SEARCH --search $PLANNER --plan-file $2 < $1
......@@ -4,18 +4,19 @@
#ifndef IMAGE_CPP_
#define IMAGE_CPP_
#include <limits>
#include "./image.h"
#include "meddly_extensions/userDefiniedOperators.h"
#include <chrono>
#include <limits>
#include <map>
#include <stdio.h>
#include "./image.h"
#include "meddly_extensions/userDefiniedOperators.h"
//////////////////////////////////////////////////
//////////////////// create a state //////////////
//////////////////////////////////////////////////
void createInfEdges(MEDDLY::expert_forest* f, int av, MEDDLY::node_handle ap,
int &rv, MEDDLY::node_handle &rp) { // NOLINT for consistency
void createInfEdges(MEDDLY::expert_forest *f, int av, MEDDLY::node_handle ap,
int &rv,
MEDDLY::node_handle &rp) { // NOLINT for consistency
// is terminal node -> nothing to do
if (f->isTerminalNode(ap)) {
rv = av;
......@@ -27,8 +28,8 @@ int &rv, MEDDLY::node_handle &rp) { // NOLINT for consistency
const int resultSize = f->getLevelSize(resultLevel);
MEDDLY::unpacked_node *A = MEDDLY::unpacked_node::newFromNode(f, ap, true);
// Initialize result
MEDDLY::unpacked_node* nb = MEDDLY::unpacked_node::newFull(f, resultLevel,
resultSize);
MEDDLY::unpacked_node *nb =
MEDDLY::unpacked_node::newFull(f, resultLevel, resultSize);
int ev;
MEDDLY::node_handle ep;
for (int i = 0; i < resultSize; i++) {
......@@ -51,17 +52,17 @@ int &rv, MEDDLY::node_handle &rp) { // NOLINT for consistency
rv += av;
}
void stateToEVMDD(MEDDLY::forest* f, std::vector<int> &vals, int cost,
MEDDLY::dd_edge& res) {
void stateToEVMDD(MEDDLY::forest *f, std::vector<int> &vals, int cost,
MEDDLY::dd_edge &res) {
assert(vals.size() == g_variable_domain.size() * 2);
// create normal state path
int* stateAssignment = new int[vals.size() + 1];
int *stateAssignment = new int[vals.size() + 1];
stateAssignment[0] = 0;
for (int i = 0; i < vals.size(); i++) {
stateAssignment[i + 1] = vals.at(i);
}
int* assignments[] = { stateAssignment };
int costs[] = { cost };
int *assignments[] = {stateAssignment};
int costs[] = {cost};
f->createEdge(assignments, costs, 1, res);
// create for every other path a link to the terminal node with cost inf
......@@ -70,7 +71,7 @@ MEDDLY::dd_edge& res) {
MEDDLY::node_handle a = res.getNode();
int av, ev;
res.getEdgeValue(av);
createInfEdges(static_cast<MEDDLY::expert_forest*>(f), av, a, ev, result);
createInfEdges(static_cast<MEDDLY::expert_forest *>(f), av, a, ev, result);
res.set(result, ev);
// Clear memory
......@@ -80,8 +81,8 @@ MEDDLY::dd_edge& res) {
//////////////////////////////////////////////////
////////// create operator transitions ///////////
//////////////////////////////////////////////////
void preVarEdge(MEDDLY::forest* f, Operator& op, MEDDLY::dd_edge& res,
bool inverted) {
void preVarEdge(MEDDLY::forest *f, Operator &op, MEDDLY::dd_edge &res,
bool inverted) {
int nVars = g_variable_domain.size() * 2;
std::vector<int> vals;
for (int i = 0; i < nVars; i++) {
......@@ -100,7 +101,8 @@ bool inverted) {
int var = op.get_pre_post()[i].var;
int val = op.get_pre_post()[i].pre;
vals[2 * var + 1] = val;
// Note: -1 stands for no precodition which is exactly MEDDLY::DONT_CARE -> nothing to do
// Note: -1 stands for no precodition which is exactly MEDDLY::DONT_CARE ->
// nothing to do
// Handles conditional effects
// (only for axioms-> not really conditional)
......@@ -118,7 +120,7 @@ bool inverted) {
}
}
void effVarEdge(MEDDLY::forest* f, Operator& op, MEDDLY::dd_edge& res) {
void effVarEdge(MEDDLY::forest *f, Operator &op, MEDDLY::dd_edge &res) {
int nVars = g_variable_domain.size() * 2;
std::vector<int> vals;
for (int i = 0; i < nVars; i++) {
......@@ -136,8 +138,8 @@ void effVarEdge(MEDDLY::forest* f, Operator& op, MEDDLY::dd_edge& res) {
stateToEVMDD(f, vals, 0, res);
}
void condEffVarEdge(MEDDLY::forest* f, std::vector<PrePost> condV,
MEDDLY::dd_edge& res) {
void condEffVarEdge(MEDDLY::forest *f, std::vector<PrePost> condV,
MEDDLY::dd_edge &res) {
MEDDLY::dd_edge fires(f);
fires.set(-1, std::numeric_limits<int>::max());
/// Conditional effect fires:
......@@ -191,8 +193,8 @@ MEDDLY::dd_edge& res) {
int var = condV[0].var;
MEDDLY::dd_edge frame(f);
MEDDLY::node_handle result = -1;
valEqualsValEdge(static_cast<MEDDLY::expert_forest*>(f), 2 * var + 1, 2 * var,
result);
valEqualsValEdge(static_cast<MEDDLY::expert_forest *>(f), 2 * var + 1,
2 * var, result);
frame.set(result, 0);
/// combine pre, eff and frame
......@@ -200,7 +202,7 @@ MEDDLY::dd_edge& res) {
MEDDLY::apply(UNIONMIN, fires, notFires, res);
}
void condEffVarsEdge(MEDDLY::forest* f, Operator& op, MEDDLY::dd_edge& res) {
void condEffVarsEdge(MEDDLY::forest *f, Operator &op, MEDDLY::dd_edge &res) {
// empty conditional effect => return blank
if (!op.has_conditional_effects()) {
res.set(-1, 0);
......@@ -223,20 +225,20 @@ void condEffVarsEdge(MEDDLY::forest* f, Operator& op, MEDDLY::dd_edge& res) {
res.set(-1, 0);
for (auto elem : cEffVars) {
//std::cout << g_variable_name[elem.first] << " " << elem.second.size()
// std::cout << g_variable_name[elem.first] << " " << elem.second.size()
//<< std::endl;
MEDDLY::dd_edge curCondEffect(f);
condEffVarEdge(f, elem.second, curCondEffect);
MEDDLY::apply(INTERSECTIONMAX, res, curCondEffect, res);
}
//std::cout << "Full one: " << std::endl;
//MEDDLY::FILE_output out(stdout);
//res.show(out, 3);
// std::cout << "Full one: " << std::endl;
// MEDDLY::FILE_output out(stdout);
// res.show(out, 3);
}
void valEqualsValEdge(MEDDLY::expert_forest* f, int var1, int var2,
MEDDLY::node_handle &r) {
void valEqualsValEdge(MEDDLY::expert_forest *f, int var1, int var2,
MEDDLY::node_handle &r) {
assert(var1 > var2);
// Initialize result (+ 1 beacuse root is level 0)
......@@ -245,13 +247,13 @@ MEDDLY::node_handle &r) {
const int resultSize1 = f->getLevelSize(resultLevel1);
const int resultSize2 = f->getLevelSize(resultLevel2);
MEDDLY::unpacked_node* nb1 = MEDDLY::unpacked_node::newFull(f, resultLevel1,
resultSize1);
MEDDLY::unpacked_node *nb1 =
MEDDLY::unpacked_node::newFull(f, resultLevel1, resultSize1);
MEDDLY::node_handle cur_var2;
int dummy;
for (int i = 0; i < resultSize1; i++) {
MEDDLY::unpacked_node* nb2 = MEDDLY::unpacked_node::newFull(f, resultLevel2,
resultSize2);
MEDDLY::unpacked_node *nb2 =
MEDDLY::unpacked_node::newFull(f, resultLevel2, resultSize2);
for (int j = 0; j < resultSize2; j++) {
// 0 cost path!
if (i == j) {
......@@ -270,8 +272,8 @@ MEDDLY::node_handle &r) {
f->createReducedNode(-1, nb1, dummy, r);
}
void valsEqualsPrimedValsEdge(MEDDLY::forest* f, Operator& op,
MEDDLY::dd_edge& res) {
void valsEqualsPrimedValsEdge(MEDDLY::forest *f, Operator &op,
MEDDLY::dd_edge &res) {
// TODO(speckd): is there an more efficient way to find the eff vars?
std::vector<int> noEffVars;
for (int i = 0; i < g_variable_domain.size(); i++) {
......@@ -294,15 +296,15 @@ MEDDLY::dd_edge& res) {
// create assignments and combine the edges with each other
for (int i = 0; i < noEffVars.size(); i++) {
MEDDLY::dd_edge tmp(f);
valEqualsValEdge(static_cast<MEDDLY::expert_forest*>(f),
noEffVars[i] * 2 + 1, noEffVars[i] * 2, result);
valEqualsValEdge(static_cast<MEDDLY::expert_forest *>(f),
noEffVars[i] * 2 + 1, noEffVars[i] * 2, result);
tmp.set(result, cost);
MEDDLY::apply(INTERSECTIONMAX, res, tmp, res);
}
}
void createOpTrans(MEDDLY::forest* f, Operator& op, MEDDLY::dd_edge& res,
bool withCost) {
void createOpTrans(MEDDLY::forest *f, Operator &op, MEDDLY::dd_edge &res,
bool withCost) {
// pre vars
MEDDLY::dd_edge preVar(f);
preVarEdge(f, op, preVar);
......@@ -329,8 +331,8 @@ bool withCost) {
///////////////// File Handling //////////////////
//////////////////////////////////////////////////
bool writeEdge(std::string fileName, MEDDLY::forest* f, MEDDLY::dd_edge& edge) {
FILE * pFile;
bool writeEdge(std::string fileName, MEDDLY::forest *f, MEDDLY::dd_edge &edge) {
FILE *pFile;
pFile = fopen((fileName).c_str(), "w");
MEDDLY::FILE_output fileout(pFile);
f->writeEdges(fileout, &edge, 1);
......@@ -338,8 +340,8 @@ bool writeEdge(std::string fileName, MEDDLY::forest* f, MEDDLY::dd_edge& edge) {
return true;
}
bool readEdge(std::string fileName, MEDDLY::forest* f, MEDDLY::dd_edge& res) {
FILE * pFile;
bool readEdge(std::string fileName, MEDDLY::forest *f, MEDDLY::dd_edge &res) {
FILE *pFile;
pFile = fopen(fileName.c_str(), "r");
MEDDLY::FILE_input fileout(pFile);
f->readEdges(fileout, &res, 1);
......@@ -355,4 +357,4 @@ bool deleteFile(std::string fileName) {
return true;
}
#endif // IMAGE_CPP_
#endif // IMAGE_CPP_
......@@ -4,16 +4,18 @@
#ifndef OPERATIONTRANSITIONCREATER_H_
#define OPERATIONTRANSITIONCREATER_H_
#include "../operator.h"
#include "sdac_parser/parser.h"
#include <meddly.h>
#include <meddly_expert.h>
#include "sdac_parser/parser.h"
#include "../operator.h"
// Create transition relations for a list of operations with a certain node limit
void createOperationTransition(MEDDLY::forest* f, vector<Operator>& ops,
std::vector<std::shared_ptr<MEDDLY::dd_edge>>& opTrans, int nodeLimit);
// Create transition relations for a list of operations with a certain node
// limit
void createOperationTransition(
MEDDLY::forest *f, vector<Operator> &ops,
std::vector<std::shared_ptr<MEDDLY::dd_edge>> &opTrans, int nodeLimit);
// Creates and stores the cost function of an operator as EVMDD
void createOperationCostFunction(MEDDLY::forest* f, Operator* op);
void createOperationCostFunction(MEDDLY::forest *f, Operator *op);
#endif // OPERATIONTRANSITIONCREATER_H_
// Copyright 19.09.2017, University of Freiburg,
// Author: David Speck <speckd>.
#include <algorithm>
#include "aStarBwd.h"
#include "../image.h"
#include <algorithm>
void AStarBwd::image(MEDDLY::dd_edge& stateSet, MEDDLY::dd_edge& transOp,
MEDDLY::dd_edge &res) {
void AStarBwd::image(MEDDLY::dd_edge &stateSet, MEDDLY::dd_edge &transOp,
MEDDLY::dd_edge &res) {
MEDDLY::dd_edge primedStateSet(forest);
MEDDLY::apply(SWAPTOPRIMEDVAR, stateSet, primedStateSet);
MEDDLY::apply(MEDDLY::PLUS, primedStateSet, transOp, res);
......@@ -16,8 +16,8 @@ MEDDLY::dd_edge &res) {
}
}
void AStarBwd::imageInv(MEDDLY::dd_edge& stateSet, MEDDLY::dd_edge& transOp,
MEDDLY::dd_edge &res) {
void AStarBwd::imageInv(MEDDLY::dd_edge &stateSet, MEDDLY::dd_edge &transOp,
MEDDLY::dd_edge &res) {
// No plus => we want to preserve the costs here
MEDDLY::apply(INTERSECTIONMAX, stateSet, transOp, res);
for (int i = 2; i < g_variable_domain.size() * 2 + 1; i = i + 2) {
......@@ -27,18 +27,20 @@ MEDDLY::dd_edge &res) {
MEDDLY::apply(SWAPVARPRIMED, res, res);
}
bool AStarBwd::reconstructSolution(
MEDDLY::dd_edge& target, std::vector<const Operator *>& plan) {
//std::cout << "BWD REConstruction" << std::endl;
bool AStarBwd::reconstructSolution(MEDDLY::dd_edge &target,
std::vector<const Operator *> &plan) {
// std::cout << "BWD REConstruction" << std::endl;
std::vector<const Operator *> planBwd;
bool valid = SymSearch::reconstructSolution(target, planBwd);
for (int i = planBwd.size() - 1; i >= 0; i--)
std::reverse(planBwd.begin(), planBwd.end());
for (int i = 0; i < planBwd.size(); i++) {
plan.push_back(planBwd[i]);
//plan.insert(plan.end(), planBwd.begin(), planBwd.end());
}
// plan.insert(plan.end(), planBwd.begin(), planBwd.end());
return valid;
}
int AStarBwd::selectAnyState(MEDDLY::dd_edge& targetState) {
int AStarBwd::selectAnyState(MEDDLY::dd_edge &targetState) {
std::vector<int> stateValsFull = minPath(targetState);
int costAfter = minVal(targetState);
std::vector<int> stateVals;
......@@ -51,7 +53,6 @@ int AStarBwd::selectAnyState(MEDDLY::dd_edge& targetState) {
if (i % 2 == 1) {
stateVals.push_back(stateValsFull[i]);
}
}
// We generated one explicit state and use it from now on
......@@ -59,10 +60,10 @@ int AStarBwd::selectAnyState(MEDDLY::dd_edge& targetState) {
return costAfter;
}
Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
Operator *AStarBwd::reconstructPlanStep(MEDDLY::dd_edge &targetState) {
MEDDLY::FILE_output out(stdout);
int costAfter = selectAnyState(targetState);
//targetState.show(out, 3);
// targetState.show(out, 3);
for (int op_i = 0; op_i < g_operators.size(); op_i++) {
MEDDLY::dd_edge successors(forest);
imageInv(targetState, *g_operators[op_i].get_op_evmdd(), successors);
......@@ -73,42 +74,44 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// We need to add the cost to target and then check if it fits
MEDDLY::dd_edge costDummy(forest);
MEDDLY::apply(MEDDLY::PLUS, *g_operators[op_i].get_SDAC_cost(), targetState, costDummy);
MEDDLY::apply(MEDDLY::PLUS, *g_operators[op_i].get_SDAC_cost(),
targetState, costDummy);
int cost_tmp = minVal(costDummy);
costDummy.set(-1, cost_tmp);
MEDDLY::apply(MEDDLY::PLUS, tmp, costDummy, costDummy);
//std::cout << minVal(costDummy) << ", " << costAfter << std::endl;
// std::cout << minVal(costDummy) << ", " << costAfter << std::endl;
// Cost Fits
//std::cout << "Cost after: " << costAfter << ", minval" << minVal(tmp) << std::endl;
// std::cout << "Cost after: " << costAfter << ", minval" << minVal(tmp)
// << std::endl;
if (minVal(costDummy) == costAfter) {
//tmp.show(out, 3);
// tmp.show(out, 3);
MEDDLY::apply(MINSTATES, tmp, tmp);
// add cost to it
selectAnyState(tmp);
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));
//targetState.show(out, 3);
//std::cout << "-----------------------" << std::endl;
//std::cout << "\n" << curClosedList << std::endl;
// 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 dummy;
return &g_operators[op_i];
}
}
}
std::cout << "null operation - something went wrong - no op found!"
<< std::endl;
<< std::endl;
return nullptr;
}
// Old code used for paper submission
//Operator* AStarBwd::reconstructPlanStep2(
//std::vector<std::shared_ptr<MEDDLY::dd_edge>>& opTrans,
//MEDDLY::dd_edge& statesBefore, MEDDLY::dd_edge& targetState) {
// Operator* AStarBwd::reconstructPlanStep2(
// std::vector<std::shared_ptr<MEDDLY::dd_edge>>& opTrans,
// MEDDLY::dd_edge& statesBefore, MEDDLY::dd_edge& targetState) {
// std::vector<int> stateValsFull = minPath(targetState);
// int costAfter = minVal(targetState);
// std::vector<int> stateVals;
......@@ -154,9 +157,11 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
//
// Operator op = g_operators[op_i];
//
// /// Our goal state reachable with that cost!!!! really important otherwise the cost does not fit.
// /// Our goal state reachable with that cost!!!! really important otherwise
// the cost does not fit.
// /// Took me hours to find that bug :^)
// /// We search the cost of the current op and add it then to the states from before
// /// We search the cost of the current op and add it then to the states
// from before
// MEDDLY::dd_edge cost_tmp(forest);
// MEDDLY::apply(MEDDLY::PLUS, targetState, *op.get_SDAC_cost(), cost_tmp);
// cost_tmp.set(-1, minVal(cost_tmp) - minVal(targetState));
......@@ -170,7 +175,8 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// // if it is reachable with this cost
//
// MEDDLY::apply(INTERSECTIONMAX, costReachable, sStarPrimed, costReachable);
// //std::cout << g_operators[op_i].get_name() << " :" << minVal(costReachable)
// //std::cout << g_operators[op_i].get_name() << " :" <<
// minVal(costReachable)
// //<< std::endl;
//
// // We need only states which really have the same effects!
......@@ -179,7 +185,8 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// MEDDLY::apply(SWAPVARPRIMED, eff, eff);
// MEDDLY::apply(INTERSECTIONMAX, eff, costReachable, costReachable);
//
// /// check how the result state look like...we should replace it with the normal state
// /// check how the result state look like...we should replace it with the
// normal state
// /// function and apply an operator => thats basically what we do here...
// if (op.has_conditional_effects()) {
// MEDDLY::dd_edge cond_removal(forest);
......@@ -189,7 +196,8 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// if (pp.cond.size() == 0)
// continue;
//
// // Here we check if all! conditional prev are fitting with the target state
// // Here we check if all! conditional prev are fitting with the target
// state
// // If yes we know that the effect trigger!
// bool allfitting = true;
// for (auto &ce : pp.cond) {
......@@ -201,7 +209,8 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// if (!allfitting)
// continue;
//
// // now we add the conditional effects to the cond removal because it triggers!
// // now we add the conditional effects to the cond removal because it
// triggers!
// int nVars = g_variable_domain.size() * 2;
// std::vector<int> vals;
// for (int i = 0; i < nVars; i++) {
......@@ -263,9 +272,11 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// if (s == curState) {
// int costOfOperator = costAfter - costBefore;
//
// /*std::cout << costAfter << " - " << evaluatePath(*g_operators[op_i].get_SDAC_cost(), stateValsFull) << " = "
// /*std::cout << costAfter << " - " <<
// evaluatePath(*g_operators[op_i].get_SDAC_cost(), stateValsFull) << " = "
// << costBefore << std::endl;
// std::cout << g_operators[op_i].get_name() << " selected" << std::endl;*/
// std::cout << g_operators[op_i].get_name() << " selected" <<
// std::endl;*/
//
// // Important to minimize cost of targetState
// // Here we need to swap target and current state...
......@@ -314,4 +325,3 @@ Operator* AStarBwd::reconstructPlanStep(MEDDLY::dd_edge& targetState) {
// << std::endl;
// return nullptr;
//}
// Copyright 19.09.2017, University of Freiburg,
// Author: David Speck <speckd>.
#include <meddly.h>
#include <meddly_expert.h>
#include "symSearch.h"
#include "../meddly_extensions/userDefiniedOperators.h"
#include "../../operator.h"
#include "../../timer.h"
#include "../meddly_extensions/userDefiniedOperators.h"
#include "symSearch.h"
#include <meddly.h>
#include <meddly_expert.h>
#ifndef ASTARBWD_H_
#define ASTARBWD_H_
class AStarBwd: public SymSearch {
public:
AStarBwd() :
SymSearch() {
}
class AStarBwd : public SymSearch {
public:
AStarBwd() : SymSearch() {}
~AStarBwd() {
}
~AStarBwd() {}
/**
* Handles the complete backward search.
......@@ -27,24 +24,23 @@ class AStarBwd: public SymSearch {
* @param transOps Transition relations representing operations.
* @param plan A plan which will be filled with operations.
*/
bool reconstructSolution(
MEDDLY::dd_edge& target, std::vector<const Operator *>& plan);
protected:
bool reconstructSolution(MEDDLY::dd_edge &target,
std::vector<const Operator *> &plan);
void image(MEDDLY::dd_edge& stateSet, MEDDLY::dd_edge& transOp,
MEDDLY::dd_edge &res);
protected:
void image(MEDDLY::dd_edge &stateSet, MEDDLY::dd_edge &transOp,
MEDDLY::dd_edge &res);
void imageInv(MEDDLY::dd_edge& stateSet, MEDDLY::dd_edge& transOp,
MEDDLY::dd_edge &res);
void imageInv(MEDDLY::dd_edge &stateSet, MEDDLY::dd_edge &transOp,
MEDDLY::dd_edge &res);
Operator* reconstructPlanStep(MEDDLY::dd_edge& targetState);
Operator *reconstructPlanStep(MEDDLY::dd_edge &targetState);
/*Operator* reconstructPlanStep2(
std::vector<std::shared_ptr<MEDDLY::dd_edge>>& opTrans,
MEDDLY::dd_edge& statesBefore, MEDDLY::dd_edge& targetState);*/
int selectAnyState(MEDDLY::dd_edge& targetState);
int selectAnyState(MEDDLY::dd_edge &targetState);
};
#endif // ASTARBWD_H_
// Copyright 19.09.2017, University of Freiburg,
// Author: David Speck <speckd>.
#include <algorithm>
#include <functional>
#include "symSearch.h"
#include "../image.h"
#include "../operationTransitionCreater.h"
#include <algorithm>
#include <functional>
bool higherCost(Operator& op1, Operator& op2) {
bool higherCost(Operator &op1, Operator &op2) {
return op1.get_cost() > op2.get_cost();
}
void SymSearch::buildImage(
std::vector<std::shared_ptr<MEDDLY::dd_edge>>& transOps,
MEDDLY::dd_edge& cheapest, MEDDLY::dd_edge& newStates) {
std::vector<std::shared_ptr<MEDDLY::dd_edge>> &transOps,
MEDDLY::dd_edge &cheapest, MEDDLY::dd_edge &newStates) {
newStates.set(-1, std::numeric_limits<int>::max());
for (int i = 0; i < transOps.size(); i++) {
MEDDLY::dd_edge cur(forest);
......@@ -21,25 +22,28 @@ MEDDLY::dd_edge& cheapest, MEDDLY::dd_edge& newStates) {
}
}
bool SymSearch::reconstructSolution(MEDDLY::dd_edge& target,
std::vector<const Operator *>& plan) {
bool SymSearch::reconstructSolution(MEDDLY::dd_edge &target,
std::vector<const Operator *> &plan) {
MEDDLY::dd_edge curTargetStates(forest);
std::vector<int> targetState = minPath(target);
stateToEVMDD(forest, targetState, 0, curTargetStates);
// Due to architecture we need to search for the target state in open or closed
// Due to architecture we need to search for the target state in open or
// closed
MEDDLY::dd_edge allReachabelStates(forest);
MEDDLY::apply(UNIONMIN, open, closed, allReachabelStates);
MEDDLY::apply(INTERSECTIONMAX, curTargetStates, allReachabelStates,
curTargetStates);
curTargetStates);
int planCost = minVal(curTargetStates);
// We need to sort the operators according to there application cost due to 0 cost ops!
//using namespace std::placeholders;
// We need to sort the operators according to there application cost due to 0
// cost ops!
// using namespace std::placeholders;
if (!domain_has_sdac()) {
std::sort(g_operators.begin(), g_operators.end(),
std::bind(higherCost, std::placeholders::_1, std::placeholders::_2));
std::sort(
g_operators.begin(), g_operators.end(),
std::bind(higherCost, std::placeholders::_1, std::placeholders::_2));
}
std::cout << "Beginning plan reconstruction: " << std::endl;
......@@ -51,7 +55,7 @@ std::vector<const Operator *>& plan) {
curClosedList = closedLists.size();
while (minVal(startReached) == std::numeric_limits<int>::max()) {
Operator* curOp = reconstructPlanStep(curTargetStates);
Operator *curOp = reconstructPlanStep(curTargetStates);
if (curOp == nullptr)
return false;
plan.insert(plan.begin(), curOp);
......@@ -61,11 +65,12 @@ std::vector<const Operator *>& plan) {
MEDDLY::apply(INTERSECTIONMAX, curTargetStates, start, startReached);
}
std::cout << "DONE!" << std::endl;
return true;
}
void SymSearch::step(std::vector<std::shared_ptr<MEDDLY::dd_edge>>& transOps,
std::vector<std::shared_ptr<MEDDLY::dd_edge>>& mutexes) {
void SymSearch::step(std::vector<std::shared_ptr<MEDDLY::dd_edge>> &transOps,
std::vector<std::shared_ptr<MEDDLY::dd_edge>> &mutexes) {
double start = g_timer();
MEDDLY::dd_edge cheapest(forest);
......@@ -82,8 +87,8 @@ std::vector<std::shared_ptr<MEDDLY::dd_edge>>& mutexes) {
timeLastStep = g_timer() - start;
}
void SymSearch::updateOpen(MEDDLY::dd_edge& cheapest,
MEDDLY::dd_edge& newStates) {
void SymSearch::updateOpen(MEDDLY::dd_edge &cheapest,
MEDDLY::dd_edge &newStates) {
MEDDLY::apply(UNIONMIN, closed, cheapest, closed);
MEDDLY::dd_edge tmp(forest);
MEDDLY::apply(PARTIALCOMPLEMENT, closed, tmp);
......@@ -92,12 +97,11 @@ MEDDLY::dd_edge& newStates) {
// added to closed list
closedLists.push_back(
std::shared_ptr<MEDDLY::dd_edge>(new MEDDLY::dd_edge(cheapest)));
std::shared_ptr<MEDDLY::dd_edge>(new MEDDLY::dd_edge(cheapest)));
}
void SymSearch::removeMutexStatesFromOpenStates(
std::vector<std::shared_ptr<MEDDLY::dd_edge>>& mutexes) {
std::vector<std::shared_ptr<MEDDLY::dd_edge>> &mutexes) {
for (int i = 0; i < mutexes.size(); i++) {
MEDDLY::apply(INTERSECTIONMAX, open, *mutexes[i], open);
}
......
// Copyright 19.09.2017, University of Freiburg,
// Author: David Speck <speckd>.
#include <meddly.h>
#include <meddly_expert.h>
#include <map>
#include "../meddly_extensions/userDefiniedOperators.h"
#include "../../operator.h"
#include "../../timer.h"
#include "../meddly_extensions/userDefiniedOperators.h"
#include <map>
#include <meddly.h>
#include <meddly_expert.h>
#ifndef SYMSEARCH_H_
#define SYMSEARCH_H_
class SymSearch {
public:
public:
SymSearch() {
timeLastStep = 0;
curClosedList = -1;
forest = nullptr;
}
virtual ~SymSearch() {
}
virtual ~SymSearch() {}
void initialize(MEDDLY::forest* forest, MEDDLY::dd_edge& start) {
void initialize(MEDDLY::forest *forest, MEDDLY::dd_edge &start) {
this->start = start;
this->open = start;
this->forest = forest;
closed = MEDDLY::dd_edge(forest);
closed.set(-1, std::numeric_limits<int>::max());
MEDDLY::apply(UNIONMIN, closed, start, closed);
//closed.set(-1, 0);
// closed.set(-1, 0);
}
void step(std::vector<std::shared_ptr<MEDDLY::dd_edge>>& transOps,
std::vector<std::shared_ptr<MEDDLY::dd_edge>>& mutexes);
void step(std::vector<std::shared_ptr<MEDDLY::dd_edge>> &transOps,