2016-10-08 16:03:14 +02:00
|
|
|
#include <catch.hpp>
|
2016-09-02 18:27:00 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-06-20 01:53:55 +02:00
|
|
|
/*TEST_CASE("[PDDL normalization] PDDL expressions are correctly reduced", "[PDDL normalization]")
|
2016-09-04 23:30:08 +02:00
|
|
|
{
|
|
|
|
auto n1 = expressions::NotPointer(new expressions::Not);
|
|
|
|
auto n2 = expressions::NotPointer(new expressions::Not);
|
|
|
|
auto a = expressions::AndPointer(new expressions::And);
|
|
|
|
auto o = expressions::OrPointer(new expressions::Or);
|
|
|
|
auto i = expressions::ImplyPointer(new expressions::Imply);
|
|
|
|
|
|
|
|
i->setArgument(0, new expressions::Dummy("a"));
|
|
|
|
i->setArgument(1, new expressions::Dummy("b"));
|
|
|
|
|
|
|
|
o->addArgument(i);
|
|
|
|
o->addArgument(new expressions::Dummy("c"));
|
|
|
|
|
|
|
|
a->addArgument(o);
|
|
|
|
a->addArgument(new expressions::Dummy("d"));
|
|
|
|
|
|
|
|
n2->setArgument(a);
|
|
|
|
n1->setArgument(n2);
|
|
|
|
|
|
|
|
std::stringstream output;
|
2016-09-05 00:06:09 +02:00
|
|
|
n1->reduced()->print(output);
|
2016-09-04 23:30:08 +02:00
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(output.str() == "(not (not (and (or (or (not (a)) (b)) (c)) (d))))");
|
2016-09-04 23:30:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL normalization] PDDL expressions are correctly simplified", "[PDDL normalization]")
|
2016-09-05 00:37:43 +02:00
|
|
|
{
|
|
|
|
auto a1 = expressions::AndPointer(new expressions::And);
|
|
|
|
auto a2 = expressions::AndPointer(new expressions::And);
|
|
|
|
auto o1 = expressions::OrPointer(new expressions::Or);
|
|
|
|
auto o2 = expressions::OrPointer(new expressions::Or);
|
|
|
|
|
|
|
|
a1->addArgument(new expressions::Dummy("a"));
|
|
|
|
a1->addArgument(new expressions::Dummy("b"));
|
|
|
|
a1->addArgument(a2);
|
|
|
|
|
|
|
|
a2->addArgument(new expressions::Dummy("c"));
|
|
|
|
a2->addArgument(new expressions::Dummy("d"));
|
|
|
|
a2->addArgument(o1);
|
|
|
|
|
|
|
|
o1->addArgument(new expressions::Dummy("e"));
|
|
|
|
o1->addArgument(new expressions::Dummy("f"));
|
|
|
|
o1->addArgument(o2);
|
|
|
|
|
|
|
|
o2->addArgument(new expressions::Dummy("g"));
|
|
|
|
o2->addArgument(new expressions::Dummy("h"));
|
|
|
|
|
|
|
|
std::stringstream output;
|
|
|
|
a1->simplified()->print(output);
|
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(output.str() == "(and (a) (b) (c) (d) (or (e) (f) (g) (h)))");
|
2016-09-05 00:37:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL normalization] Implications are correctly replaced", "[PDDL normalization]")
|
2016-09-02 18:45:00 +02:00
|
|
|
{
|
2016-09-04 18:26:02 +02:00
|
|
|
auto i = expressions::ImplyPointer(new expressions::Imply);
|
2016-09-02 18:45:00 +02:00
|
|
|
|
2016-09-04 22:26:17 +02:00
|
|
|
i->setArgument(0, new expressions::Dummy("a"));
|
|
|
|
i->setArgument(1, new expressions::Dummy("b"));
|
2016-09-02 18:45:00 +02:00
|
|
|
|
2016-09-04 22:26:17 +02:00
|
|
|
std::stringstream output;
|
2016-12-07 01:56:06 +01:00
|
|
|
i->reduced()->print(output);
|
2016-09-02 18:45:00 +02:00
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(output.str() == "(or (not (a)) (b))");
|
2016-09-02 18:45:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL normalization] Double negations are correctly replaced", "[PDDL normalization]")
|
2016-09-02 18:27:00 +02:00
|
|
|
{
|
2016-09-04 18:26:02 +02:00
|
|
|
auto n1 = expressions::NotPointer(new expressions::Not);
|
|
|
|
auto n2 = expressions::NotPointer(new expressions::Not);
|
2016-09-02 18:27:00 +02:00
|
|
|
|
2016-09-04 22:26:17 +02:00
|
|
|
n2->setArgument(new expressions::Dummy("a"));
|
|
|
|
n1->setArgument(n2);
|
2016-09-02 18:27:00 +02:00
|
|
|
|
2016-09-04 22:26:17 +02:00
|
|
|
std::stringstream output;
|
2016-12-07 01:56:06 +01:00
|
|
|
n1->simplified()->print(output);
|
2016-09-02 18:27:00 +02:00
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(output.str() == "(a)");
|
2016-09-02 18:27:00 +02:00
|
|
|
}
|
2016-09-04 20:49:22 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
TEST_CASE("[PDDL normalization] Expressions inside double negations are also simplified", "[PDDL normalization]")
|
2016-09-04 22:26:17 +02:00
|
|
|
{
|
|
|
|
auto n1 = expressions::NotPointer(new expressions::Not);
|
|
|
|
auto n2 = expressions::NotPointer(new expressions::Not);
|
2016-12-07 01:56:06 +01:00
|
|
|
auto a1 = expressions::AndPointer(new expressions::And);
|
|
|
|
auto a2 = expressions::AndPointer(new expressions::And);
|
2016-09-04 20:49:22 +02:00
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
a2->addArgument(new expressions::Dummy("d"));
|
|
|
|
a2->addArgument(new expressions::Dummy("e"));
|
2016-09-04 20:49:22 +02:00
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
a1->addArgument(new expressions::Dummy("a"));
|
|
|
|
a1->addArgument(new expressions::Dummy("b"));
|
|
|
|
a1->addArgument(new expressions::Dummy("c"));
|
|
|
|
a1->addArgument(a2);
|
|
|
|
|
|
|
|
n2->setArgument(a1);
|
2016-09-04 22:26:17 +02:00
|
|
|
n1->setArgument(n2);
|
2016-09-04 20:49:22 +02:00
|
|
|
|
2016-09-04 22:26:17 +02:00
|
|
|
std::stringstream output;
|
2016-12-07 01:56:06 +01:00
|
|
|
n1->simplified()->print(output);
|
2016-09-04 20:49:22 +02:00
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
CHECK(output.str() == "(and (a) (b) (c) (d) (e))");
|
2016-09-04 20:49:22 +02:00
|
|
|
}
|
2016-09-06 18:50:23 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-02 01:16:22 +01:00
|
|
|
TEST_CASE("[PDDL normalization] Nested “for all” expressions are correctly simplified", "[PDDL normalization]")
|
2016-09-06 18:50:23 +02:00
|
|
|
{
|
|
|
|
auto v1 = expressions::VariablePointer(new expressions::Variable("x"));
|
|
|
|
auto v2 = expressions::VariablePointer(new expressions::Variable("y"));
|
|
|
|
auto v3 = expressions::VariablePointer(new expressions::Variable("z"));
|
|
|
|
auto v4 = expressions::VariablePointer(new expressions::Variable("u"));
|
|
|
|
auto v5 = expressions::VariablePointer(new expressions::Variable("v"));
|
|
|
|
auto v6 = expressions::VariablePointer(new expressions::Variable("w"));
|
|
|
|
|
|
|
|
auto f1 = expressions::ForAllPointer(new expressions::ForAll);
|
|
|
|
auto f2 = expressions::ForAllPointer(new expressions::ForAll);
|
|
|
|
|
|
|
|
f1->variables() = {v1, v2, v3};
|
|
|
|
f2->variables() = {v4, v5, v6};
|
|
|
|
|
|
|
|
f1->setArgument(f2);
|
2016-09-07 00:34:26 +02:00
|
|
|
f2->setArgument(new expressions::Dummy("a"));
|
2016-09-06 18:50:23 +02:00
|
|
|
|
|
|
|
std::stringstream output;
|
2016-12-07 01:56:06 +01:00
|
|
|
f1->simplified()->print(output);
|
2016-09-06 18:50:23 +02:00
|
|
|
|
2016-12-02 01:16:22 +01:00
|
|
|
CHECK(output.str() == "(forall (?x ?y ?z ?u ?v ?w) (a))");
|
2016-09-06 18:50:23 +02:00
|
|
|
}
|
2016-09-06 18:51:29 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-02 01:16:22 +01:00
|
|
|
TEST_CASE("[PDDL normalization] Nested “exists” expressions are correctly simplified", "[PDDL normalization]")
|
2016-09-06 18:51:29 +02:00
|
|
|
{
|
|
|
|
auto v1 = expressions::VariablePointer(new expressions::Variable("x"));
|
|
|
|
auto v2 = expressions::VariablePointer(new expressions::Variable("y"));
|
|
|
|
auto v3 = expressions::VariablePointer(new expressions::Variable("z"));
|
|
|
|
auto v4 = expressions::VariablePointer(new expressions::Variable("u"));
|
|
|
|
auto v5 = expressions::VariablePointer(new expressions::Variable("v"));
|
|
|
|
auto v6 = expressions::VariablePointer(new expressions::Variable("w"));
|
|
|
|
|
|
|
|
auto e1 = expressions::ExistsPointer(new expressions::Exists);
|
|
|
|
auto e2 = expressions::ExistsPointer(new expressions::Exists);
|
|
|
|
|
|
|
|
e1->variables() = {v1, v2, v3};
|
|
|
|
e2->variables() = {v4, v5, v6};
|
|
|
|
|
|
|
|
e1->setArgument(e2);
|
2016-09-07 00:34:26 +02:00
|
|
|
e2->setArgument(new expressions::Dummy("a"));
|
2016-09-06 18:51:29 +02:00
|
|
|
|
|
|
|
std::stringstream output;
|
2016-12-07 01:56:06 +01:00
|
|
|
e1->simplified()->print(output);
|
2016-09-06 18:51:29 +02:00
|
|
|
|
2016-12-02 01:16:22 +01:00
|
|
|
CHECK(output.str() == "(exists (?x ?y ?z ?u ?v ?w) (a))");
|
2016-09-06 18:51:29 +02:00
|
|
|
}
|
2016-09-07 00:34:26 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
TEST_CASE("[PDDL normalization] “for all” expressions are correctly replaced by “exists” expressions during normalization", "[PDDL normalization]")
|
2016-09-07 00:34:26 +02:00
|
|
|
{
|
|
|
|
auto v1 = expressions::VariablePointer(new expressions::Variable("x"));
|
|
|
|
auto v2 = expressions::VariablePointer(new expressions::Variable("y"));
|
|
|
|
auto v3 = expressions::VariablePointer(new expressions::Variable("z"));
|
2016-12-07 01:56:06 +01:00
|
|
|
auto v4 = expressions::VariablePointer(new expressions::Variable("u"));
|
|
|
|
auto v5 = expressions::VariablePointer(new expressions::Variable("v"));
|
|
|
|
auto v6 = expressions::VariablePointer(new expressions::Variable("w"));
|
2016-09-07 00:34:26 +02:00
|
|
|
|
2016-09-08 02:40:51 +02:00
|
|
|
auto f1 = expressions::ForAllPointer(new expressions::ForAll);
|
2016-12-07 01:56:06 +01:00
|
|
|
auto e = expressions::ExistsPointer(new expressions::Exists);
|
2016-09-08 02:40:51 +02:00
|
|
|
auto f2 = expressions::ForAllPointer(new expressions::ForAll);
|
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
f1->variables() = {v1, v2};
|
|
|
|
e->variables() = {v3, v4};
|
|
|
|
f2->variables() = {v5, v6};
|
2016-09-08 02:40:51 +02:00
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
f1->setArgument(e);
|
|
|
|
e->setArgument(f2);
|
|
|
|
f2->setArgument(new expressions::Dummy("a"));
|
2016-09-08 02:40:51 +02:00
|
|
|
|
2016-09-07 00:34:26 +02:00
|
|
|
std::stringstream output;
|
2016-12-07 01:56:06 +01:00
|
|
|
f1->normalized()->print(output);
|
2016-09-08 03:42:32 +02:00
|
|
|
|
2016-12-07 01:56:06 +01:00
|
|
|
CHECK(output.str() == "(exists (?x ?y) (not (exists (?z ?u ?v ?w) (not (a)))))");
|
2017-06-20 01:53:55 +02:00
|
|
|
}*/
|