Implemented parsing of PDDL constants.

This commit is contained in:
2016-06-01 16:47:34 +02:00
parent 3c97ced486
commit 25cf7c8ae8
9 changed files with 509 additions and 6 deletions

View File

@@ -14,7 +14,8 @@ class PDDLParserTests : public ::testing::Test
protected:
PDDLParserTests()
: m_blocksworldDomainFile(readFile("data/blocksworld-domain.pddl")),
m_storageDomainFile(readFile("data/storage-domain.pddl"))
m_storageDomainFile(readFile("data/storage-domain.pddl")),
m_woodworkingDomainFile(readFile("data/woodworking-domain.pddl"))
{
}
@@ -34,6 +35,7 @@ class PDDLParserTests : public ::testing::Test
std::stringstream m_blocksworldDomainFile;
std::stringstream m_storageDomainFile;
std::stringstream m_woodworkingDomainFile;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -155,3 +157,37 @@ TEST_F(PDDLParserTests, ParseStorageDomain)
FAIL() << e.what();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_F(PDDLParserTests, ParseConstants)
{
try
{
const auto description = plasp::pddl::Description::fromStream(m_woodworkingDomainFile);
ASSERT_NO_THROW(description.domain());
const auto &domain = description.domain();
// Name
ASSERT_EQ(domain.name(), "woodworking");
// Types
const auto &acolour = *domain.types()[0];
const auto &surface = *domain.types()[4];
const auto &treatmentstatus = *domain.types()[5];
// Constants
ASSERT_EQ(domain.constants().size(), 8u);
ASSERT_EQ(domain.constants()[0]->type(), &surface);
ASSERT_EQ(domain.constants()[2]->type(), &surface);
ASSERT_EQ(domain.constants()[3]->type(), &treatmentstatus);
ASSERT_EQ(domain.constants()[6]->type(), &treatmentstatus);
ASSERT_EQ(domain.constants()[7]->type(), &acolour);
}
catch (const std::exception &e)
{
FAIL() << e.what();
}
}

View File

