ai.search
Class Problem

java.lang.Object
  extended byai.search.Problem
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.lang.Runnable
Direct Known Subclasses:
CannibalProblem, ChainProblem, Puzzle8Problem, RouteProblem

public abstract class Problem
extends java.lang.Object
implements java.lang.Runnable, java.awt.event.ActionListener

An abstract search problem.

Author:
Jill Zimmerman -- jill.zimmerman@goucher.edu

Field Summary
 java.lang.String algorithm
          The search algorithm.
 java.awt.Canvas canvas
          canvas to display the search.
 Node currentNode
          The current node in the search.
 boolean display
          Whether or not to display the search.
 java.lang.Object goal
          An optional goal state.
 java.lang.String heuristic
          The search heuristic.
 java.lang.Object initialState
          The initial state.
 int numExpanded
          The number of nodes expanded in the search.
 java.util.Vector q
          The search queue.
 Search search
          The search.
 Node searchResult
          The node which is the search result.
 
Constructor Summary
Problem(java.lang.Object initState)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
abstract  java.lang.String actionToString(java.lang.Object action)
          Convert an action to a string.
 int edgeCost(Node node, java.lang.Object action, java.lang.Object state)
          Return the cost of an edge.
abstract  boolean equalState(java.lang.Object state1, java.lang.Object state2)
          Determine if two states are equivalent.
 boolean goalReached(java.lang.Object state)
          Is the state a goal state?
 int hCost(java.lang.Object state)
          Return the estimated cost from given state to a goal.
 void run()
           
 Node solve(java.lang.String alg, java.lang.String heur, int maxExpanded)
          Solve the problem with the specified search algorithm.
 void start()
           
abstract  java.lang.String stateToString(java.lang.Object state)
          Convert a state to a string.
 void stop()
           
abstract  java.util.Vector successors(java.lang.Object state)
          Determine all the states which are successors of the given state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

initialState

public java.lang.Object initialState
The initial state.


goal

public java.lang.Object goal
An optional goal state.


numExpanded

public int numExpanded
The number of nodes expanded in the search.


display

public boolean display
Whether or not to display the search.


canvas

public java.awt.Canvas canvas
canvas to display the search.


q

public java.util.Vector q
The search queue.


search

public Search search
The search.


algorithm

public java.lang.String algorithm
The search algorithm.


heuristic

public java.lang.String heuristic
The search heuristic.


searchResult

public Node searchResult
The node which is the search result.


currentNode

public Node currentNode
The current node in the search.

Constructor Detail

Problem

public Problem(java.lang.Object initState)
Method Detail

successors

public abstract java.util.Vector successors(java.lang.Object state)
Determine all the states which are successors of the given state.

Parameters:
state - is the given state
Returns:
a vector of successors

equalState

public abstract boolean equalState(java.lang.Object state1,
                                   java.lang.Object state2)
Determine if two states are equivalent.

Parameters:
state1 - and states are the two states
Returns:
true if equal

stateToString

public abstract java.lang.String stateToString(java.lang.Object state)
Convert a state to a string.

Parameters:
state - is the given state
Returns:
a string expressing the state

actionToString

public abstract java.lang.String actionToString(java.lang.Object action)
Convert an action to a string.

Parameters:
action - is the given action
Returns:
a string expressing the action

goalReached

public boolean goalReached(java.lang.Object state)
Is the state a goal state?


hCost

public int hCost(java.lang.Object state)
Return the estimated cost from given state to a goal. A default value is 0.


edgeCost

public int edgeCost(Node node,
                    java.lang.Object action,
                    java.lang.Object state)
Return the cost of an edge. A default value is 1.


start

public void start()

stop

public void stop()

run

public void run()
Specified by:
run in interface java.lang.Runnable

solve

public Node solve(java.lang.String alg,
                  java.lang.String heur,
                  int maxExpanded)
Solve the problem with the specified search algorithm.

Parameters:
alg - is the algorithm.
heur - is an optional heuristic
maxExpanded - is the maximum number of nodes to expand
Returns:
the node of a solution.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener