1 / 6

Monkey and Bananas Exercise

Monkey and Bananas Exercise. Notes on Exercise 3.10 of Bratko For CSCE 580 Sp03 Marco Valtorta. Bratko’s Solution.

janeconner
Download Presentation

Monkey and Bananas Exercise

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Monkey and Bananas Exercise Notes on Exercise 3.10 of Bratko For CSCE 580 Sp03 Marco Valtorta

  2. Bratko’s Solution • let canget(State,Actions) be the relation that holds if the monkey can get from State to a state in which it has the bananas by carrying out the moves described in the list Actions. • If the monkey already has the bananas, there is nothing that it needs to do. canget( state(_,_,_,has), [ ]). • Definition continues on the next slide

  3. Bratko’s Solution (ctd.) • The monkey can get from State to a state in which it has the bananas by doing Action followed by Actions if • (a) the monkey can move from State to NewState by doing Action, and • (b) the monkey can move from NewState to a state in which it has the bananas by doing Actions. canget( State, [Action|Actions]) :- move( State, Action, NewState), canget( NewState, Actions).

  4. Alternate Solution • canget1(State, Actions, Path) if the monkey can get the bananas from State by doing the actions in the difference list Path – Actions • If the monkey is already in a state in which it can get the bananas, then there is nothing that it needs to do: canget1( state(_,_,_,has), Actions, Actions). • Definition continues on the next slide

  5. Alternate Solution (Ctd.) • The monkey can get the bananas from State1 by doing the Actions in Path - Actions if • (a) the monkey can move to State2 by doing Move, and • (b) the monkey can get the bananas from State2 by doing the actions in Path - (Actions + Move) canget1( State1, Actions, Path) :- move( State1, Move, State2), canget1( State2, [Move | Actions], Path).

  6. Alternate Solution (Ctd.) • There is a procedural reading to the alternate solution: accumulate the solution path into the Actions list going down the goal tree, then save it at the bottom of the goal tree • The solution Path is built backwards! We need: canget( State, Actions) :- canget1( State, [ ], ReverseActions), rev(Actions, ReverseActions). • Actions can be thought of as an accumulator. • Accumulators and difference lists are good for efficiency, but in this exercise the simpler solution is faster too!

More Related