diff --git a/README.md b/README.md index 08e5e23fd..7cb796b02 100644 --- a/README.md +++ b/README.md @@ -76,16 +76,16 @@ Here is a table of algorithms, the figure, name of the code in the book and in t | 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] | | 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] | | 9.8 | Append | | | -| 10.1 | Air-Cargo-problem | | -| 10.2 | Spare-Tire-Problem | | -| 10.3 | Three-Block-Tower | | -| 10.7 | Cake-Problem | | -| 10.9 | Graphplan | | +| 10.1 | Air-Cargo-problem |`air_cargo` |[`planning.py`][planning]| +| 10.2 | Spare-Tire-Problem | `spare_tire` |[`planning.py`][planning]| +| 10.3 | Three-Block-Tower | `three_block_tower` |[`planning.py`][planning]| +| 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` |[`planning.py`][planning]| +| 10.9 | Graphplan | `GraphPlan` |[`planning.py`][planning]| | 10.13 | Partial-Order-Planner | | | 11.1 | Job-Shop-Problem-With-Resources | | | 11.5 | Hierarchical-Search | | | 11.8 | Angelic-Search | | -| 11.10 | Doubles-tennis | | +| 11.10 | Doubles-tennis | `double_tennis_problem` |[`planning.py`][planning]| | 13 | Discrete Probability Distribution | `ProbDist` | [`probability.py`][probability] | | 13.1 | DT-Agent | `DTAgent` | [`probability.py`][probability] | | 14.9 | Enumeration-Ask | `enumeration_ask` | [`probability.py`][probability] | diff --git a/logic.py b/logic.py index 9054cdfc7..bd9c92334 100644 --- a/logic.py +++ b/logic.py @@ -842,7 +842,22 @@ def subst(s, x): def fol_fc_ask(KB, alpha): - raise NotImplementedError + """A simple forward-chaining algorithm. [Figure 9.3]""" + while new is not None: + new = [] + for rule in KB: + p, q = parse_definite_clause(standardize_variables(rule)) + for p_ in random.KB.clauses: + if p != p_: + for theta in (subst(theta, p) == subst(theta, p_)): + q_ = subst(theta, q) + if not unify(q_,KB.sentence in KB) or not unify(q_, new): + new.append(q_) + phi = unify(q_,alpha) + if phi is not None: + return phi + KB.tell(new) + return None def standardize_variables(sentence, dic=None): diff --git a/planning.py b/planning.py index 17028e4c6..47eae77da 100644 --- a/planning.py +++ b/planning.py @@ -237,6 +237,7 @@ def goal_test(kb): return PDLL(init, [eat_cake, bake_cake], goal_test) + class Level(): """ Contains the state of the planning problem @@ -531,8 +532,8 @@ def double_tennis_problem(): init = [expr('At(A, LeftBaseLine)'), expr('At(B, RightNet)'), expr('Approaching(Ball, RightBaseLine)'), - expr('Partner(A,B)'), - expr('Partner(A,B)')] + expr('Partner(A, B)'), + expr('Partner(B, A)')] def goal_test(kb): required = [expr('Goal(Returned(Ball))'), expr('At(a, RightNet)'), expr('At(a, LeftNet)')] @@ -543,17 +544,17 @@ def goal_test(kb): ##actions #hit - precond_pos=[expr("Approaching(Ball,loc)"), expr("At(actor,loc)")] + precond_pos=[expr("Approaching(Ball, loc)"), expr("At(actor, loc)")] 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)"), [precond_pos, precond_neg], [effect_add, effect_rem]) #go - precond_pos = [ expr("At(actor,loc)")] + 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]) + 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]) return PDLL(init, [hit, go], goal_test) diff --git a/probability.py b/probability.py index 1d7992e6d..a5699b7f4 100644 --- a/probability.py +++ b/probability.py @@ -643,5 +643,7 @@ def particle_filtering(e, N, HMM): w[i] = float("{0:.4f}".format(w[i])) # STEP 2 + s = weighted_sample_with_replacement(N, s, w) + return s
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: