diff --git a/include/loki/details/pddl/exceptions.hpp b/include/loki/details/pddl/exceptions.hpp index 2c41668e..3b378a9c 100644 --- a/include/loki/details/pddl/exceptions.hpp +++ b/include/loki/details/pddl/exceptions.hpp @@ -186,6 +186,22 @@ class MultiDefinitionObjectError : public SemanticParserError MultiDefinitionObjectError(const std::string& name, const std::string& error_handler_output); }; +/* Function */ + +class IllformedFunctionDefinitionMissingValue : public SemanticParserError +{ +public: + IllformedFunctionDefinitionMissingValue(const FunctionSkeleton& function, const Function& values, const std::string& error_handler_output); +}; + +class IllformedFunctionDefinitionMultipleValues : public SemanticParserError +{ +public: + IllformedFunctionDefinitionMultipleValues(const FunctionSkeleton& function_skeleton, + const Function& ground_function, + const std::string& error_handler_output); +}; + /* Compatibility errors */ class MismatchedDomainError : public SemanticParserError { diff --git a/src/pddl/exceptions.cpp b/src/pddl/exceptions.cpp index 8f078e4e..13e2a2c3 100644 --- a/src/pddl/exceptions.cpp +++ b/src/pddl/exceptions.cpp @@ -18,7 +18,9 @@ #include "loki/details/pddl/exceptions.hpp" #include "loki/details/pddl/domain.hpp" +#include "loki/details/pddl/function.hpp" #include "loki/details/pddl/function_skeleton.hpp" +#include "loki/details/pddl/object.hpp" #include "loki/details/pddl/predicate.hpp" #include @@ -174,6 +176,24 @@ MultiDefinitionObjectError::MultiDefinitionObjectError(const std::string& name, { } +/* Function*/ +IllformedFunctionDefinitionMissingValue::IllformedFunctionDefinitionMissingValue(const FunctionSkeleton& function_skeleton, + const Function& values, + const std::string& error_handler_output) : + SemanticParserError("The function with name \"" + function_skeleton->str() + "\n misses a value definition in the initial state for arguments \"" + + values->str() + "\".", + error_handler_output) +{ +} + +IllformedFunctionDefinitionMultipleValues::IllformedFunctionDefinitionMultipleValues(const FunctionSkeleton& function_skeleton, + const Function& ground_function, + const std::string& error_handler_output) : + SemanticParserError("The function with name \"" + function_skeleton->str() + "\n has multiple values defined for \"" + ground_function->str() + "\".", + error_handler_output) +{ +} + /* Compatibility errors */ MismatchedDomainError::MismatchedDomainError(const Domain& domain, const std::string& domain_name, const std::string& error_handler_output) : SemanticParserError("Mismatched domain names \"" + domain->get_name() + "!=" + domain_name + ".", error_handler_output) diff --git a/src/pddl/parser.cpp b/src/pddl/parser.cpp index 4f363fbc..65bf64d7 100644 --- a/src/pddl/parser.cpp +++ b/src/pddl/parser.cpp @@ -167,6 +167,7 @@ Problem parse(const ast::Problem& problem_node, Context& context, const Domain& std::visit(UnpackingVisitor(initial_literals, numeric_fluents), initial_element); } } + /* Goal section */ auto goal_condition = std::optional(); if (problem_node.goal.has_value()) diff --git a/src/pddl/parser/initial.cpp b/src/pddl/parser/initial.cpp index 6256524d..1b586275 100644 --- a/src/pddl/parser/initial.cpp +++ b/src/pddl/parser/initial.cpp @@ -27,6 +27,9 @@ namespace loki std::vector> parse(const ast::Initial& initial_node, Context& context) { + // TODO: IllformedFunctionDefinitionMissingValue and IllformedFunctionDefinitionMultipleValues using value_definitions. + std::unordered_map> value_definitions; + auto initial_element_list = std::vector>(); for (const auto& initial_element : initial_node.initial_elements) { diff --git a/tests/unit/pddl/factory.cpp b/tests/unit/pddl/factory.cpp index f7021bcc..365301fe 100644 --- a/tests/unit/pddl/factory.cpp +++ b/tests/unit/pddl/factory.cpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace loki::domain::tests { @@ -54,4 +55,19 @@ TEST(LokiTests, FactoryIteratorEmptyTest) EXPECT_EQ(objects.size(), 0); } +TEST(LokiTests, FactoryVariantTest) +{ + PDDLFactory objects(2); + PDDLFactory terms(2); + const auto object_0 = objects.get_or_create("object_0", TypeList()); + const auto object_1 = objects.get_or_create("object_1", TypeList()); + + const auto term_0_object_0 = terms.get_or_create(object_0); + const auto term_1_object_0 = terms.get_or_create(object_0); + const auto term_2_object_1 = terms.get_or_create(object_1); + + EXPECT_EQ(term_0_object_0, term_1_object_0); + EXPECT_NE(term_0_object_0, term_2_object_1); +} + }