Implemented predicate parsing and refactored context storage.

This commit is contained in:
2016-06-01 14:11:13 +02:00
parent 44482ae438
commit 3c97ced486
14 changed files with 265 additions and 110 deletions

View File

@@ -48,22 +48,40 @@ TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
const auto &domain = description.domain();
// Name
ASSERT_EQ(domain.name(), "BLOCKS");
// Requirements
ASSERT_EQ(domain.requirements().size(), 2u);
ASSERT_EQ(domain.requirements()[0].type(), plasp::pddl::Requirement::Type::STRIPS);
ASSERT_EQ(domain.requirements()[1].type(), plasp::pddl::Requirement::Type::Typing);
// Types
ASSERT_EQ(domain.types().size(), 1u);
const auto block = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("block")->second);
const auto &block = *domain.types()[0];
ASSERT_EQ(block.name(), "block");
ASSERT_EQ(block.parentTypes().size(), 0u);
// Predicates
ASSERT_EQ(domain.predicates().size(), 5u);
const auto on = domain.predicates().find({"on", 2});
const auto &on = *domain.predicates()[0];
ASSERT_EQ(on.name(), "on");
ASSERT_EQ(on.arguments().size(), 2u);
ASSERT_EQ(on.arguments()[0].name(), "x");
const auto onArgument0Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[0].type());
ASSERT_EQ(onArgument0Type, &block);
ASSERT_EQ(on.arguments()[1].name(), "y");
const auto onArgument1Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[1].type());
ASSERT_EQ(onArgument1Type, &block);
const auto &handempty = *domain.predicates()[3];
ASSERT_EQ(handempty.name(), "handempty");
ASSERT_TRUE(handempty.arguments().empty());
}
catch (const std::exception &e)
{
@@ -83,16 +101,22 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
const auto &domain = description.domain();
// Name
ASSERT_EQ(domain.name(), "Storage-Propositional");
// Requirements
ASSERT_EQ(domain.requirements().size(), 1u);
ASSERT_EQ(domain.requirements()[0].type(), plasp::pddl::Requirement::Type::Typing);
const auto area = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("area")->second);
const auto hoist = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("hoist")->second);
const auto object = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("object")->second);
const auto storearea = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("storearea")->second);
const auto surface = boost::get<plasp::pddl::TypePrimitive>(domain.types().find("surface")->second);
// Types
ASSERT_EQ(domain.types().size(), 10u);
const auto &hoist = *domain.types()[0];
const auto &surface = *domain.types()[1];
const auto &area = *domain.types()[3];
const auto &object = *domain.types()[4];
const auto &storearea = *domain.types()[7];
const auto &crate = *domain.types()[9];
const auto &hoistParents = hoist.parentTypes();
ASSERT_EQ(hoistParents.size(), 1u);
@@ -102,6 +126,29 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
ASSERT_EQ(areaParents.size(), 2u);
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
// Predicates
ASSERT_EQ(domain.predicates().size(), 8u);
const auto &on = *domain.predicates()[5];
ASSERT_EQ(on.name(), "on");
ASSERT_EQ(on.arguments().size(), 2u);
ASSERT_EQ(on.arguments()[0].name(), "c");
const auto onArgument0Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[0].type());
ASSERT_EQ(onArgument0Type, &crate);
ASSERT_EQ(on.arguments()[1].name(), "s");
const auto onArgument1Type = boost::get<const plasp::pddl::PrimitiveType *>(on.arguments()[1].type());
ASSERT_EQ(onArgument1Type, &storearea);
const auto &in = *domain.predicates()[1];
ASSERT_EQ(in.name(), "in");
ASSERT_EQ(in.arguments().size(), 2u);
ASSERT_EQ(in.arguments()[0].name(), "x");
const auto inArgument0Type = boost::get<const plasp::pddl::EitherType *>(in.arguments()[0].type());
ASSERT_EQ(inArgument0Type->allowedTypes().size(), 2u);
ASSERT_EQ(inArgument0Type->allowedTypes()[0], &storearea);
ASSERT_EQ(inArgument0Type->allowedTypes()[1], &crate);
}
catch (const std::exception &e)
{

View File

@@ -1,32 +1,32 @@
(define (domain Storage-Propositional)
(:requirements :typing)
(:types hoist surface place area - object
container depot - place
storearea transitarea - area
area crate - surface)
container depot - place
storearea transitarea - area
area crate - surface)
(:predicates (clear ?s - storearea)
(in ?x - (either storearea crate) ?p - place)
(available ?h - hoist)
(lifting ?h - hoist ?c - crate)
(at ?h - hoist ?a - area)
(on ?c - crate ?s - storearea)
(connected ?a1 ?a2 - area)
(in ?x - (either storearea crate) ?p - place)
(available ?h - hoist)
(lifting ?h - hoist ?c - crate)
(at ?h - hoist ?a - area)
(on ?c - crate ?s - storearea)
(connected ?a1 ?a2 - area)
(compatible ?c1 ?c2 - crate))
(:action lift
:parameters (?h - hoist ?c - crate ?a1 - storearea ?a2 - area ?p - place)
:precondition (and (connected ?a1 ?a2) (at ?h ?a2) (available ?h)
(on ?c ?a1) (in ?a1 ?p))
(on ?c ?a1) (in ?a1 ?p))
:effect (and (not (on ?c ?a1)) (clear ?a1)
(not (available ?h)) (lifting ?h ?c) (not (in ?c ?p))))
(not (available ?h)) (lifting ?h ?c) (not (in ?c ?p))))
(:action drop
:parameters (?h - hoist ?c - crate ?a1 - storearea ?a2 - area ?p - place)
:precondition (and (connected ?a1 ?a2) (at ?h ?a2) (lifting ?h ?c)
(clear ?a1) (in ?a1 ?p))
(clear ?a1) (in ?a1 ?p))
:effect (and (not (lifting ?h ?c)) (available ?h)
(not (clear ?a1)) (on ?c ?a1) (in ?c ?p)))
(not (clear ?a1)) (on ?c ?a1) (in ?c ?p)))
(:action move
:parameters (?h - hoist ?from ?to - storearea)