2016-10-08 16:03:14 +02:00
|
|
|
#include <catch.hpp>
|
2016-05-30 15:44:13 +02:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
#include <plasp/pddl/Description.h>
|
2016-06-07 14:00:29 +02:00
|
|
|
#include <plasp/pddl/expressions/And.h>
|
2016-06-03 17:12:39 +02:00
|
|
|
#include <plasp/pddl/expressions/Either.h>
|
2016-06-07 14:00:29 +02:00
|
|
|
#include <plasp/pddl/expressions/Not.h>
|
|
|
|
#include <plasp/pddl/expressions/Predicate.h>
|
2016-06-04 14:46:05 +02:00
|
|
|
#include <plasp/pddl/expressions/PrimitiveType.h>
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-06-08 13:52:36 +02:00
|
|
|
using namespace plasp::pddl;
|
|
|
|
|
2016-05-30 15:44:13 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] The Blocks World domain is parsed correctly", "[PDDL parser]")
|
2016-05-30 15:44:13 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
const auto description = Description::fromFile("data/blocksworld-domain.pddl", context);
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE_NOTHROW(description.domain());
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &domain = description.domain();
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// Name
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(domain.name() == "blocks");
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// Requirements
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.requirements().size() == 2u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(domain.requirements()[0].type() == Requirement::Type::STRIPS);
|
|
|
|
CHECK(domain.requirements()[1].type() == Requirement::Type::Typing);
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// Types
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.types().size() == 1u);
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &block = *domain.types()[0];
|
2016-05-30 15:44:13 +02:00
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(block.name() == "block");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(block.parentTypes().size() == 0u);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
// Predicates
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.predicates().size() == 5u);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &on = *domain.predicates()[0];
|
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(on.name() == "on");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(on.arguments().size() == 2u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(on.arguments()[0]->name() == "x");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(&onArgument0Type == &block);
|
|
|
|
CHECK(on.arguments()[1]->name() == "y");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(&onArgument1Type == &block);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &handempty = *domain.predicates()[3];
|
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(handempty.name() == "handempty");
|
|
|
|
CHECK(handempty.arguments().empty());
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
// Actions
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.actions().size() == 4u);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &pickUp = *domain.actions()[0];
|
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUp.name() == "pick-up");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(pickUp.parameters().size() == 1u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUp.parameters()[0]->name() == "x");
|
|
|
|
CHECK(pickUp.parameters()[0]->type() == &block);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
2016-06-12 23:51:45 +02:00
|
|
|
const auto &pickUpPre = dynamic_cast<const expressions::And &>(*pickUp.precondition());
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(pickUpPre.arguments().size() == 3u);
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &pickUpPre0 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUpPre0.name() == "clear");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(pickUpPre0.arguments().size() == 1u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &pickUpPre00 = dynamic_cast<const expressions::Variable &>(*pickUpPre0.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUpPre00.name() == "x");
|
|
|
|
CHECK(pickUpPre00.type() == &block);
|
|
|
|
CHECK(&pickUpPre00 == pickUp.parameters()[0].get());
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &pickUpPre2 = dynamic_cast<const expressions::Predicate &>(*pickUpPre.arguments()[2]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUpPre2.name() == "handempty");
|
|
|
|
CHECK(pickUpPre2.arguments().empty());
|
2016-06-04 14:46:05 +02:00
|
|
|
|
2016-06-12 23:51:45 +02:00
|
|
|
const auto &pickUpEff = dynamic_cast<const expressions::And &>(*pickUp.effect());
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(pickUpEff.arguments().size() == 4u);
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &pickUpEff0 = dynamic_cast<const expressions::Not &>(*pickUpEff.arguments()[0]);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &pickUpEff00 = dynamic_cast<const expressions::Predicate &>(*pickUpEff0.argument());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUpEff00.name() == "ontable");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(pickUpEff00.arguments().size() == 1u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &pickUpEff000 = dynamic_cast<const expressions::Variable &>(*pickUpEff00.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(pickUpEff000.name() == "x");
|
|
|
|
CHECK(pickUpEff000.type() == &block);
|
2016-05-30 20:43:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] A Blocks World problem is parsed correctly", "[PDDL parser]")
|
2016-05-30 20:43:36 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
const auto description = Description::fromFiles({"data/blocksworld-domain.pddl", "data/blocksworld-problem.pddl"}, context);
|
2016-06-08 13:52:36 +02:00
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE_NOTHROW(description.problem());
|
2016-06-08 13:52:36 +02:00
|
|
|
|
|
|
|
const auto &problem = description.problem();
|
|
|
|
|
|
|
|
// Name
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.name() == "blocks-4-0");
|
|
|
|
CHECK(problem.domain().name() == "blocks");
|
2016-06-08 13:52:36 +02:00
|
|
|
|
|
|
|
// Requirements
|
|
|
|
// TODO: compute domain vs. problem requirements correctly and check them
|
|
|
|
|
|
|
|
// Objects
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(problem.objects().size() == 4u);
|
2016-06-08 13:52:36 +02:00
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.objects()[0]->name() == "d");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(problem.objects()[0]->type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.objects()[0]->type()->name() == "block");
|
|
|
|
CHECK(problem.objects()[3]->name() == "c");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(problem.objects()[3]->type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.objects()[3]->type()->name() == "block");
|
2016-06-08 13:52:36 +02:00
|
|
|
|
2016-06-09 18:13:19 +02:00
|
|
|
// Initial State
|
|
|
|
const auto &facts = problem.initialState().facts();
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(facts.size() == 9u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact0.name() == "clear");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact0.arguments().size() == 1u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact00 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact00.name() == "c");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact00.type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact00.type()->name() == "block");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact8 = dynamic_cast<const expressions::Predicate &>(*facts[8].get());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact8.name() == "handempty");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact8.arguments().size() == 0u);
|
2016-06-09 18:13:19 +02:00
|
|
|
|
2016-06-09 23:19:20 +02:00
|
|
|
// Goal
|
|
|
|
const auto &goal = dynamic_cast<const expressions::And &>(problem.goal());
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(goal.arguments().size() == 3u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal0.name() == "on");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(goal0.arguments().size() == 2u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal00.name() == "d");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal01.name() == "c");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal2 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[2]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal2.name() == "on");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(goal2.arguments().size() == 2u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal20 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal20.name() == "b");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal21 = dynamic_cast<const expressions::Constant &>(*goal2.arguments()[1]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal21.name() == "a");
|
2016-06-08 13:52:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2016-06-04 14:46:05 +02:00
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] The Storage domain is parsed correctly", "[PDDL parser]")
|
2016-06-08 13:52:36 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
const auto description = plasp::pddl::Description::fromFile("data/storage-domain.pddl", context);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE_NOTHROW(description.domain());
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &domain = description.domain();
|
|
|
|
|
|
|
|
// Name
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(domain.name() == "storage-propositional");
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
// Requirements
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.requirements().size() == 1u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(domain.requirements()[0].type() == Requirement::Type::Typing);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
// Types
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.types().size() == 10u);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
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();
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(hoistParents.size() == 1u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(std::find(hoistParents.cbegin(), hoistParents.cend(), &object) != hoistParents.cend());
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &areaParents = area.parentTypes();
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(areaParents.size() == 2u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(std::find(areaParents.cbegin(), areaParents.cend(), &object) != areaParents.cend());
|
|
|
|
CHECK(std::find(areaParents.cbegin(), areaParents.cend(), &surface) != areaParents.cend());
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
// Predicates
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.predicates().size() == 8u);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &on = *domain.predicates()[5];
|
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(on.name() == "on");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(on.arguments().size() == 2u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(on.arguments()[0]->name() == "c");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &onArgument0Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[0]->type());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(&onArgument0Type == &crate);
|
|
|
|
CHECK(on.arguments()[1]->name() == "s");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &onArgument1Type = dynamic_cast<const expressions::PrimitiveType &>(*on.arguments()[1]->type());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(&onArgument1Type == &storearea);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &in = *domain.predicates()[1];
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(in.name() == "in");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(in.arguments().size() == 2u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(in.arguments()[0]->name() == "x");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &inArgument0Type = dynamic_cast<const expressions::Either &>(*in.arguments()[0]->type());
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(inArgument0Type.arguments().size() == 2u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &inArgument0Type0 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(&inArgument0Type0 == &storearea);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &inArgument0Type1 = dynamic_cast<const expressions::PrimitiveType &>(*inArgument0Type.arguments()[1]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(&inArgument0Type1 == &crate);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
// Actions
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.actions().size() == 5u);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
|
|
|
const auto &drop = *domain.actions()[1];
|
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(drop.name() == "drop");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(drop.parameters().size() == 5u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(drop.parameters()[3]->name() == "a2");
|
|
|
|
CHECK(drop.parameters()[3]->type() == &area);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
2016-06-12 23:51:45 +02:00
|
|
|
const auto &dropPre = dynamic_cast<const expressions::And &>(*drop.precondition());
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(dropPre.arguments().size() == 5u);
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &dropPre2 = dynamic_cast<const expressions::Predicate &>(*dropPre.arguments()[2]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(dropPre2.name() == "lifting");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(dropPre2.arguments().size() == 2u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &dropPre21 = dynamic_cast<const expressions::Variable &>(*dropPre2.arguments()[1]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(dropPre21.name() == "c");
|
|
|
|
CHECK(dropPre21.type() == &crate);
|
2016-06-08 13:41:17 +02:00
|
|
|
|
2016-06-12 23:51:45 +02:00
|
|
|
const auto &dropEff = dynamic_cast<const expressions::And &>(*drop.effect());
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(dropEff.arguments().size() == 5u);
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &dropEff2 = dynamic_cast<const expressions::Not &>(*dropEff.arguments()[2]);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &dropEff20 = dynamic_cast<const expressions::Predicate &>(*dropEff2.argument());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(dropEff20.name() == "clear");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(dropEff20.arguments().size() == 1u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &dropEff200 = dynamic_cast<const expressions::Variable &>(*dropEff20.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(dropEff200.name() == "a1");
|
|
|
|
CHECK(dropEff200.type() == &storearea);
|
2016-05-30 15:44:13 +02:00
|
|
|
}
|
2016-06-01 16:47:34 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] A Storage problem is parsed correctly", "[PDDL parser]")
|
2016-06-08 13:57:01 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
const auto description = Description::fromFiles({"data/storage-domain.pddl", "data/storage-problem.pddl"}, context);
|
2016-06-08 13:57:01 +02:00
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE_NOTHROW(description.problem());
|
2016-06-08 13:57:01 +02:00
|
|
|
|
|
|
|
const auto &problem = description.problem();
|
|
|
|
|
|
|
|
// Name
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.name() == "storage-1");
|
|
|
|
CHECK(problem.domain().name() == "storage-propositional");
|
2016-06-08 13:57:01 +02:00
|
|
|
|
|
|
|
// Requirements
|
|
|
|
// TODO: compute domain vs. problem requirements correctly and check them
|
|
|
|
|
|
|
|
// Objects
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(problem.objects().size() == 7u);
|
2016-06-08 13:57:01 +02:00
|
|
|
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.objects()[0]->name() == "depot0-1-1");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(problem.objects()[0]->type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.objects()[0]->type()->name() == "storearea");
|
|
|
|
CHECK(problem.objects()[6]->name() == "loadarea");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(problem.objects()[6]->type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(problem.objects()[6]->type()->name() == "transitarea");
|
2016-06-08 13:57:01 +02:00
|
|
|
|
2016-06-09 18:16:51 +02:00
|
|
|
// Initial State
|
|
|
|
const auto &facts = problem.initialState().facts();
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(facts.size() == 10u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact0 = dynamic_cast<const expressions::Predicate &>(*facts[0].get());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact0.name() == "in");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact0.arguments().size() == 2u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact01 = dynamic_cast<const expressions::Constant &>(*fact0.arguments()[1]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact01.name() == "depot0");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact01.type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact01.type()->name() == "depot");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact9 = dynamic_cast<const expressions::Predicate &>(*facts[9].get());
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact9.name() == "available");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact9.arguments().size() == 1u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &fact90 = dynamic_cast<const expressions::Constant &>(*fact9.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact90.name() == "hoist0");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(fact90.type() != nullptr);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(fact90.type()->name() == "hoist");
|
2016-06-09 18:16:51 +02:00
|
|
|
|
2016-06-09 23:21:05 +02:00
|
|
|
// Goal
|
|
|
|
const auto &goal = dynamic_cast<const expressions::And &>(problem.goal());
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(goal.arguments().size() == 1u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal0 = dynamic_cast<const expressions::Predicate &>(*goal.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal0.name() == "in");
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(goal0.arguments().size() == 2u);
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal00 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[0]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal00.name() == "crate0");
|
2016-06-13 01:38:56 +02:00
|
|
|
const auto &goal01 = dynamic_cast<const expressions::Constant &>(*goal0.arguments()[1]);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(goal01.name() == "depot0");
|
2016-06-08 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] Constants are parsed correctly", "[PDDL parser]")
|
2016-06-01 16:47:34 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
const auto description = Description::fromFile("data/woodworking-domain.pddl", context);
|
2016-06-01 16:47:34 +02:00
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE_NOTHROW(description.domain());
|
2016-06-01 16:47:34 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
const auto &domain = description.domain();
|
2016-06-01 16:47:34 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// Name
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(domain.name() == "woodworking");
|
2016-06-01 16:47:34 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// Types
|
|
|
|
const auto &acolour = *domain.types()[0];
|
|
|
|
const auto &surface = *domain.types()[4];
|
|
|
|
const auto &treatmentstatus = *domain.types()[5];
|
2016-06-01 16:47:34 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// Constants
|
2016-10-08 16:03:14 +02:00
|
|
|
REQUIRE(domain.constants().size() == 8u);
|
2016-11-29 06:03:05 +01:00
|
|
|
CHECK(domain.constants()[0]->type() == &surface);
|
|
|
|
CHECK(domain.constants()[2]->type() == &surface);
|
|
|
|
CHECK(domain.constants()[3]->type() == &treatmentstatus);
|
|
|
|
CHECK(domain.constants()[6]->type() == &treatmentstatus);
|
|
|
|
CHECK(domain.constants()[7]->type() == &acolour);
|
2016-06-07 14:07:17 +02:00
|
|
|
|
2016-06-08 13:41:17 +02:00
|
|
|
// TODO: add test with constants in predicates
|
2016-06-01 16:47:34 +02:00
|
|
|
}
|
2016-06-02 23:41:40 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] White spaces are ignored", "[PDDL parser]")
|
2016-06-02 23:41:40 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
CHECK_NOTHROW(Description::fromFile("data/white-space-test.pddl", context));
|
2016-06-02 23:41:40 +02:00
|
|
|
}
|
2016-06-08 13:52:36 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected", "[PDDL parser]")
|
2016-06-08 13:52:36 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS_AS(Description::fromFile("data/blocksworld-problem.pddl", context), ConsistencyException);
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), plasp::input::ParserException);
|
|
|
|
}
|
2016-06-08 13:52:36 +02:00
|
|
|
}
|
2016-06-09 15:19:01 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] Common PDDL syntax errors are detected", "[PDDL parser]")
|
2016-06-09 15:19:01 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_NOTHROW(Description::fromFile("data/pddl-syntax/domain-valid.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-1.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-2.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expressions-3.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-1.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-2.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-expression-name-3.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-1.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-2.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-3.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-4.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-5.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-6.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-7.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-parentheses-8.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-1.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-2.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-3.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-4.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-5.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-6.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-section-name-7.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-1.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-2.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-3.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-types-4.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-1.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-2.pddl", context));
|
|
|
|
}
|
|
|
|
SECTION("")
|
|
|
|
{
|
|
|
|
CHECK_THROWS(Description::fromFile("data/pddl-syntax/domain-variables-3.pddl", context));
|
|
|
|
}
|
2016-06-09 15:19:01 +02:00
|
|
|
}
|
2016-06-09 18:32:55 +02:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-10-08 16:03:14 +02:00
|
|
|
TEST_CASE("[PDDL parser] Former issues are fixed", "[PDDL parser]")
|
2016-06-09 18:32:55 +02:00
|
|
|
{
|
2016-11-29 06:03:05 +01:00
|
|
|
plasp::output::Logger logger;
|
|
|
|
Context context(Parser(), logger);
|
|
|
|
|
|
|
|
SECTION("white space issues with constants and parsing unsupported sections")
|
|
|
|
{
|
|
|
|
CHECK_NOTHROW(Description::fromFile("data/issues/issue-1.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("white space issues with empty n-ary predicates")
|
|
|
|
{
|
|
|
|
CHECK_NOTHROW(Description::fromFile("data/issues/issue-2.pddl", context));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("comments are correctly ignored")
|
|
|
|
{
|
|
|
|
CHECK_NOTHROW(Description::fromFile("data/issues/issue-3.pddl", context));
|
|
|
|
}
|
2016-06-09 18:32:55 +02:00
|
|
|
}
|