In this exercise you will: Note that the testing of this lab will use graph searching algorithms that will be described later. However, your tasks in this lab can be accomplished without understanding the algorithms at this time.
These provided files are required by the lab.
These are the lecture presentations in which the concepts for this lab were introduced.
First, add the new packages below to your ProblemSolver by right-clicking on Source Packages in the project tree and selecting New > Java Package... as shown below on the left.

After, your project structure should look like that on the right.

Now add the following classes to their respective packages. These classes have been discussed previously and are available from the menu on the left under Files. To add a class to a package, right-click the package and slect New > Java Class... as shown below on the left.

After, your project structure should like that on the right.

Now add the provided test classes ExampleGraphTest and SolutionTest to your project. Do this in two steps: For example, to create ExampleGraphTest.java, right-click ExampleGraph.java under Source Packages and select Tools > Create/Update Tests, as shown below.

This will create the corresponding test class under Test Packages whose default content you can then change.

After, your test packages structure should like that on the right.

Now test your project by running the graph example test as shown below left. Right-click ExampleGraphTest.java and select Run File.

The test output should look like that below right.

The example graph class and test class are shown in the menu at left. The test class runs some graph searches, the nature of which are described in the next module.

For now, look at ExampleGraphTest and note how the searches result in search predecessor information being set in the vertices and made available through the getPredecessor method in the Vertex class.

Breadth-first and depth-first graph searches generate predecessor trees that can be used to generate problem solutions, as described in Problem Solutions in the menu on the left.

It is not necessary at this time to know precisely how the graph searches work, only that they set vertex predecessor information during the search. This information can be used to construct solutions to problems.

Implement the described Solution class and test it by running the SolutionTest class.

The test output should look like that below.

These files include the ExampleGraph class and its test class ExampleGraphTest.
These files include the Solution class, which you must complete, and a SolutionTest class.
SolutionTest.java

These files make up the graph framework, which contains the Vertex, Graph, and GraphSearcher classes.
This section presents a Java framework for representing and searching graphs. The framework is comprised of the following classes, whose relationships are shown below. Note that the graph search operations are discussed in the Graph Search Algorithms presentation:

Vertex.java

Graph.java

Note that the search method employs a double-ended queue (java.util.LinkedList) so that it can be used for both breadth-first and depth-first search.

GraphSearcher.java

In this exercise you have three tasks:
You will create a Solution class that shows the path from a start vertex to an end vertex in a graph search.

This task is slightly complicated by the fact that although the output is from start to end, you must begin your solution processing with end.

To begin, create a Java class file called Solution.java in the framework.solution package:

The API for the Solution class is described in the Javadoc comments of the class template given below.

Create a test file for Solution.java and populate it with this SolutionTest.java file, whose content is shown in the menu.

The output is shown below. Note that although 3 states are shown, the length of the solution, that is, the number of moves to achieve the solution, is 2.

Move to the next step when your Solution class passes the test.

            |  |
            |  | F
            |  | W
          G |  |
            |  | C
            |  |


            |  |
          F |  |
            |  | W
          G |  |
            |  | C
            |  |


            |  |
            |  | F
            |  | W
            |  | G
            |  | C
            |  |

	
-- --
-- SolutionTest.java

--

--
See the "Framework Code" menu item to the left for a description of the graph framework code.

Create a new source package called framework.graph in your ProblemSolver project and install the Vertex.java, Graph.java, and GraphSearcher.java files in the package.

After installing the graph framework files, your project structure should look like that below.

Using ExampleGraph as a model, create a FarmerGraph class that represents the full FWGC problem:

FarmerGraph should be in the domains.farmer package as shown to the right. Note:

Add a new class called FarmerGraph to your domains.farmer package:

Here is a template for the file:

All the work is done by the FarmerGraph constructor.

First create the ten (10) possible FarmerState objects and store them as vertices.

For example, to create the vertex representing the start state:

Next, use the addEdge method inherited from the Graph class to link the vertices.

