Commit d5feb78b authored by David Speck's avatar David Speck

running version

parent 4a7847ef
...@@ -718,24 +718,27 @@ fast_downward_plugin( ...@@ -718,24 +718,27 @@ fast_downward_plugin(
symple/sym_astar symple/sym_astar
symple/plan_reconstruction symple/plan_reconstruction
symple/sym_enums symple/sym_enums
symple/bidirectional_potential symple/heuristics/bidirectional_potential
symple/heuristics/evmdd_encoder
symple/potential_open_list
Meddly/operations_extension/userOperations Meddly/operations_extension/userOperations
Meddly/operations_extension/evplus Meddly/operations_extension/evplus
Meddly/operations_extension/minus. Meddly/operations_extension/minus.
Meddly/operations_extension/multiply Meddly/operations_extension/multiply
Meddly/operations_extension/divide Meddly/operations_extension/divide
Meddly/operations_extension/unionmin Meddly/operations_extension/unionmin
Meddly/operations_extension/greaterThan Meddly/operations_extension/greaterThan
Meddly/operations_extension/greaterEquals Meddly/operations_extension/greaterEquals
Meddly/operations_extension/lessThan Meddly/operations_extension/lessThan
Meddly/operations_extension/lessEquals Meddly/operations_extension/lessEquals
Meddly/operations_extension/equals Meddly/operations_extension/equals
Meddly/operations_extension/intersectionmax Meddly/operations_extension/intersectionmax
Meddly/operations_extension/partialcomplement Meddly/operations_extension/partialcomplement
Meddly/operations_extension/pow Meddly/operations_extension/pow
Meddly/operations_extension/restrict Meddly/operations_extension/restrict
Meddly/operations_extension/swapVar Meddly/operations_extension/swapVar
Meddly/operations_extension/pot_heuristic
Meddly/operations_extension/copy
DEPENDS DEPENDS
) )
......
...@@ -2,52 +2,45 @@ ...@@ -2,52 +2,45 @@
// Author: David Speck <speckd>. // Author: David Speck <speckd>.
#include "evplus.h" #include "evplus.h"
#include "userOperations.h"
#include <limits>
#include <meddly.h> #include <meddly.h>
#include <meddly_expert.h> #include <meddly_expert.h>
#include <limits>
#include "userOperations.h"
const MEDDLY::binary_opname *USER_OPS::EVPLUS; const MEDDLY::binary_opname *USER_OPS::EVPLUS;
namespace USER_OPS namespace USER_OPS {
{
class EVPlus; class EVPlus;
class Plus_Opname; class Plus_Opname;
} // namespace USER_OPS } // namespace USER_OPS
class USER_OPS::EVPlus : public MEDDLY::binary_operation class USER_OPS::EVPlus : public MEDDLY::binary_operation {
{ public:
public:
EVPlus(const MEDDLY::binary_opname *code, MEDDLY::expert_forest *arg1, EVPlus(const MEDDLY::binary_opname *code, MEDDLY::expert_forest *arg1,
MEDDLY::expert_forest *arg2, MEDDLY::expert_forest *res) MEDDLY::expert_forest *arg2, MEDDLY::expert_forest *res)
: binary_operation(code, 4, 2, arg1, arg2, res) : binary_operation(code, 4, 2, arg1, arg2, res) {
{
can_commute = true; can_commute = true;
} }
bool isStaleEntry(const MEDDLY::node_handle *entry) bool isStaleEntry(const MEDDLY::node_handle *entry) {
{
return arg1F->isStale(entry[1]) || arg2F->isStale(entry[3]) || return arg1F->isStale(entry[1]) || arg2F->isStale(entry[3]) ||
resF->isStale(entry[5]); resF->isStale(entry[5]);
} }
void discardEntry(const MEDDLY::node_handle *entryData) void discardEntry(const MEDDLY::node_handle *entryData) {
{
arg1F->uncacheNode(entryData[1]); arg1F->uncacheNode(entryData[1]);
arg2F->uncacheNode(entryData[3]); arg2F->uncacheNode(entryData[3]);
resF->uncacheNode(entryData[5]); resF->uncacheNode(entryData[5]);
} }
void showEntry(MEDDLY::output &strm, const MEDDLY::node_handle *data) const void showEntry(MEDDLY::output &strm, const MEDDLY::node_handle *data) const {
{
strm << "[" << getName() << "(<" << long(data[0]) << ":" << long(data[1]) strm << "[" << getName() << "(<" << long(data[0]) << ":" << long(data[1])
<< ">, <" << long(data[2]) << ":" << long(data[3]) << ">): <" << ">, <" << long(data[2]) << ":" << long(data[3]) << ">): <"
<< long(data[4]) << ":" << long(data[5]) << ">]"; << long(data[4]) << ":" << long(data[5]) << ">]";
} }
void computeDDEdge(const MEDDLY::dd_edge &ar1, const MEDDLY::dd_edge &ar2, void computeDDEdge(const MEDDLY::dd_edge &ar1, const MEDDLY::dd_edge &ar2,
MEDDLY::dd_edge &res) MEDDLY::dd_edge &res) {
{
MEDDLY::node_handle result; MEDDLY::node_handle result;
float ev, aev, bev; float ev, aev, bev;
ar1.getEdgeValue(aev); ar1.getEdgeValue(aev);
...@@ -56,21 +49,18 @@ public: ...@@ -56,21 +49,18 @@ public:
res.set(result, ev); res.set(result, ev);
} }
protected:
void compute(float aev, MEDDLY::node_handle a, float bev, void compute(float aev, MEDDLY::node_handle a, float bev,
MEDDLY::node_handle b, float &cev, MEDDLY::node_handle &c) MEDDLY::node_handle b, float &cev, MEDDLY::node_handle &c) {
{ // std::cout << "<" << aev << ", " << a << ">, " << "<" << bev << ", " << b
// std::cout << "<" << aev << ", " << a << ">, " << "<" << bev << ", " << b << "> " << std::endl; // << "> " << std::endl;
if (checkTerminals(aev, a, bev, b, cev, c)) if (checkTerminals(aev, a, bev, b, cev, c)) return;
return;
float residual = aev + bev; // remove for default PLUS float residual = aev + bev; // remove for default PLUS
aev = bev = 0; // remove for default PLUS aev = bev = 0; // remove for default PLUS
MEDDLY::compute_table::search_key *Key = findResult(aev, a, bev, b, cev, c); MEDDLY::compute_table::search_key *Key = findResult(aev, a, bev, b, cev, c);
if (0 == Key) if (0 == Key) {
{
// std::cout << "Cache hit" << std::endl; // std::cout << "Cache hit" << std::endl;
cev += residual; // remove for default PLUS cev += residual; // remove for default PLUS
return; return;
} }
// Get level information // Get level information
...@@ -98,8 +88,7 @@ protected: ...@@ -98,8 +88,7 @@ protected:
: MEDDLY::unpacked_node::newFromNode(arg2F, b, true); : MEDDLY::unpacked_node::newFromNode(arg2F, b, true);
// do computation // do computation
for (int i = 0; i < resultSize; i++) for (int i = 0; i < resultSize; i++) {
{
float ev; float ev;
MEDDLY::node_handle ed; MEDDLY::node_handle ed;
compute(aev + A->ef(i), A->d(i), bev + B->ef(i), B->d(i), ev, ed); compute(aev + A->ef(i), A->d(i), bev + B->ef(i), B->d(i), ev, ed);
...@@ -121,60 +110,52 @@ protected: ...@@ -121,60 +110,52 @@ protected:
// Add to CT // Add to CT
saveResult(Key, a, b, cev, c); saveResult(Key, a, b, cev, c);
cev += residual; // remove for default PLUS cev += residual; // remove for default PLUS
} }
protected:
// Check if something is a terminal // Check if something is a terminal
bool checkTerminals(float aev, MEDDLY::node_handle a, float bev, bool checkTerminals(float aev, MEDDLY::node_handle a, float bev,
MEDDLY::node_handle b, float &cev, MEDDLY::node_handle b, float &cev,
MEDDLY::node_handle &c) MEDDLY::node_handle &c) {
{ if (a == -1 && b == -1) {
if (a == -1 && b == -1)
{
c = -1; c = -1;
cev = aev + bev; cev = aev + bev;
return true; return true;
} }
// Case where one (or both) edge is infinity // Case where one (or both) edge is infinity
if (aev == INFTY || bev == INFTY) if (aev == INFTY || bev == INFTY) {
{
c = -1; c = -1;
cev = INFTY; cev = INFTY;
return true; return true;
} }
if (0 == a || 0 == b) if (0 == a || 0 == b) {
{
std::cout << "ERROR => Zero edge pointer in intersectionmax" << std::endl; std::cout << "ERROR => Zero edge pointer in intersectionmax" << std::endl;
return true; return true;
} }
return false; return false;
} }
MEDDLY::compute_table::search_key * MEDDLY::compute_table::search_key *findResult(
findResult(float aev, MEDDLY::node_handle a, float bev, MEDDLY::node_handle b, float aev, MEDDLY::node_handle a, float bev, MEDDLY::node_handle b,
float &cev, MEDDLY::node_handle &c) float &cev, MEDDLY::node_handle &c) {
{
MEDDLY::compute_table::search_key *CTsrch = useCTkey(); MEDDLY::compute_table::search_key *CTsrch = useCTkey();
MEDDLY_DCASSERT(CTsrch); MEDDLY_DCASSERT(CTsrch);
CTsrch->reset(); CTsrch->reset();
if (can_commute && a > b) if (can_commute && a > b) {
{
CTsrch->write(bev); CTsrch->write(bev);
CTsrch->writeNH(b); CTsrch->writeNH(b);
CTsrch->write(aev); CTsrch->write(aev);
CTsrch->writeNH(a); CTsrch->writeNH(a);
} } else {
else
{
CTsrch->write(aev); CTsrch->write(aev);
CTsrch->writeNH(a); CTsrch->writeNH(a);
CTsrch->write(bev); CTsrch->write(bev);
CTsrch->writeNH(b); CTsrch->writeNH(b);
} }
MEDDLY::compute_table::search_result &cacheFind = CT->find(CTsrch); MEDDLY::compute_table::search_result &cacheFind = CT->find(CTsrch);
if (!cacheFind) if (!cacheFind) return CTsrch;
return CTsrch;
cacheFind.read(cev); cacheFind.read(cev);
c = resF->linkNode(cacheFind.readNH()); c = resF->linkNode(cacheFind.readNH());
doneCTkey(CTsrch); doneCTkey(CTsrch);
...@@ -182,8 +163,7 @@ protected: ...@@ -182,8 +163,7 @@ protected:
} }
void saveResult(MEDDLY::compute_table::search_key *Key, MEDDLY::node_handle a, void saveResult(MEDDLY::compute_table::search_key *Key, MEDDLY::node_handle a,
MEDDLY::node_handle b, float cev, MEDDLY::node_handle c) MEDDLY::node_handle b, float cev, MEDDLY::node_handle c) {
{
arg1F->cacheNode(a); arg1F->cacheNode(a);
arg2F->cacheNode(b); arg2F->cacheNode(b);
MEDDLY::compute_table::entry_builder &entry = CT->startNewEntry(Key); MEDDLY::compute_table::entry_builder &entry = CT->startNewEntry(Key);
...@@ -193,20 +173,17 @@ protected: ...@@ -193,20 +173,17 @@ protected:
} }
}; };
class USER_OPS::Plus_Opname : public MEDDLY::binary_opname class USER_OPS::Plus_Opname : public MEDDLY::binary_opname {
{ public:
public:
Plus_Opname() : binary_opname("EVPLUS") {} Plus_Opname() : binary_opname("EVPLUS") {}
MEDDLY::binary_operation *buildOperation(MEDDLY::expert_forest *arg1, MEDDLY::binary_operation *buildOperation(MEDDLY::expert_forest *arg1,
MEDDLY::expert_forest *arg2, MEDDLY::expert_forest *arg2,
MEDDLY::expert_forest *res) const MEDDLY::expert_forest *res) const {
{
return new USER_OPS::EVPlus(this, arg1, arg2, res); return new USER_OPS::EVPlus(this, arg1, arg2, res);
} }
}; };
void USER_OPS::initializePlus() void USER_OPS::initializePlus() {
{
USER_OPS::EVPLUS = new USER_OPS::Plus_Opname(); USER_OPS::EVPLUS = new USER_OPS::Plus_Opname();
} }
...@@ -7,12 +7,11 @@ ...@@ -7,12 +7,11 @@
#include <meddly.h> #include <meddly.h>
#include <meddly_expert.h> #include <meddly_expert.h>
namespace USER_OPS { namespace USER_OPS {
extern const MEDDLY::binary_opname* EVPLUS;
void initializePlus();
extern const MEDDLY::binary_opname *EVPLUS;
} void initializePlus();
} // namespace USER_OPS
#endif // EVMDD_PLUSREAL_PLUS_H_ #endif // EVMDD_PLUSREAL_PLUS_H_
// Copyright 05.07.2018, University of Freiburg, // Copyright 05.07.2018, University of Freiburg,
// Author: David Speck <speckd>. // Author: David Speck <speckd>.
#include "pow.h"
#include <meddly.h> #include <meddly.h>
#include <meddly_expert.h> #include <meddly_expert.h>
#include <limits>
#include <cmath> #include <cmath>
#include "pow.h" #include <limits>
#include "userOperations.h" #include "userOperations.h"
const MEDDLY::unary_opname *USER_OPS::POW; const MEDDLY::unary_opname *USER_OPS::POW;
namespace USER_OPS namespace USER_OPS {
{
class Pow; class Pow;
class Pow_Opname; class Pow_Opname;
} // namespace USER_OPS } // namespace USER_OPS
class USER_OPS::Pow : public MEDDLY::unary_operation
{
public:
Pow(const MEDDLY::unary_opname *code,
MEDDLY::expert_forest *arg, MEDDLY::expert_forest *res)
: MEDDLY::unary_operation(code, 3, 2, arg, res), exp(2)
{
}
void setExp(float exp) class USER_OPS::Pow : public MEDDLY::unary_operation {
{ public:
this->exp = exp; Pow(const MEDDLY::unary_opname *code, MEDDLY::expert_forest *arg,
} MEDDLY::expert_forest *res)
: MEDDLY::unary_operation(code, 3, 2, arg, res), exp(2) {}
void setExp(float exp) { this->exp = exp; }
void discardEntry(const MEDDLY::node_handle *data) void discardEntry(const MEDDLY::node_handle *data) {
{
argF->uncacheNode(data[2]); argF->uncacheNode(data[2]);
resF->uncacheNode(data[4]); resF->uncacheNode(data[4]);
} }
bool isStaleEntry(const MEDDLY::node_handle *data) bool isStaleEntry(const MEDDLY::node_handle *data) {
{
return argF->isStale(data[2]) || resF->isStale(data[4]); return argF->isStale(data[2]) || resF->isStale(data[4]);
} }
void showEntry(MEDDLY::output &strm, const MEDDLY::node_handle* /*data*/) const void showEntry(MEDDLY::output &strm,
{ const MEDDLY::node_handle * /*data*/) const {
strm << "todo"; strm << "todo";
} }
void computeDDEdge(const MEDDLY::dd_edge &a, MEDDLY::dd_edge &b) void computeDDEdge(const MEDDLY::dd_edge &a, MEDDLY::dd_edge &b) {
{
MEDDLY::node_handle result; MEDDLY::node_handle result;
float av, ev; float av, ev;
a.getEdgeValue(av); a.getEdgeValue(av);
...@@ -55,12 +45,13 @@ public: ...@@ -55,12 +45,13 @@ public:
b.set(result, ev); b.set(result, ev);
} }
protected: protected:
float exp; float exp;
MEDDLY::compute_table::search_key *findResult(float aev, MEDDLY::node_handle a, float &cv, MEDDLY::compute_table::search_key *findResult(float aev,
MEDDLY::node_handle &c) MEDDLY::node_handle a,
{ float &cv,
MEDDLY::node_handle &c) {
MEDDLY::compute_table::search_key *CTsrch = useCTkey(); MEDDLY::compute_table::search_key *CTsrch = useCTkey();
MEDDLY_DCASSERT(CTsrch); MEDDLY_DCASSERT(CTsrch);
CTsrch->reset(); CTsrch->reset();
...@@ -68,8 +59,7 @@ protected: ...@@ -68,8 +59,7 @@ protected:
CTsrch->write(aev); CTsrch->write(aev);
CTsrch->writeNH(a); CTsrch->writeNH(a);
MEDDLY::compute_table::search_result &cacheFind = CT->find(CTsrch); MEDDLY::compute_table::search_result &cacheFind = CT->find(CTsrch);
if (!cacheFind) if (!cacheFind) return CTsrch;
return CTsrch;
cacheFind.read(cv); cacheFind.read(cv);
c = resF->linkNode(cacheFind.readNH()); c = resF->linkNode(cacheFind.readNH());
doneCTkey(CTsrch); doneCTkey(CTsrch);
...@@ -77,8 +67,7 @@ protected: ...@@ -77,8 +67,7 @@ protected:
} }
void saveResult(MEDDLY::compute_table::search_key *Key, MEDDLY::node_handle a, void saveResult(MEDDLY::compute_table::search_key *Key, MEDDLY::node_handle a,
float cv, MEDDLY::node_handle c) float cv, MEDDLY::node_handle c) {
{
argF->cacheNode(a); argF->cacheNode(a);
MEDDLY::compute_table::entry_builder &entry = CT->startNewEntry(Key); MEDDLY::compute_table::entry_builder &entry = CT->startNewEntry(Key);
entry.writeResult(cv); entry.writeResult(cv);
...@@ -86,18 +75,16 @@ protected: ...@@ -86,18 +75,16 @@ protected:
CT->addEntry(); CT->addEntry();
} }
void compute(float av, MEDDLY::node_handle ap, float &rv, MEDDLY::node_handle &rp) void compute(float av, MEDDLY::node_handle ap, float &rv,
{ MEDDLY::node_handle &rp) {
if (argF->isTerminalNode(ap)) if (argF->isTerminalNode(ap)) {
{
rv = std::pow(av, exp); rv = std::pow(av, exp);
rp = ap; rp = ap;
return; return;
} }
// If we already visited the node we stop here // If we already visited the node we stop here
MEDDLY::compute_table::search_key *Key = findResult(av, ap, rv, rp); MEDDLY::compute_table::search_key *Key = findResult(av, ap, rv, rp);
if (0 == Key) if (0 == Key) {
{
return; return;
} }
...@@ -105,18 +92,17 @@ protected: ...@@ -105,18 +92,17 @@ protected:
int resultLevel = argF->getNodeLevel(ap); int resultLevel = argF->getNodeLevel(ap);
const int resultSize = resF->getLevelSize(resultLevel); const int resultSize = resF->getLevelSize(resultLevel);
MEDDLY::unpacked_node *A = MEDDLY::unpacked_node::newFromNode(argF, ap, MEDDLY::unpacked_node *A =
true); MEDDLY::unpacked_node::newFromNode(argF, ap, true);
// Initialize result // Initialize result
MEDDLY::unpacked_node *nb = MEDDLY::unpacked_node::newFull(resF, MEDDLY::unpacked_node *nb =
resultLevel, resultSize); MEDDLY::unpacked_node::newFull(resF, resultLevel, resultSize);
// Recursive call // Recursive call
float ev; float ev;
MEDDLY::node_handle ep; MEDDLY::node_handle ep;
for (int i = 0; i < resultSize; i++) for (int i = 0; i < resultSize; i++) {
{
compute(A->ef(i) + av, A->d(i), ev, ep); compute(A->ef(i) + av, A->d(i), ev, ep);
nb->d_ref(i) = ep; nb->d_ref(i) = ep;
nb->setEdge(i, ev); nb->setEdge(i, ev);
...@@ -134,30 +120,21 @@ protected: ...@@ -134,30 +120,21 @@ protected:
} }
}; };
class USER_OPS::Pow_Opname : public MEDDLY::unary_opname class USER_OPS::Pow_Opname : public MEDDLY::unary_opname {
{ public:
public: Pow_Opname() : unary_opname("ParitalComplement") {}
Pow_Opname() : unary_opname("ParitalComplement")
{
}
MEDDLY::unary_operation *buildOperation(MEDDLY::expert_forest *arg1, MEDDLY::unary_operation *buildOperation(MEDDLY::expert_forest *arg1,
MEDDLY::expert_forest *res) const MEDDLY::expert_forest *res) const {
{
return new USER_OPS::Pow(this, arg1, res); return new USER_OPS::Pow(this, arg1, res);
} }
}; };
void USER_OPS::initializePow() void USER_OPS::initializePow() { USER_OPS::POW = new USER_OPS::Pow_Opname; }
{
USER_OPS::POW = new USER_OPS::Pow_Opname;
}
void USER_OPS::setPowExp(const MEDDLY::dd_edge &arg, const MEDDLY::dd_edge &res, void USER_OPS::setPowExp(const MEDDLY::dd_edge &arg, const MEDDLY::dd_edge &res,
float exp) float exp) {
{ Pow *powOP = reinterpret_cast<Pow *>(MEDDLY::getOperation(POW, arg, res));
Pow *powOP = reinterpret_cast<Pow *>(MEDDLY::getOperation(
POW, arg, res));
powOP->setExp(exp); powOP->setExp(exp);
powOP = nullptr; powOP = nullptr;
} }
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
#ifndef POW_H_ #ifndef POW_H_
#define POW_H_ #define POW_H_
namespace USER_OPS #include <meddly.h>
{ #include <meddly_expert.h>
namespace USER_OPS {
extern const MEDDLY::unary_opname *POW; extern const MEDDLY::unary_opname *POW;
void initializePow(); void initializePow();
void setPowExp(const MEDDLY::dd_edge &arg, const MEDDLY::dd_edge &res, void setPowExp(const MEDDLY::dd_edge &arg, const MEDDLY::dd_edge &res,
float exp); float exp);
} // namespace USER_OPS } // namespace USER_OPS
#endif // POW_H_ #endif // POW_H_
\ No newline at end of file
...@@ -2,12 +2,16 @@ ...@@ -2,12 +2,16 @@
// Author: David Speck <speckd> // Author: David Speck <speckd>
#include "userOperations.h" #include "userOperations.h"
#include <fstream>
#include <iomanip>
#include <limits> #include <limits>
#include <set>
#include <sstream>
#include <stack>
const float INFTY = std::numeric_limits<float>::infinity(); const float INFTY = std::numeric_limits<float>::infinity();
void USER_OPS::initializeUserOperations() void USER_OPS::initializeUserOperations() {
{
USER_OPS::initializePlus(); USER_OPS::initializePlus();
USER_OPS::initializeMinus(); USER_OPS::initializeMinus();
USER_OPS::initializeMultiply(); USER_OPS::initializeMultiply();
...@@ -23,4 +27,106 @@ void USER_OPS::initializeUserOperations() ...@@ -23,4 +27,106 @@ void USER_OPS::initializeUserOperations()
USER_OPS::initializePow(); USER_OPS::initializePow();
USER_OPS::initializeRestrict(); USER_OPS::initializeRestrict();
USER_OPS::initializeSwapVar(); USER_OPS::initializeSwapVar();
} USER_OPS::initializePotHeuristic();
\ No newline at end of file USER_OPS::initializeCopy();
}
template <typename T>
std::string to_string_with_precision(const T a_value, const int n = 20) {
std::ostringstream out;
out << std::setprecision(n) << a_value;
// std::string res = out.str();
// res.erase(res.find_last_not_of('0') + 1, std::string::npos);
return out.str();
}
void USER_OPS::to_dot(const MEDDLY::dd_edge &edge, std::string file_name) {
MEDDLY::forest *f = edge.getForest();
MEDDLY::expert_forest *exp_forest = static_cast<MEDDLY::expert_forest *>(f);
// Collect edge data
std::set<int> closed_nodes;
std::map<int, std::string> levels_to_output;
std::string edges;
std::stack<MEDDLY::node_handle> node_stack;
node_stack.push(edge.getNode());
float incoming_weight;
edge.getEdgeValue(incoming_weight);