A
StateSpaceSolver is a
Solver where:
- The search queue is set to be a double-ended queue, implemented
as a linked list (as with GraphSolver), but
- The expand method dynamically creates child vertices using
the problem's Mover object.
StateSpaceSolver is abstract so that subclasses can implement
breadth-first and depth-first search. Also:
- StateSpaceSolver's constructor, like that
for GraphSolver, sets the queue to a linked list managed as
a double-ended queue. However, it does not create a graph for the
problem.
- StateSpaceSolver overrides the expand method so
that child vertices are created using the problem's Mover
object.
The use of a Mover is similar to that employed by the
previously discussed graph creation algorithm (see menu). However,
since there is no
graph involved, there is no reclaiming of vertices.
Since checking for repeated vertices is done by the state space
search algorithm, expand need not concern itself with
reencountering vertices.
- Since there is no graph, StateSpaceSolver does not
override the getCurrent method.
StateSpaceSolver.java
should be added to the
framework.solution package and completed
by the student.
As with
GraphSolver, a
StateSpaceSolver
can manage the double-ended queue
deque as either:
- A FIFO (first-in first-out) queue, for breadth-first search, or
- A LIFO (last-in first-out) stack, for depth-first search
This is accomplished simply by overriding
the
Solver's
add method: