From 3f6d72de6af8dc222c06324e04969c6e9ee3af72 Mon Sep 17 00:00:00 2001 From: opensourceware Date: Mon, 26 Sep 2016 15:55:29 +0800 Subject: [PATCH 1/2] Added implementation of the cake problem --- planning.py | 29 ++++++++++++++++++++++++++++- tests/test_planning.py | 11 +++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/planning.py b/planning.py index c4ebe1181..726a5602d 100644 --- a/planning.py +++ b/planning.py @@ -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)'), @@ -210,3 +210,30 @@ def goal_test(kb): 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) diff --git a/tests/test_planning.py b/tests/test_planning.py index 739324256..2fa5ad395 100644 --- a/tests/test_planning.py +++ b/tests/test_planning.py @@ -46,3 +46,14 @@ def test_spare_tire(): 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() From 1f3b32f891cab2d8f40c48aa55ba035e78df65a2 Mon Sep 17 00:00:00 2001 From: opensourceware Date: Mon, 26 Sep 2016 16:14:46 +0800 Subject: [PATCH 2/2] Added test for three_block_tower and fixed a bug in three_block_tower code --- planning.py | 5 ++--- tests/test_planning.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/planning.py b/planning.py index 726a5602d..2dd57787a 100644 --- a/planning.py +++ b/planning.py @@ -195,15 +195,14 @@ 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)')] diff --git a/tests/test_planning.py b/tests/test_planning.py index 2fa5ad395..3567ab445 100644 --- a/tests/test_planning.py +++ b/tests/test_planning.py @@ -47,6 +47,18 @@ def test_spare_tire(): 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy