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

Skip to content

Planning #253

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 4 commits into from
Sep 7, 2016
Merged
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
51 changes: 47 additions & 4 deletions planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class PDLL:
"""
PDLL used to deine a search problem
PDLL used to define a search problem
It stores states in a knowledge base consisting of first order logic statements
The conjunction of these logical statements completely define a state
"""
Expand Down Expand Up @@ -61,7 +61,11 @@ def __call__(self, kb, args):

def substitute(self, e, args):
"""Replaces variables in expression with their respective Propostional symbol"""
new_args = [args[i] for x in e.args for i in range(len(self.args)) if self.args[i] == x]
new_args = list(e.args)
for num, x in enumerate(e.args):
for i in range(len(self.args)):
if self.args[i] == x:
new_args[num] = args[i]
return Expr(e.op, *new_args)

def check_precond(self, kb, args):
Expand Down Expand Up @@ -123,12 +127,51 @@ def goal_test(kb):
effect_rem = [expr("In(c, p)")]
unload = Action(expr("Unload(c, p, a)"), [precond_pos, precond_neg], [effect_add, effect_rem])

# Load
# Used used 'f' instead of 'from' because 'from' is a python keyword and expr uses eval() function
# Fly
# Used 'f' instead of 'from' because 'from' is a python keyword and expr uses eval() function
precond_pos = [expr("At(p, f)"), expr("Plane(p)"), expr("Airport(f)"), expr("Airport(to)")]
precond_neg = []
effect_add = [expr("At(p, to)")]
effect_rem = [expr("At(p, f)")]
fly = Action(expr("Fly(p, f, to)"), [precond_pos, precond_neg], [effect_add, effect_rem])

return PDLL(init, [load, unload, fly], goal_test)


def spare_tire():
init = [expr('Tire(Flat)'),
expr('Tire(Spare)'),
expr('At(Flat, Axle)'),
expr('At(Spare, Trunk)')]

def goal_test(kb):
required = [expr('At(Spare, Axle)'), expr('At(Flat, Ground)')]
for q in required:
if kb.ask(q) is False:
return False
return True

##Actions
#Remove
precond_pos = [expr("At(obj, loc)")]
precond_neg = []
effect_add = [expr("At(obj, Ground)")]
effect_rem = [expr("At(obj, loc)")]
remove = Action(expr("Remove(obj, loc)"), [precond_pos, precond_neg], [effect_add, effect_rem])

#PutOn
precond_pos = [expr("Tire(t)"), expr("At(t, Ground)")]
precond_neg = [expr("At(Flat, Axle)")]
effect_add = [expr("At(t, Axle)")]
effect_rem = [expr("At(t, Ground)")]
put_on = Action(expr("PutOn(t, Axle)"), [precond_pos, precond_neg], [effect_add, effect_rem])

#LeaveOvernight
precond_pos = []
precond_neg = []
effect_add = []
effect_rem = [expr("At(Spare, Ground)"), expr("At(Spare, Axle)"), expr("At(Spare, Trunk)"),
expr("At(Flat, Ground)"), expr("At(Flat, Axle)"), expr("At(Flat, Trunk)")]
leave_overnight = Action(expr("LeaveOvernight"), [precond_pos, precond_neg], [effect_add, effect_rem])

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