Skip to content

test case for double tennis problem #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def act(self, action):
"""
Performs the action given as argument.
Note that action is an Expr like expr('Remove(Glass, Table)') or expr('Eat(Sandwich)')
"""
"""
action_name = action.op
args = action.args
list_action = first(a for a in self.actions if a.name == action_name)
Expand Down Expand Up @@ -74,6 +74,7 @@ def substitute(self, e, args):
def check_precond(self, kb, args):
"""Checks if the precondition is satisfied in the current state"""
# check for positive clauses
#print (self.precond_pos[0].__eq__(expr('At(actor, loc)')), self.precond_neg)
for clause in self.precond_pos:
if self.substitute(clause, args) not in kb.clauses:
return False
Expand Down Expand Up @@ -536,7 +537,7 @@ def double_tennis_problem():
expr('Partner(B, A)')]

def goal_test(kb):
required = [expr('Goal(Returned(Ball))'), expr('At(a, RightNet)'), expr('At(a, LeftNet)')]
required = [expr('Returned(Ball)'), expr('At(a, LeftNet)'), expr('At(a, RightNet)')]
return all(kb.ask(q) is not False for q in required)

# Actions
Expand All @@ -546,14 +547,14 @@ def goal_test(kb):
precond_neg = []
effect_add = [expr("Returned(Ball)")]
effect_rem = []
hit = Action(expr("Hit(actor, Ball)"), [precond_pos, precond_neg], [effect_add, effect_rem])
hit = Action(expr("Hit(actor, Ball, loc)"), [precond_pos, precond_neg], [effect_add, effect_rem])

# Go
precond_pos = [expr("At(actor, loc)")]
precond_neg = []
effect_add = [expr("At(actor, to)")]
effect_rem = [expr("At(actor, loc)")]
go = Action(expr("Go(actor, to)"), [precond_pos, precond_neg], [effect_add, effect_rem])
go = Action(expr("Go(actor, to, loc)"), [precond_pos, precond_neg], [effect_add, effect_rem])

return PDDL(init, [hit, go], goal_test)

Expand Down Expand Up @@ -862,3 +863,17 @@ def goal_test(kb):

return Problem(init, [add_engine1, add_engine2, add_wheels1, add_wheels2, inspect1, inspect2],
goal_test, [job_group1, job_group2], resources)


def test_three_block_tower():
p = three_block_tower()
assert p.goal_test() is False
solution = [expr("MoveToTable(C, A)"),
expr("Move(B, Table, C)"),
expr("Move(A, Table, B)")]

for action in solution:
p.act(action)

assert p.goal_test()

12 changes: 12 additions & 0 deletions tests/test_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,19 @@ def test_spare_tire():

assert p.goal_test()

def test_double_tennis():
p = double_tennis_problem()
assert p.goal_test() is False

solution = [expr("Go(A, RightBaseLine, LeftBaseLine)"),
expr("Hit(A, Ball, RightBaseLine)"),
expr("Go(A, LeftNet, RightBaseLine)")]

for action in solution:
p.act(action)

assert p.goal_test()

def test_three_block_tower():
p = three_block_tower()
assert p.goal_test() is False
Expand Down