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

Skip to content

Commit 28d7996

Browse files
Chipe1norvig
authored andcommitted
Changes to planning.py (aimacode#452)
* Removed redundant condition * moved gola_test inside function * refactor goal_test()
1 parent 8ca5ab1 commit 28d7996

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

planning.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ def air_cargo():
110110

111111
def goal_test(kb):
112112
required = [expr('At(C1 , JFK)'), expr('At(C2 ,SFO)')]
113-
for q in required:
114-
if kb.ask(q) is False:
115-
return False
116-
return True
113+
return all([kb.ask(q) is not False for q in required])
117114

118115
# Actions
119116

@@ -151,11 +148,8 @@ def spare_tire():
151148
expr('At(Spare, Trunk)')]
152149

153150
def goal_test(kb):
154-
required = [expr('At(Spare, Axle)'), expr('At(Flat, Ground)')]
155-
for q in required:
156-
if kb.ask(q) is False:
157-
return False
158-
return True
151+
required = [expr('At(Spare, Axle)')]
152+
return all(kb.ask(q) is not False for q in required)
159153

160154
# Actions
161155

@@ -197,10 +191,7 @@ def three_block_tower():
197191

198192
def goal_test(kb):
199193
required = [expr('On(A, B)'), expr('On(B, C)')]
200-
for q in required:
201-
if kb.ask(q) is False:
202-
return False
203-
return True
194+
return all(kb.ask(q) is not False for q in required)
204195

205196
# Actions
206197

@@ -228,10 +219,7 @@ def have_cake_and_eat_cake_too():
228219

229220
def goal_test(kb):
230221
required = [expr('Have(Cake)'), expr('Eaten(Cake)')]
231-
for q in required:
232-
if kb.ask(q) is False:
233-
return False
234-
return True
222+
return all(kb.ask(q) is not False for q in required)
235223

236224
# Actions
237225

@@ -517,18 +505,14 @@ def extract_solution(self, goals_pos, goals_neg, index):
517505
return solution
518506

519507

520-
def goal_test(kb, goals):
521-
for q in goals:
522-
if kb.ask(q) is False:
523-
return False
524-
return True
525-
526-
527508
def spare_tire_graphplan():
528509
pddl = spare_tire()
529510
negkb = FolKB([expr('At(Flat, Trunk)')])
530511
graphplan = GraphPlan(pddl, negkb)
531512

513+
def goal_test(kb, goals):
514+
return all(kb.ask(q) is not False for q in goals)
515+
532516
# Not sure
533517
goals_pos = [expr('At(Spare, Axle)'), expr('At(Flat, Ground)')]
534518
goals_neg = []
@@ -553,10 +537,7 @@ def double_tennis_problem():
553537

554538
def goal_test(kb):
555539
required = [expr('Goal(Returned(Ball))'), expr('At(a, RightNet)'), expr('At(a, LeftNet)')]
556-
for q in required:
557-
if kb.ask(q) is False:
558-
return False
559-
return True
540+
return all(kb.ask(q) is not False for q in required)
560541

561542
# Actions
562543

0 commit comments

Comments
 (0)