Started implementing PDDL type parsing.

This commit is contained in:
2016-05-30 20:43:36 +02:00
parent 1c4c035acc
commit a989f5f86e
8 changed files with 362 additions and 13 deletions

View File

@@ -13,7 +13,8 @@ class PDDLParserTests : public ::testing::Test
{
protected:
PDDLParserTests()
: m_blocksworldDomainFile(readFile("data/blocksworld-domain.pddl"))
: m_blocksworldDomainFile(readFile("data/blocksworld-domain.pddl")),
m_storageDomainFile(readFile("data/storage-domain.pddl"))
{
}
@@ -32,11 +33,12 @@ class PDDLParserTests : public ::testing::Test
}
std::stringstream m_blocksworldDomainFile;
std::stringstream m_storageDomainFile;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_F(PDDLParserTests, ParseValidPDDLFile)
TEST_F(PDDLParserTests, ParseBlocksWorldDomain)
{
try
{
@@ -46,9 +48,62 @@ TEST_F(PDDLParserTests, ParseValidPDDLFile)
const auto &domain = description.domain();
ASSERT_EQ(domain.name(), "BLOCKS");
ASSERT_EQ(domain.requirements().size(), 2u);
ASSERT_EQ(domain.requirements()[0], plasp::pddl::Requirement::Type::STRIPS);
ASSERT_EQ(domain.requirements()[1], plasp::pddl::Requirement::Type::Typing);
ASSERT_EQ(domain.types().size(), 1u);
const auto blockType = domain.types().find("block");
ASSERT_NE(blockType, domain.types().cend());
ASSERT_EQ(blockType->second.name(), "block");
ASSERT_EQ(blockType->second.parentTypes().size(), 0u);
}
catch (const std::exception &e)
{
FAIL() << e.what();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_F(PDDLParserTests, ParseStorageDomain)
{
try
{
const auto description = plasp::pddl::Description::fromStream(m_storageDomainFile);
ASSERT_NO_THROW(description.domain());
const auto &domain = description.domain();
ASSERT_EQ(domain.name(), "Storage-Propositional");
ASSERT_EQ(domain.requirements().size(), 1u);
ASSERT_EQ(domain.requirements()[0], plasp::pddl::Requirement::Type::Typing);
const auto area = domain.types().find("area");
ASSERT_NE(area, domain.types().cend());
const auto hoist = domain.types().find("hoist");
ASSERT_NE(hoist, domain.types().cend());
const auto object = domain.types().find("object");
ASSERT_NE(object, domain.types().cend());
const auto storearea = domain.types().find("storearea");
ASSERT_NE(storearea, domain.types().cend());
const auto surface= domain.types().find("surface");
ASSERT_NE(surface, domain.types().cend());
const auto &hoistParents = hoist->second.parentTypes();
ASSERT_EQ(hoistParents.size(), 1u);
ASSERT_TRUE(std::find(hoistParents.cbegin(), hoistParents.cend(), &object->second) != hoistParents.cend());
const auto &areaParents = area->second.parentTypes();
ASSERT_EQ(areaParents.size(), 2u);
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &object->second) != areaParents.cend());
ASSERT_TRUE(std::find(areaParents.cbegin(), areaParents.cend(), &surface->second) != areaParents.cend());
}
catch (const std::exception &e)
{

View File

@@ -0,0 +1,46 @@
(define (domain Storage-Propositional)
(:requirements :typing)
(:types hoist surface place area - object
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)
(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))
:effect (and (not (on ?c ?a1)) (clear ?a1)
(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))
:effect (and (not (lifting ?h ?c)) (available ?h)
(not (clear ?a1)) (on ?c ?a1) (in ?c ?p)))
(:action move
:parameters (?h - hoist ?from ?to - storearea)
:precondition (and (at ?h ?from) (clear ?to) (connected ?from ?to))
:effect (and (not (at ?h ?from)) (at ?h ?to) (not (clear ?to)) (clear ?from)))
(:action go-out
:parameters (?h - hoist ?from - storearea ?to - transitarea)
:precondition (and (at ?h ?from) (connected ?from ?to))
:effect (and (not (at ?h ?from)) (at ?h ?to) (clear ?from)))
(:action go-in
:parameters (?h - hoist ?from - transitarea ?to - storearea)
:precondition (and (at ?h ?from) (connected ?from ?to) (clear ?to))
:effect (and (not (at ?h ?from)) (at ?h ?to) (not (clear ?to))))
)