hSearch
Class State

java.lang.Object
  extended by hSearch.State
All Implemented Interfaces:
java.lang.Comparable<State>

public abstract class State
extends java.lang.Object
implements java.lang.Comparable<State>

State serves as a base class for a problem specific state. Any particular problem should extend the state class, add problem specific state details to it and give implementations for the abstract methods. It may optionally override the non final methods. Important: Override Object.equals to check the equality of two states and toString method for a suitable display function.


Field Summary
protected  int cost
           
protected  State parent
           
protected  java.util.ArrayList<State> successors
           
 
Constructor Summary
State()
           
State(State parent)
           
 
Method Summary
protected  void addSuccessor(State successor)
           
 int compareTo(State obj)
          Compare desirability with another state.
 int f()
          Comparability Function = Desirability - Cost
 int g()
           
 int gChild()
          Cost of Child, default is 1+g, available for overriding
abstract  java.util.ArrayList<State> generateSuccessors()
          Returns a successor list by applying suitable operators but should not add any state to the successors list or set the successor list to this list.
 State getParent()
           
 java.lang.String getPath()
          Returns the path from the initial state to this (goal) state as a string.
 java.lang.String getPath(java.lang.String path)
           
 int getPathLength()
          Returns the length of a state from the initial state.
 java.util.ArrayList<State> getSuccessors()
           
abstract  int h()
          Desirabilty Function
abstract  boolean isGoal()
          Whether or not a given state is a goal state.
protected  void setParent(State parent)
           
 void show()
          A display routine specific to the problem state.
 void showPath()
          Routine to print the path from the initial state to this (goal) state.
 void updateCost()
          UpdateCost() and UpdateCost(State) together in a chained recursive fashion are able to depth first traverse the successor tree and update cost values in case the best parent has just got better!
 void updateCost(State caller)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

successors

protected java.util.ArrayList<State> successors

parent

protected State parent

cost

protected int cost
Constructor Detail

State

public State(State parent)

State

public State()
Method Detail

getParent

public final State getParent()

getSuccessors

public final java.util.ArrayList<State> getSuccessors()

setParent

protected final void setParent(State parent)

addSuccessor

protected final void addSuccessor(State successor)

g

public int g()

gChild

public int gChild()
Cost of Child, default is 1+g, available for overriding


h

public abstract int h()
Desirabilty Function


f

public final int f()
Comparability Function = Desirability - Cost


compareTo

public final int compareTo(State obj)
Compare desirability with another state. java.util.PriorityQueue < E > implements a min heap. Since f() is greater for a more desirable state, compare returns -(f()-obj.f())

Specified by:
compareTo in interface java.lang.Comparable<State>

updateCost

public final void updateCost()
UpdateCost() and UpdateCost(State) together in a chained recursive fashion are able to depth first traverse the successor tree and update cost values in case the best parent has just got better!


updateCost

public final void updateCost(State caller)

showPath

public void showPath()
Routine to print the path from the initial state to this (goal) state.


getPath

public java.lang.String getPath()
Returns the path from the initial state to this (goal) state as a string.


getPath

public java.lang.String getPath(java.lang.String path)

getPathLength

public int getPathLength()
Returns the length of a state from the initial state.


isGoal

public abstract boolean isGoal()
Whether or not a given state is a goal state.


generateSuccessors

public abstract java.util.ArrayList<State> generateSuccessors()
Returns a successor list by applying suitable operators but should not add any state to the successors list or set the successor list to this list. It MUST set the parent of each state so that cost of each child is meaningful.


show

public void show()
A display routine specific to the problem state. Override the toString property suitably for show and showPath to work. Obviously, both are available for overriding in case the display cannot be handled by toString or display is not directed to the console.



Hosted by www.Geocities.ws

1