You are on page 1of 3

Last modified on: September 16, 2010

VacuumCleanerAssignment:AgentBreadth
Description
Create a Java vacuum cleaner using Java that is given an array representation of the complete board state. Using this representation, your agent should perform a breadth first search to find the sequence of actions that it should take to clean all of the squares in the fewest moves. Please name your agent file AgentBreadth.jess. Your tree should have a branching factor of five and should utilize nodes like the one shown on the right. Each node should contain the board state, which consists of an array of characters that represent the board, the coordinates of the vacuum, and a tag that represents how the vacuum got from the parent node to the current node (i.e., left, right, up, down, clean). The UML class diagram shown below depicts the structure that your program have. Your agent should be hardcoded to solve this problem for the board shown below: v * - * - - - * - * - - * * Be sure to consult the Vacuum Cleaner Programmers Manual for additional information about how to create a Java-based vacuum cleaner. Finally, I am also providing you with a Java method that performs a breadth first search based on the pseudo code given in your textbook. The code is listed below:

Page 1 of 3

Last modified on: September 16, 2010


public static List<String> breadthFirstSearch(List<Node> fringe) { List<String> ret = null; while(fringe.size() > 0) { Node n = fringe.remove(0); if (n.getState().isGoalState()) { ret = solution(n); break; } else { n.expand(); m_visitedStates_s.add(n.getState()); if(n.getLeftChild() != null) fringe.add(n.getLeftChild()); if(n.getRightChild() != null) fringe.add(n.getRightChild()); if(n.getUpChild() != null) fringe.add(n.getUpChild()); if(n.getDownChild() != null) fringe.add(n.getDownChild()); if(n.getCleanChild() != null) fringe.add(n.getCleanChild()); } } return ret; }

The expand method asks a node to create all of its child nodes. This is a complicated method because it needs to create all possible child nodes that have not been visited yet. In addition, when it creates each child node it needs to populate the node with the new board state resulting from the action. The solution method returns a sequence of actions by backtracking from the goal node to the root node. Finally, here are some tips for building and running your agent: Copy the vacuum cleaner jar to your project folder Add the vacuum cleaner jar to your build path in eclipse Add your board text file to your project folder Run your agent from the command line with the project folder as your current directory using: java classpath.;vacuum_3.0.jar;./bin edu.lhup.vacuum.Main OR for Linux: java classpath.:vacuum_3.0.jar:./bin edu.lhup.vacuum.Main The rubric I will use to grade this assignment is given on the next page. Please pay close attention to this rubric when doing the assignment.

Page 2 of 3

Last modified on: September 16, 2010

Rubric
Name: Task Description Agent Ruler Java code compiles without any errors Your Node class supports five children (left, right, up, down, and clean) one parent, and has an expand method that creates all of its children and a solution method that returns a sequence of actions by backtracking from the goal node to the root node. Your State class represents the state of the board and is capable of updating the state based on the five valid vacuum actions (left, right, up, down, clean). Your State class should also be able to determine if it represents the goal state. Your AgentBreadth class determines the optimum sequence of actions by performing a breadth first search. It then performs the sequence on the environment. After the sequence is complete, it stops moving. Total Comments: 4 2 Possible Points Your Score

10

Page 3 of 3

You might also like