@@ -0,0 +1,215 @@
(define (domain woodworking)
(:requirements :typing :durative-actions :numeric-fluents)
(:types
acolour awood woodobj machine
surface treatmentstatus - object
highspeed-saw glazer grinder immersion-varnisher
planer saw spray-varnisher - machine
board part - woodobj)
(:constants
verysmooth smooth rough - surface
varnished glazed untreated colourfragments - treatmentstatus
natural - acolour)
(:predicates
(idle ?machine - machine)
(unused ?obj - part)
(available ?obj - woodobj)
(surface-condition ?obj - woodobj ?surface - surface)
(treatment ?obj - part ?treatment - treatmentstatus)
(colour ?obj - part ?colour - acolour)
(wood ?obj - woodobj ?wood - awood)
(in-highspeed-saw ?b - board ?m - highspeed-saw)
(empty ?m - highspeed-saw)
(has-colour ?machine - machine ?colour - acolour)
(grind-treatment-change ?old ?new - treatmentstatus)
(is-smooth ?surface - surface))
(:functions
(board-size ?board - board)
(goal-size ?obj - part))
(:durative-action do-immersion-varnish
:parameters (?x - part ?m - immersion-varnisher
?newcolour - acolour ?surface - surface)
:duration (= ?duration 10)
:condition (and
(at start (idle ?m))
(at start (available ?x))
(at start (surface-condition ?x ?surface))
(at start (is-smooth ?surface))
(at start (has-colour ?m ?newcolour))
(at start (treatment ?x untreated)))
:effect (and
(at start (not (idle ?m)))
(at start (not (available ?x)))
(at start (not (treatment ?x untreated)))
(at start (not (colour ?x natural)))
(at end (idle ?m))
(at end (available ?x))
(at end (treatment ?x varnished))
(at end (colour ?x ?newcolour))))
(:durative-action do-spray-varnish
:parameters (?x - part ?m - spray-varnisher
?newcolour - acolour ?surface - surface)
:duration (= ?duration (goal-size ?x))
:condition (and
(at start (idle ?m))
(at start (available ?x))
(at start (surface-condition ?x ?surface))
(at start (is-smooth ?surface))
(at start (has-colour ?m ?newcolour))
(at start (treatment ?x untreated)))
:effect (and
(at start (not (idle ?m)))
(at start (not (available ?x)))
(at start (not (treatment ?x untreated)))
(at start (not (colour ?x natural)))
(at end (idle ?m))
(at end (available ?x))
(at end (treatment ?x varnished))
(at end (colour ?x ?newcolour))))
(:durative-action do-glaze
:parameters (?x - part ?m - glazer
?newcolour - acolour)
:duration (= ?duration (+ (goal-size ?x) 5))
:condition (and
(at start (idle ?m))
(at start (available ?x))
(at start (has-colour ?m ?newcolour))
(at start (treatment ?x untreated)))
:effect (and
(at start (not (idle ?m)))
(at start (not (available ?x)))
(at start (not (treatment ?x untreated)))
(at start (not (colour ?x natural)))
(at end (idle ?m))
(at end (available ?x))
(at end (treatment ?x glazed))
(at end (colour ?x ?newcolour))))
(:durative-action do-grind
:parameters (?x - part ?m - grinder ?oldsurface - surface
?oldcolour - acolour
?oldtreatment ?newtreatment - treatmentstatus)
:duration (= ?duration (* 3 (goal-size ?x)))
:condition (and
(at start (idle ?m))
(at start (available ?x))
(at start (surface-condition ?x ?oldsurface))
(at start (is-smooth ?oldsurface))
(at start (colour ?x ?oldcolour))
(at start (treatment ?x ?oldtreatment))
(at start (grind-treatment-change ?oldtreatment ?newtreatment)))
:effect (and
(at start (not (idle ?m)))
(at start (not (available ?x)))
(at start (not (surface-condition ?x ?oldsurface)))
(at start (not (treatment ?x ?oldtreatment)))
(at start (not (colour ?x ?oldcolour)))
(at end (idle ?m))
(at end (available ?x))
(at end (surface-condition ?x verysmooth))
(at end (treatment ?x ?newtreatment))
(at end (colour ?x natural))))
(:durative-action do-plane
:parameters (?x - part ?m - planer ?oldsurface - surface
?oldcolour - acolour ?oldtreatment - treatmentstatus)
:duration (= ?duration (* 2 (goal-size ?x)))
:condition (and
(at start (idle ?m))
(at start (available ?x))
(at start (surface-condition ?x ?oldsurface))
(at start (treatment ?x ?oldtreatment))
(at start (colour ?x ?oldcolour)))
:effect (and
(at start (not (idle ?m)))
(at start (not (available ?x)))
(at start (not (surface-condition ?x ?oldsurface)))
(at start (not (treatment ?x ?oldtreatment)))
(at start (not (colour ?x ?oldcolour)))
(at end (idle ?m))
(at end (available ?x))
(at end (surface-condition ?x smooth))
(at end (treatment ?x untreated))
(at end (colour ?x natural))))
(:durative-action load-highspeed-saw
:parameters (?b - board ?m - highspeed-saw)
:duration (= ?duration 30)
:condition (and
(at start (idle ?m))
(at start (empty ?m))
(at start (available ?b)))
:effect (and
(at start (not (idle ?m)))
(at start (not (available ?b)))
(at start (not (empty ?m)))
(at end (idle ?m))
(at end (in-highspeed-saw ?b ?m))))
(:durative-action unload-highspeed-saw
:parameters (?b - board ?m - highspeed-saw)
:duration (= ?duration 10)
:condition (and
(at start (idle ?m))
(at start (in-highspeed-saw ?b ?m)))
:effect (and
(at start (not (idle ?m)))
(at end (available ?b))
(at end (not (in-highspeed-saw ?b ?m)))
(at end (empty ?m))
(at end (idle ?m))))
(:durative-action cut-board
:parameters (?b - board ?p - part ?m - highspeed-saw ?w - awood
?surface - surface)
:duration (= ?duration 10)
:condition (and
(at start (idle ?m))
(at start (unused ?p))
(at start (in-highspeed-saw ?b ?m))
(at start (wood ?b ?w))
(at start (surface-condition ?b ?surface))
(at start (>= (board-size ?b) (goal-size ?p))))
:effect (and
(at start (not (idle ?m)))
(at start (not (unused ?p)))
(at start (decrease (board-size ?b) (goal-size ?p)))
(at end (idle ?m))
(at end (available ?p))
(at end (wood ?p ?w))
(at end (surface-condition ?p ?surface))
(at end (colour ?p natural))
(at end (treatment ?p untreated))))
(:durative-action do-saw
:parameters (?b - board ?p - part ?m - saw ?w - awood
?surface - surface)
:duration (= ?duration 30)
:condition (and
(at start (idle ?m))
(at start (unused ?p))
(at start (available ?b))
(at start (wood ?b ?w))
(at start (surface-condition ?b ?surface))
(at start (>= (board-size ?b) (goal-size ?p))))
:effect (and
(at start (not (idle ?m)))
(at start (not (unused ?p)))
(at start (not (available ?b)))
(at end (decrease (board-size ?b) (goal-size ?p)))
(at end (idle ?m))
(at end (available ?p))
(at end (available ?b))
(at end (wood ?p ?w))
(at end (surface-condition ?p ?surface))
(at end (colour ?p natural))
(at end (treatment ?p untreated))))
)