Skip to content

Commit

Permalink
add test problem_expert.exist_precidate
Browse files Browse the repository at this point in the history
  • Loading branch information
Rezenders committed Sep 2, 2024
1 parent 3156cba commit 2262740
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 0 deletions.
91 changes: 91 additions & 0 deletions plansys2_problem_expert/test/pddl/domain_simple_derived.pddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
(define (domain simple)
(:requirements :strips :typing :adl :fluents :durative-actions :derived-predicates)

;; Types ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(:types
person - object
message - object
robot - object
room - object
room_with_teleporter - room
);; end Types ;;;;;;;;;;;;;;;;;;;;;;;;;

;; Predicates ;;;;;;;;;;;;;;;;;;;;;;;;;
(:predicates

(robot_talk ?r - robot ?m - message ?p - person)
(robot_near_person ?r - robot ?p - person)
(robot_at ?r - robot ?ro - room)
(person_at ?p - person ?ro - room)
(is_teleporter_enabled ?r - room_with_teleporter)
(is_teleporter_destination ?r - room)
(inferred-robot_at ?r - robot ?ro - room)
(inferred-person_at ?p - person ?ro - room)
);; end Predicates ;;;;;;;;;;;;;;;;;;;;
;; Functions ;;;;;;;;;;;;;;;;;;;;;;;;;
(:functions
(room_distance ?r1 - room ?r2 - room)
);; end Functions ;;;;;;;;;;;;;;;;;;;;

;; Derived predicates ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(:derived (inferred-robot_at ?r - robot ?ro - room)
(and
(robot_at ?r ?ro)
)
)
(:derived (inferred-person_at ?p - person ?ro - room)
(and
(person_at ?p ?ro)
)
)

;; Actions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(:durative-action move
:parameters (?r - robot ?r1 ?r2 - room)
:duration ( = ?duration (* (room_distance ?r1 ?r2) 0.5))
:condition (and
(at start(robot_at ?r ?r1)))
:effect (and
(at start(not(robot_at ?r ?r1)))
(at end(robot_at ?r ?r2))
)
)

(:action teleport
:parameters (?r - robot ?r1 - room_with_teleporter ?r2 - room)
:precondition (and
(robot_at ?r ?r1)
(is_teleporter_enabled ?r1)
(is_teleporter_destination ?r2)
)
:effect (and
(not(robot_at ?r ?r1))
(robot_at ?r ?r2)
)
)

(:durative-action talk
:parameters (?r - robot ?from ?p - person ?m - message)
:duration ( = ?duration 5)
:condition (and
(over all(robot_near_person ?r ?p))
)
:effect (and
(at end(robot_talk ?r ?m ?p))
)
)

(:durative-action approach
:parameters (?r - robot ?ro - room ?p - person)
:duration ( = ?duration 5)
:condition (and
(over all(robot_at ?r ?ro))
(over all(person_at ?p ?ro))
(at end(person_at ?p ?ro))
)
:effect (and
(at end(robot_near_person ?r ?p))
)
)

);; end Domain ;;;;;;;;;;;;;;;;;;;;;;;;
66 changes: 66 additions & 0 deletions plansys2_problem_expert/test/unit/problem_expert_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,72 @@ TEST(problem_expert, is_goal_satisfied)
ASSERT_TRUE(problem_expert.isGoalSatisfied(goal));
}

TEST(problem_expert, exist_predicate)
{
std::string pkgpath = ament_index_cpp::get_package_share_directory("plansys2_problem_expert");
std::ifstream domain_ifs(pkgpath + "/pddl/domain_simple_derived.pddl");
std::string domain_str((
std::istreambuf_iterator<char>(domain_ifs)),
std::istreambuf_iterator<char>());

auto domain_expert = std::make_shared<plansys2::DomainExpert>(domain_str);
plansys2::ProblemExpert problem_expert(domain_expert);

std::ifstream problem_ifs(pkgpath + "/pddl/problem_simple_1.pddl");
std::string problem_str((
std::istreambuf_iterator<char>(problem_ifs)),
std::istreambuf_iterator<char>());
ASSERT_TRUE(problem_expert.addProblem(problem_str));

ASSERT_TRUE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(robot_at leia kitchen)")));
ASSERT_TRUE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(inferred-robot_at leia kitchen)")));
ASSERT_TRUE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(person_at jack bedroom)")));
ASSERT_TRUE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(inferred-person_at jack bedroom)")));
ASSERT_FALSE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(inferred-person_at jack kitchen)")));
ASSERT_FALSE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(inferred-robot_at leia bedroom)")));

problem_expert.removePredicate(
parser::pddl::fromStringPredicate("(robot_at leia kitchen)"));
problem_expert.removePredicate(
parser::pddl::fromStringPredicate("(person_at jack bedroom)"));

ASSERT_FALSE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(inferred-person_at jack bedroom)")));
ASSERT_FALSE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(inferred-robot_at leia kitchen)")));
ASSERT_FALSE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(person_at jack bedroom)")));
ASSERT_FALSE(
problem_expert.existPredicate(
parser::pddl::fromStringPredicate(
"(robot_at leia kitchen)")));

}

int main(int argc, char ** argv)
{
testing::InitGoogleTest(&argc, argv);
Expand Down

0 comments on commit 2262740

Please sign in to comment.