Here is a zipped NetBeans project to use for this lab:
CS_2511_Graph_Search.zip.
Unzip this file and open the
resulting
CS_2511_Graph_Search NetBeans project.
Three source packages are used:
- farmer: An implementation of the FWGC problem.
You will use the FarmerState class and complete
the FarmerGraph class.
- framework: The problem-solving framework
provided for you
in
Assignment 2. This package is only used for
the State interface type implemented by FarmerState.
- graph: The graph representation and search framework
that implements breadth-first and depth-first graph search. This
package contains an ExampleGraph class that you can use as
a model for FarmerGraph.
Two files under
Test Packages are used in this lab.
- farmer.FarmerGraphTest: This class will not compile until
you complete FarmerGraph.
- graph.ExampleGraphTest: This class should run (click
through the warning about the FarmerGraphTest errors) and
produce the output shown to the right.
Your job is to complete the
FarmerGraph class so that when
the
FarmerGraphTest class is run, it produces the output shown
to the right.
This lab is accomplished by completing the FarmerGraph class,
using ExampleGraph as a model.
The
graph.ExampleGraph class under
Source Packages, shown
to the right, represents the graph pictured below:
Note:
- ExampleGraph extends the abstract Graph class
- There are instance fields and getters for each of the graph's
vertices
- The constructor creates the vertices and edges, then uses the
inherited addVertices, addEdges,
and setDirected methods to complete the representation.
The
graph.ExampleGraphTest class under
Test Packages, shown
to the right, produces the output below by:
- Creating an ExampleGraph object
- Getting its vertices
- Making assertions about and printing the graph's adjacency
lists
- Making assertions about and printing the results of
breadth-first and depth-first searches of the graph
The
farmer.FarmerGraphTest class under
Test Packages, shown
to the right, is entirely analogous to
graph.ExampleGraphTest
and should produce the output below.
The
farmer.FarmerGraph class under
Source Packages, shown
to the right, must be completed to represent the graph pictured below:
The vertices in this graph are
FarmerState objects:
To complete
FarmerGraph, you must thoroughly
understand
ExampleGraph.
However, since the
FarmerGraphTest displays
actual
FarmerState objects in its search results, the
construction of
FarmerGraph vertices is slightly different.
ExampleGraph vertices are created by
constructing
SimpleVertex objects with simple names, as in:
private Vertex r;
...
r = new SimpleVertex("r");
FarmerGraph vertices must be
FarmerState objects, so they
must be constucted by, for example:
private Vertex v1;
...
v1 = new FarmerState("west", "west", "west", "west"); // the start state
This works because the
FarmerState class extends
the
graph.SimpleVertex class.
Finally, in order for
FarmerGraphTest to print
the
FarmerGraph adjacency lists with simple names, the vertices
must be given these names after creation, for example:
v1.setName("1");
When finished, zip your project folder as
your-login-LEX8.zip.
Email the zip file to your TA.