Note: It is not necessary to create a Graph object for this. Since FarmerGraph extends Graph, it is a Graph and inherits the addEdge method. To get rid of the NetBeans warning about overridable method calls in the constructor, use super.addEdge(...).

Recall that in the FWGC problem, if there is an edge from v1 to v2, then there is an edge from v2 to v1.

To test your graph, there will need to be access to the FWGC problem's start and end vertices.

Complete the getStart and getEnd methods.

In the last step, create a test class for FarmerGraph and replace its default contents with the FarmerGraphTest.java file shown in the menu at left.

This test does four searches on your graph:

A successful test results in:

Additionally, for each search, the test file displays the path traced from the start (or end) to the end (or start). The path must show a valid solution. Example solutions are shown in the menu.

Important:
After adding the FarmerGraphTest class shown below, your test packages structure should look like that on the right.

FarmerGraphTest.java

	  BFS from start to end:
            |  |
          F |  |
          W |  |
          G |  |
          C |  |
            |  |

            |  |
            |  | F
          W |  |
            |  | G
          C |  |
            |  |

            |  |
          F |  |
          W |  |
            |  | G
          C |  |
            |  |

            |  |
            |  | F
            |  | W
            |  | G
          C |  |
            |  |

            |  |
          F |  |
            |  | W
          G |  |
          C |  |
            |  |

            |  |
            |  | F
            |  | W
          G |  |
            |  | C
            |  |

            |  |
          F |  |
            |  | W
          G |  |
            |  | C
            |  |

            |  |
            |  | F
            |  | W
            |  | G
            |  | C
            |  |

          BFS from end to start:
            |  |
            |  | F
            |  | W
            |  | G
            |  | C
            |  |

            |  |
          F |  |
            |  | W
          G |  |
            |  | C
            |  |

            |  |
            |  | F
            |  | W
          G |  |
            |  | C
            |  |

            |  |
          F |  |
            |  | W
          G |  |
          C |  |
            |  |

            |  |
            |  | F
            |  | W
            |  | G
          C |  |
            |  |

            |  |
          F |  |
          W |  |
            |  | G
          C |  |
            |  |

            |  |
            |  | F
          W |  |
            |  | G
          C |  |
            |  |

            |  |
          F |  |
          W |  |
          G |  |
          C |  |
            |  |

          DFS from start to end:
            |  |
          F |  |
          W |  |
          G |  |
          C |  |
            |  |

            |  |
            |  | F
          W |  |
            |  | G
          C |  |
            |  |

            |  |
          F |  |
          W |  |
            |  | G
          C |  |
            |  |

            |  |
            |  | F
          W |  |
            |  | G
            |  | C
            |  |

            |  |
          F |  |
          W |  |
          G |  |
            |  | C
            |  |

            |  |
            |  | F
            |  | W
          G |  |
            |  | C
            |  |

            |  |
          F |  |
            |  | W
          G |  |
            |  | C
            |  |

            |  |
            |  | F
            |  | W
            |  | G
            |  | C
            |  |

          DFS from end to start:
            |  |
            |  | F
            |  | W
            |  | G
            |  | C
            |  |

            |  |
          F |  |
            |  | W
          G |  |
            |  | C
            |  |

            |  |
            |  | F
            |  | W
          G |  |
            |  | C
            |  |

            |  |
          F |  |
          W |  |
          G |  |
            |  | C
            |  |

            |  |
            |  | F
          W |  |
            |  | G
            |  | C
            |  |

            |  |
          F |  |
          W |  |
            |  | G
          C |  |
            |  |

            |  |
            |  | F
          W |  |
            |  | G
          C |  |
            |  |

            |  |
          F |  |
          W |  |
          G |  |
          C |  |
            |  |
	
When your Solution and FarmerGraph classes are working correctly: Note the general Submission Policy in the menu at left.

Your project will be inspected, tested, and run by the lab instructor. Grading criteria: