vacuum breadth first search
TRANSCRIPT
Last modified on: September 16, 2010
Vacuum Cleaner Assignment: “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
at your program have. diagram shown below depicts the structure th
Your agent should be hardcoded to
v * - *
Be sure to consu m r
Finally, I am also providing you with a Java method that performs a breadth first :
solve this problem for the board shown below:
- - - -
* - * -
- - * *
lt the VacuuCleaner Programmer’s Manual foadditional information about how tocreate a Java-based vacuum cleaner.
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 = break;
solution(n);
} else {
n.expand(); m_visitedStates_s.add(n.getState()); if(n.getLeftChild() != null)
fringe.add(n.getLeftChiif(n.getRightChild() != null)
ld());
fringe.add(n.getRightChild()); if(n.getUpChild() != null)
fringe.add(n.getUpChildif(n.getDownChild() != null)
());
fringe.add(n.getDownChilif(n.getCleanChild() != null)
d());
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
curr directory using: ent
java asspath.;vacuum_3.0.jar;./bin edu.lhup.vacuum.Main
‐clO
java ‐classpath.:vacuum_3.0.jar:./bin edu.lhup.vacuum.Main R for Linux:
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
Page 3 of 3
Rubric Name:
Task Description Possible Points
Your Score
Agent Ruler
Java code compiles without any errors 4
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.
2
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.
2
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.
2
Total 10
Comments: