Commit d5feb78b authored by David Speck's avatar David Speck

running version

parent 4a7847ef
......@@ -718,7 +718,9 @@ fast_downward_plugin(
symple/sym_astar
symple/plan_reconstruction
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/evplus
Meddly/operations_extension/minus.
......@@ -735,7 +737,8 @@ fast_downward_plugin(
Meddly/operations_extension/pow
Meddly/operations_extension/restrict
Meddly/operations_extension/swapVar
Meddly/operations_extension/pot_heuristic
Meddly/operations_extension/copy
DEPENDS
)
......
......@@ -2,52 +2,45 @@
// Author: David Speck <speckd>.
#include "evplus.h"
#include "userOperations.h"
#include <limits>
#include <meddly.h>
#include <meddly_expert.h>
#include <limits>
#include "userOperations.h"
const MEDDLY::binary_opname *USER_OPS::EVPLUS;
namespace USER_OPS
{
namespace USER_OPS {
class EVPlus;
class Plus_Opname;
} // namespace USER_OPS
class USER_OPS::EVPlus : public MEDDLY::binary_operation
{
public:
class USER_OPS::EVPlus : public MEDDLY::binary_operation {
public:
EVPlus(const MEDDLY::binary_opname *code, MEDDLY::expert_forest *arg1,
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;
}
bool isStaleEntry(const MEDDLY::node_handle *entry)
{
bool isStaleEntry(const MEDDLY::node_handle *entry) {
return arg1F->isStale(entry[1]) || arg2F->isStale(entry[3]) ||
resF->isStale(entry[5]);
}
void discardEntry(const MEDDLY::node_handle *entryData)
{
void discardEntry(const MEDDLY::node_handle *entryData) {
arg1F->uncacheNode(entryData[1]);
arg2F->uncacheNode(entryData[3]);
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])
<< ">, <" << long(data[2]) << ":" << long(data[3]) << ">): <"
<< long(data[4]) << ":" << long(data[5]) << ">]";
}
void computeDDEdge(const MEDDLY::dd_edge &ar1, const MEDDLY::dd_edge &ar2,
MEDDLY::dd_edge &res)
{
MEDDLY::dd_edge &res) {
MEDDLY::node_handle result;
float ev, aev, bev;
ar1.getEdgeValue(aev);
......@@ -56,19 +49,16 @@ public:
res.set(result, ev);
}
protected:
void compute(float aev, MEDDLY::node_handle a, float bev,
MEDDLY::node_handle b, float &cev, MEDDLY::node_handle &c)
{
// std::cout << "<" << aev << ", " << a << ">, " << "<" << bev << ", " << b << "> " << std::endl;
if (checkTerminals(aev, a, bev, b, cev, c))
return;
MEDDLY::node_handle b, float &cev, MEDDLY::node_handle &c) {
// std::cout << "<" << aev << ", " << a << ">, " << "<" << bev << ", " << b
// << "> " << std::endl;
if (checkTerminals(aev, a, bev, b, cev, c)) return;
float residual = aev + bev; // remove for default PLUS
aev = bev = 0; // remove for default PLUS
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;
cev += residual; // remove for default PLUS
return;
......@@ -98,8 +88,7 @@ protected:
: MEDDLY::unpacked_node::newFromNode(arg2F, b, true);
// do computation
for (int i = 0; i < resultSize; i++)
{
for (int i = 0; i < resultSize; i++) {
float ev;
MEDDLY::node_handle ed;
compute(aev + A->ef(i), A->d(i), bev + B->ef(i), B->d(i), ev, ed);
......@@ -124,57 +113,49 @@ protected:
cev += residual; // remove for default PLUS
}
protected:
// Check if something is a terminal
bool checkTerminals(float aev, MEDDLY::node_handle a, float bev,
MEDDLY::node_handle b, float &cev,
MEDDLY::node_handle &c)
{
if (a == -1 && b == -1)
{
MEDDLY::node_handle &c) {
if (a == -1 && b == -1) {
c = -1;
cev = aev + bev;
return true;
}
// Case where one (or both) edge is infinity
if (aev == INFTY || bev == INFTY)
{
if (aev == INFTY || bev == INFTY) {
c = -1;
cev = INFTY;
return true;
}
if (0 == a || 0 == b)
{
if (0 == a || 0 == b) {
std::cout << "ERROR => Zero edge pointer in intersectionmax" << std::endl;
return true;
}
return false;
}
MEDDLY::compute_table::search_key *
findResult(float aev, MEDDLY::node_handle a, float bev, MEDDLY::node_handle b,
float &cev, MEDDLY::node_handle &c)
{
MEDDLY::compute_table::search_key *findResult(
float aev, MEDDLY::node_handle a, float bev, MEDDLY::node_handle b,
float &cev, MEDDLY::node_handle &c) {
MEDDLY::compute_table::search_key *CTsrch = useCTkey();
MEDDLY_DCASSERT(CTsrch);
CTsrch->reset();
if (can_commute && a > b)
{
if (can_commute && a > b) {
CTsrch->write(bev);
CTsrch->writeNH(b);
CTsrch->write(aev);
CTsrch->writeNH(a);
}
else
{
} else {
CTsrch->write(aev);
CTsrch->writeNH(a);
CTsrch->write(bev);
CTsrch->writeNH(b);
}
MEDDLY::compute_table::search_result &cacheFind = CT->find(CTsrch);
if (!cacheFind)
return CTsrch;
if (!cacheFind) return CTsrch;
cacheFind.read(cev);
c = resF->linkNode(cacheFind.readNH());
doneCTkey(CTsrch);
......@@ -182,8 +163,7 @@ protected:
}
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);
arg2F->cacheNode(b);
MEDDLY::compute_table::entry_builder &entry = CT->startNewEntry(Key);
......@@ -193,20 +173,17 @@ protected:
}
};
class USER_OPS::Plus_Opname : public MEDDLY::binary_opname
{
public:
class USER_OPS::Plus_Opname : public MEDDLY::binary_opname {
public:
Plus_Opname() : binary_opname("EVPLUS") {}
MEDDLY::binary_operation *buildOperation(MEDDLY::expert_forest *arg1,
MEDDLY::expert_forest *arg2,
MEDDLY::expert_forest *res) const
{
MEDDLY::expert_forest *res) const {
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();
}
......@@ -7,12 +7,11 @@
#include <meddly.h>
#include <meddly_expert.h>
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_
// Copyright 05.07.2018, University of Freiburg,
// Author: David Speck <speckd>.
#include "pow.h"
#include <meddly.h>
#include <meddly_expert.h>
#include <limits>
#include <cmath>
#include "pow.h"
#include <limits>
#include "userOperations.h"
const MEDDLY::unary_opname *USER_OPS::POW;
namespace USER_OPS
{
namespace USER_OPS {
class Pow;
class Pow_Opname;
} // 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)
{
}
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)
{
this->exp = exp;
}
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]);
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]);
}
void showEntry(MEDDLY::output &strm, const MEDDLY::node_handle* /*data*/) const
{
void showEntry(MEDDLY::output &strm,
const MEDDLY::node_handle * /*data*/) const {
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;
float av, ev;
a.getEdgeValue(av);
......@@ -55,12 +45,13 @@ public:
b.set(result, ev);
}
protected:
protected:
float exp;
MEDDLY::compute_table::search_key *findResult(float aev, MEDDLY::node_handle a, float &cv,
MEDDLY::node_handle &c)
{
MEDDLY::compute_table::search_key *findResult(float aev,
MEDDLY::node_handle a,
float &cv,
MEDDLY::node_handle &c) {
MEDDLY::compute_table::search_key *CTsrch = useCTkey();
MEDDLY_DCASSERT(CTsrch);
CTsrch->reset();
......@@ -68,8 +59,7 @@ protected:
CTsrch->write(aev);
CTsrch->writeNH(a);
MEDDLY::compute_table::search_result &cacheFind = CT->find(CTsrch);
if (!cacheFind)
return CTsrch;
if (!cacheFind) return CTsrch;
cacheFind.read(cv);
c = resF->linkNode(cacheFind.readNH());
doneCTkey(CTsrch);
......@@ -77,8 +67,7 @@ protected:
}
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);
MEDDLY::compute_table::entry_builder &entry = CT->startNewEntry(Key);
entry.writeResult(cv);
......@@ -86,18 +75,16 @@ protected:
CT->addEntry();
}
void compute(float av, MEDDLY::node_handle ap, float &rv, MEDDLY::node_handle &rp)
{
if (argF->isTerminalNode(ap))
{
void compute(float av, MEDDLY::node_handle ap, float &rv,
MEDDLY::node_handle &rp) {
if (argF->isTerminalNode(ap)) {
rv = std::pow(av, exp);
rp = ap;
return;
}
// If we already visited the node we stop here
MEDDLY::compute_table::search_key *Key = findResult(av, ap, rv, rp);
if (0 == Key)
{
if (0 == Key) {
return;
}
......@@ -105,18 +92,17 @@ protected:
int resultLevel = argF->getNodeLevel(ap);
const int resultSize = resF->getLevelSize(resultLevel);
MEDDLY::unpacked_node *A = MEDDLY::unpacked_node::newFromNode(argF, ap,
true);
MEDDLY::unpacked_node *A =
MEDDLY::unpacked_node::newFromNode(argF, ap, true);
// Initialize result
MEDDLY::unpacked_node *nb = MEDDLY::unpacked_node::newFull(resF,
resultLevel, resultSize);
MEDDLY::unpacked_node *nb =
MEDDLY::unpacked_node::newFull(resF, resultLevel, resultSize);
// Recursive call
float ev;
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);
nb->d_ref(i) = ep;
nb->setEdge(i, ev);
......@@ -134,30 +120,21 @@ protected:
}
};
class USER_OPS::Pow_Opname : public MEDDLY::unary_opname
{
public:
Pow_Opname() : unary_opname("ParitalComplement")
{
}
class USER_OPS::Pow_Opname : public MEDDLY::unary_opname {
public:
Pow_Opname() : unary_opname("ParitalComplement") {}
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);
}
};
void USER_OPS::initializePow()
{
USER_OPS::POW = new USER_OPS::Pow_Opname;
}
void USER_OPS::initializePow() { USER_OPS::POW = new USER_OPS::Pow_Opname; }
void USER_OPS::setPowExp(const MEDDLY::dd_edge &arg, const MEDDLY::dd_edge &res,
float exp)
{
Pow *powOP = reinterpret_cast<Pow *>(MEDDLY::getOperation(
POW, arg, res));
float exp) {
Pow *powOP = reinterpret_cast<Pow *>(MEDDLY::getOperation(POW, arg, res));
powOP->setExp(exp);
powOP = nullptr;
}
......@@ -4,8 +4,10 @@
#ifndef POW_H_
#define POW_H_
namespace USER_OPS
{
#include <meddly.h>
#include <meddly_expert.h>
namespace USER_OPS {
extern const MEDDLY::unary_opname *POW;
void initializePow();
void setPowExp(const MEDDLY::dd_edge &arg, const MEDDLY::dd_edge &res,
......
......@@ -2,12 +2,16 @@
// Author: David Speck <speckd>
#include "userOperations.h"
#include <fstream>
#include <iomanip>
#include <limits>
#include <set>
#include <sstream>
#include <stack>
const float INFTY = std::numeric_limits<float>::infinity();
void USER_OPS::initializeUserOperations()
{
void USER_OPS::initializeUserOperations() {
USER_OPS::initializePlus();
USER_OPS::initializeMinus();
USER_OPS::initializeMultiply();
......@@ -23,4 +27,106 @@ void USER_OPS::initializeUserOperations()
USER_OPS::initializePow();
USER_OPS::initializeRestrict();
USER_OPS::initializeSwapVar();
USER_OPS::initializePotHeuristic();
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);
edges += "\"W0\" [label = \"" + to_string_with_precision(incoming_weight) +
"\", shape= \"box\"];\n";
edges += "\"F0\" -> \"W0\" [dir = none];\n";
edges += "\"W0\" -> \"" + std::to_string(edge.getNode()) + "\";\n";
while (!node_stack.empty()) {
// Get level information
MEDDLY::node_handle node = node_stack.top();
node_stack.pop();
int level = exp_forest->getNodeLevel(node);
if (level == 0 || closed_nodes.find(node) != closed_nodes.end()) {
continue;
}
if (levels_to_output.find(level) == levels_to_output.end()) {
levels_to_output[level] =
"{ rank = same; \" " +
std::string(f->getDomain()->getVar(level)->getName()) + " \";\n";
}
levels_to_output[level] += "\"" + std::to_string(node) + "\";";
const int domain = exp_forest->getLevelSize(level);
MEDDLY::unpacked_node *A =
MEDDLY::unpacked_node::newFromNode(exp_forest, node, true);
for (int i = 0; i < domain; i++) {
std::string connection_name = std::to_string(node) + "-" +
std::to_string(i) + "-" +
std::to_string(A->d(i));
edges += "\"" + connection_name + "\" [label = \"" +
to_string_with_precision(A->ef(i)) + "\", shape= \"box\"];\n";
edges +=
"\"" + std::to_string(node) + "\" -> \"" + connection_name + "\"";
// std::to_string(A->ef(i))
edges += " [ label=\"" + std::to_string(i) + "\", dir = none]";
edges += ";\n";
edges +=
"\"" + connection_name + "\" -> \"" + std::to_string(A->d(i)) + "\"";
edges += ";\n";
node_stack.push(A->d(i));
}
closed_nodes.insert(node);
MEDDLY::unpacked_node::recycle(A);
}
std::ofstream out_file;
out_file.open(file_name);
out_file << "digraph \"DD\" {" << std::endl;
out_file << "size = \"7.5,10\"" << std::endl;
out_file << "center = true;" << std::endl;
out_file << "{ node [shape = plaintext];" << std::endl;
out_file << " edge [style = invis];" << std::endl;
out_file << " \"CONST NODES\" [style = invis];" << std::endl;
std::string level_out = "";
for (auto &entry : levels_to_output) {
level_out = " \" " +
std::string(f->getDomain()->getVar(entry.first)->getName()) +
" \" ->" + level_out;
}
out_file << level_out;
out_file << "\"CONST NODES\";" << std::endl;
out_file << "}" << std::endl;
out_file << "{ rank = same; node [shape = box]; edge [style = invis];"
<< std::endl;
out_file << "\"F0\";" << std::endl;
out_file << "}\n" << std::endl;
for (auto &pair : levels_to_output) {
pair.second += "}\n";
out_file << pair.second << std::endl;
}
out_file << "{ rank = same; \"CONST NODES\";" << std::endl;
out_file << "\"-1\"" << std::endl;
out_file << "}\n" << std::endl;
out_file << edges << std::endl;
out_file << "\"-1\" [label = \"T\"];\n" << std::endl;
out_file << "\"F0\" [label = \"\", shape = none];\n" << std::endl;
out_file << "}" << std::endl;
out_file.close();
}
......@@ -6,27 +6,29 @@
#include <meddly.h>
#include <meddly_expert.h>
#include "evplus.h"
#include "minus.h"
#include "multiply.h"
#include "copy.h"
#include "divide.h"
#include "intersectionmax.h"
#include "unionmin.h"
#include "greaterThan.h"
#include "equals.h"
#include "evplus.h"
#include "greaterEquals.h"
#include "lessThan.h"
#include "greaterThan.h"
#include "intersectionmax.h"
#include "lessEquals.h"
#include "equals.h"
#include "pow.h"
#include "lessThan.h"
#include "minus.h"
#include "multiply.h"
#include "partialcomplement.h"
#include "pot_heuristic.h"
#include "pow.h"
#include "restrict.h"
#include "swapVar.h"
#include "unionmin.h"
extern const float INFTY;
namespace USER_OPS
{
namespace USER_OPS {
void initializeUserOperations();
}
void to_dot(const MEDDLY::dd_edge &edge, std::string file_name);
} // namespace USER_OPS
#endif // USEROPERATIONS_H_
......@@ -167,7 +167,17 @@ forests/evmdd_plusreal.lo: forests/evmdd_plusreal.cc \
forests/../meddly_expert.h /usr/include/c++/7/unordered_map \
/usr/include/c++/7/bits/hashtable.h \
/usr/include/c++/7/bits/hashtable_policy.h \
/usr/include/c++/7/bits/unordered_map.h forests/../meddly_expert.hh
/usr/include/c++/7/bits/unordered_map.h forests/../meddly_expert.hh \
/usr/include/c++/7/math.h /usr/include/c++/7/cmath /usr/include/math.h \
/usr/include/x86_64-linux-gnu/bits/math-vector.h \
/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h \
/usr/include/x86_64-linux-gnu/bits/flt-eval-method.h \
/usr/include/x86_64-linux-gnu/bits/fp-logb.h \
/usr/include/x86_64-linux-gnu/bits/fp-fast.h \
/usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h \
/usr/include/x86_64-linux-gnu/bits/mathcalls.h \
/usr/include/x86_64-linux-gnu/bits/iscanonical.h \
/usr/include/x86_64-linux-gnu/bits/mathinline.h
/usr/include/stdc-predef.h:
......@@ -604,3 +614,27 @@ forests/../meddly_expert.h:
/usr/include/c++/7/bits/unordered_map.h:
forests/../meddly_expert.hh:
/usr/include/c++/7/math.h:
/usr/include/c++/7/cmath:
/usr/include/math.h:
/usr/include/x86_64-linux-gnu/bits/math-vector.h:
/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h:
/usr/include/x86_64-linux-gnu/bits/flt-eval-method.h:
/usr/include/x86_64-linux-gnu/bits/fp-logb.h:
/usr/include/x86_64-linux-gnu/bits/fp-fast.h:
/usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:
/usr/include/x86_64-linux-gnu/bits/iscanonical.h:
/usr/include/x86_64-linux-gnu/bits/mathinline.h:
......@@ -18,6 +18,7 @@
*/
#include "evmdd_plusreal.h"
#include <math.h>
// ******************************************************************
// * *
......@@ -173,6 +174,10 @@ void MEDDLY::evmdd_plusreal::normalize(unpacked_node &nb, float& ev) const
if (temp != std::numeric_limits<float>::infinity() || allInf) {
//std::cout << temp << std::endl;
temp -= ev;
/*if (isnan(temp)) {
temp = 0;
}*/
nb.setEdge(i, temp);
//MEDDLY::FILE_output out(stdout);
//nb.show(out,true);
......
......@@ -30,5 +30,6 @@ add_executable(runTests meddly_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../operations_extension/pow.cc
${CMAKE_CURRENT_SOURCE_DIR}/../operations_extension/partialcomplement.cc
${CMAKE_CURRENT_SOURCE_DIR}/../operations_extension/restrict.cc
${CMAKE_CURRENT_SOURCE_DIR}/../operations_extension/swapVar.cc)
${CMAKE_CURRENT_SOURCE_DIR}/../operations_extension/swapVar.cc
${CMAKE_CURRENT_SOURCE_DIR}/../operations_extension/pot_heuristic.cc)
target_link_libraries(runTests ${GTEST_LIBRARIES} pthread ${CMAKE_CURRENT_SOURCE_DIR}/../lib/libmeddly.a)