Algorithm
Development Kit 1.0

algs.model.searchtree
Class ClosedStates

java.lang.Object
  extended by algs.model.searchtree.ClosedStates
All Implemented Interfaces:
INodeSet, java.lang.Iterable<INode>

public class ClosedStates
extends java.lang.Object
implements INodeSet, java.lang.Iterable<INode>

Maintains the set of closed states in ordered fashion, so the state with the lowest evaluation function can be removed.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
ClosedStates()
           
 
Method Summary
 INode contains(INode n)
          Determine if the given state is contained.
 void insert(INode n)
          Insert the board state into the openStates.
 boolean isEmpty()
          Determine if open states is empty.
 java.util.Iterator<INode> iterator()
          Expose iterator to internal board states.
 INode remove()
          Not expected to be called since this is the closed list.
 boolean remove(INode n)
          Remove node from node set.
 int removeIfLowerScore(INode state)
          Remove state from list if its score is less than the score of the state as it exists within list.
 int size()
          Determine number of states in the set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClosedStates

public ClosedStates()
Method Detail

removeIfLowerScore

public int removeIfLowerScore(INode state)
Remove state from list if its score is less than the score of the state as it exists within list. Return -1 if the state wasn't on the list to begin with. Return 0 if the state is on the list and our score is higher or equal. Return +1 if the state was removed because its score was lowered.

Parameters:
state -

contains

public INode contains(INode n)
Determine if the given state is contained.

Returns the actual node as stored in the list (which may store additional storedData). Uses .equals as the comparator method.

Specified by:
contains in interface INodeSet
Parameters:
n -

insert

public void insert(INode n)
Insert the board state into the openStates.

Specified by:
insert in interface INodeSet
Parameters:
n -

isEmpty

public boolean isEmpty()
Determine if open states is empty.

Specified by:
isEmpty in interface INodeSet

size

public int size()
Determine number of states in the set.

Specified by:
size in interface INodeSet

iterator

public java.util.Iterator<INode> iterator()
Expose iterator to internal board states.

Specified by:
iterator in interface INodeSet
Specified by:
iterator in interface java.lang.Iterable<INode>

remove

public INode remove()
Not expected to be called since this is the closed list.

Specified by:
remove in interface INodeSet

remove

public boolean remove(INode n)
Description copied from interface: INodeSet
Remove node from node set.

The parameter is either an actual node in the node set or a copy of one of its nodes.

Specified by:
remove in interface INodeSet
Parameters:
n - Board state to be removed

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.