Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added implementation of the cake problem, tests for cake and three towers problem #265

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

Merged
merged 2 commits into from
Sep 27, 2016
Merged
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
34 changes: 30 additions & 4 deletions planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def goal_test(kb):
leave_overnight = Action(expr("LeaveOvernight"), [precond_pos, precond_neg], [effect_add, effect_rem])

return PDLL(init, [remove, put_on, leave_overnight], goal_test)

def three_block_tower():
init = [expr('On(A, Table)'),
expr('On(B, Table)'),
Expand All @@ -195,18 +195,44 @@ def goal_test(kb):

## Actions
# Move
precond_pos = [expr('On(b, x)'), expr('Clear(b)'), expr('Clear(y)'), expr('Block(b)'),
expr('Block(y)'), expr('b != x'), expr('b != y'), expr('x != y')]
precond_pos = [expr('On(b, x)'), expr('Clear(b)'), expr('Clear(y)'), expr('Block(b)'), expr('Block(y)')]
precond_neg = []
effect_add = [expr('On(b, y)'), expr('Clear(x)')]
effect_rem = [expr('On(b, x)'), expr('Clear(y)')]
move = Action(expr('Move(b, x, y)'), [precond_pos, precond_neg], [effect_add, effect_rem])

# MoveToTable
precond_pos = [expr('On(b, x)'), expr('Clear(b)'), expr('Block(b)'), expr('b != x')]
precond_pos = [expr('On(b, x)'), expr('Clear(b)'), expr('Block(b)')]
precond_neg = []
effect_add = [expr('On(b, Table)'), expr('Clear(x)')]
effect_rem = [expr('On(b, x)')]
moveToTable = Action(expr('MoveToTable(b, x)'), [precond_pos, precond_neg], [effect_add, effect_rem])

return PDLL(init, [move, moveToTable], goal_test)

def have_cake_and_eat_cake_too():
init = [expr('Have(Cake)')]

def goal_test(kb):
required = [expr('Have(Cake)'), expr('Eaten(Cake)')]
for q in required:
if kb.ask(q) is False:
return False
return True

##Actions
# Eat cake
precond_pos = [expr('Have(Cake)')]
precond_neg = []
effect_add = [expr('Eaten(Cake)')]
effect_rem = [expr('Have(Cake)')]
eat_cake = Action(expr('Eat(Cake)'), [precond_pos, precond_neg], [effect_add, effect_rem])

#Bake Cake
precond_pos = []
precond_neg = [expr('Have(Cake)')]
effect_add = [expr('Have(Cake)')]
effect_rem = []
bake_cake = Action(expr('Bake(Cake)'), [precond_pos, precond_neg], [effect_add, effect_rem])

return PDLL(init, [eat_cake, bake_cake], goal_test)
23 changes: 23 additions & 0 deletions tests/test_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@ def test_spare_tire():
p.act(action)

assert p.goal_test()

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()

def test_have_cake_and_eat_cake_too():
p = have_cake_and_eat_cake_too()
assert p.goal_test() is False
solution = [expr("Eat(Cake)"),
expr("Bake(Cake)")]

for action in solution:
p.act(action)

assert p.goal_test()