Assignment Search Framework
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
OpenClosedList< state_t, action_t > Class Template Reference

Public Member Functions

 OpenClosedList ()
 
virtual ~OpenClosedList ()
 
void clear ()
 
StateLocation getStateLocation (const state_t &state, StateHash hash_value, NodeID &id)
 
BFSNode< state_t, action_t > & getNode (NodeID id)
 
const BFSNode< state_t,
action_t > & 
getNode (NodeID id) const
 
virtual NodeID addNewNodeToOpen (const state_t &state, const action_t &action, StateHash hash_value, double g, double h, double node_eval, NodeID parent)
 
virtual NodeID addInitialNodeToOpen (const state_t &state, const action_t &action, StateHash hash_value, double h, double node_eval)
 
virtual NodeID getBestNodeAndClose ()
 
virtual void openNodeEvalChanged (NodeID id)
 
virtual void reopenNode (NodeID id)
 
std::size_t openListSize () const
 
std::size_t closedListSize () const
 
std::size_t size () const
 
bool isOpenEmpty () const
 

Protected Member Functions

virtual bool nodeNoWorse (const BFSNode< state_t, action_t > &node_1, const BFSNode< state_t, action_t > &node_2) const
 
virtual bool nodeNoWorse (BFSOpenLocation loc_1, BFSOpenLocation loc_2) const
 
bool heapifyUp (BFSOpenLocation loc)
 
bool heapifyDown (BFSOpenLocation loc)
 
void swapOpenLocations (BFSOpenLocation loc_1, BFSOpenLocation loc_2)
 
void printOpen ()
 

Protected Attributes

NodeTable< BFSNode< state_t,
action_t > > 
node_table
 The table of nodes being stored. More...
 
std::vector< NodeIDopen_list_heap
 The heap holding node ids representing the open list. More...
 

Detailed Description

template<class state_t, class action_t>
class OpenClosedList< state_t, action_t >

A class for an open and closed list to be used by a best-first search.

Todo:

Make the NodeTable store pointers to BFSNode, so that it can creat things that inherit from them.

Make more generic for OCL algorithm.

Constructor & Destructor Documentation

template<class state_t , class action_t >
OpenClosedList< state_t, action_t >::OpenClosedList ( )
inline

Constructor for OpenClosedList. Does nothing.

template<class state_t , class action_t >
OpenClosedList< state_t, action_t >::~OpenClosedList ( )
inlinevirtual

Destructor for OpenClosedList. Does nothing.

Member Function Documentation

template<class state_t , class action_t >
NodeID OpenClosedList< state_t, action_t >::addInitialNodeToOpen ( const state_t &  state,
const action_t &  action,
StateHash  hash_value,
double  h,
double  node_eval 
)
inlinevirtual

Adds the initial node with the given attributes to the open list.

Parameters
stateThe state being added.
actionThe action that generated this state.
hash_valueThe hash value of this state.
hThe heuristic value of the node.
node_evalThe evaluation of the node.
Returns
The id of the node added.
template<class state_t , class action_t >
NodeID OpenClosedList< state_t, action_t >::addNewNodeToOpen ( const state_t &  state,
const action_t &  action,
StateHash  hash_value,
double  g,
double  h,
double  node_eval,
NodeID  parent 
)
virtual

Adds a new node with the given attributes to the open list.

Parameters
stateThe state being added.
actionThe action that generated this state.
hash_valueThe hash value of this state.
gThe g-cost of the node.
hThe heuristic value of the node.
node_evalThe evaluation of the node.
parentThe node id of the parent of this node, or 0 if this is the first node added.
Returns
The id of the node added.
template<class state_t , class action_t >
void OpenClosedList< state_t, action_t >::clear ( )

Clears the open closed list by emptying the table and heap.

template<class state_t , class action_t >
std::size_t OpenClosedList< state_t, action_t >::closedListSize ( ) const
inline

Returns the number of nodes in the closed list.

Returns
The size of the closed list.
template<class state_t , class action_t >
NodeID OpenClosedList< state_t, action_t >::getBestNodeAndClose ( )
virtual

Finds the best node in the open list according to the node evaluation, returns its id, and moves it to closed.

Returns
The node id of the best node on the open list.
template<class state_t , class action_t >
BFSNode< state_t, action_t > & OpenClosedList< state_t, action_t >::getNode ( NodeID  id)
inline

Returns the node corresponding to the given id.

Parameters
idThe id of the node to return.
Returns
The node corresponding to the given id.
template<class state_t , class action_t >
const BFSNode< state_t, action_t > & OpenClosedList< state_t, action_t >::getNode ( NodeID  id) const
inline

Returns a const reference to a node corresponding to the given id.

Parameters
idThe id of the node to return.
Returns
The node corresponding to the given id.
template<class state_t , class action_t >
StateLocation OpenClosedList< state_t, action_t >::getStateLocation ( const state_t &  state,
StateHash  hash_value,
NodeID id 
)

Returns whether the state is in the open list, closed list, or is not stored.

Parameters
stateThe state to check for.
hash_valueThe hash value of the state to check for.
idThe id of the state if it is found to be stored.
Returns
The location of the given state.
template<class state_t , class action_t >
bool OpenClosedList< state_t, action_t >::heapifyDown ( BFSOpenLocation  loc)
protected

Heapify's down the node at the given open list location if it needs to be moved down.

Parameters
locThe location to heapify down from.
Returns
If the node at the given location has been heapified down at least one level in the heap.
template<class state_t , class action_t >
bool OpenClosedList< state_t, action_t >::heapifyUp ( BFSOpenLocation  loc)
protected

Heapify's up the node at the given open list location if it needs to be moved up.

Parameters
locThe location to heapify up from.
Returns
If the node at the given location has been heapified up at least one level in the heap.
template<class state_t , class action_t >
bool OpenClosedList< state_t, action_t >::isOpenEmpty ( ) const
inline

Returns if the open list is empty or not.

Returns
If the open list is empty or not.
template<class state_t , class action_t >
bool OpenClosedList< state_t, action_t >::nodeNoWorse ( const BFSNode< state_t, action_t > &  node_1,
const BFSNode< state_t, action_t > &  node_2 
) const
inlineprotectedvirtual

Returns true if the evaluation of the first node is less than or equal to the second.

Parameters
node_1The first node being compared.
node_2The second node being compared.
Returns
If the evaluation of the first node is less than or equal to the second.
template<class state_t , class action_t >
bool OpenClosedList< state_t, action_t >::nodeNoWorse ( BFSOpenLocation  loc_1,
BFSOpenLocation  loc_2 
) const
inlineprotectedvirtual

Returns true if the evaluation of the node in the open list at the first location is less than or equal to the second.

Parameters
loc_1The location in the open list of the first node being compared.
loc_2The location in the open list of the second node being compared.
Returns
If the evaluation of the first node is less than or equal to the second.
template<class state_t , class action_t >
std::size_t OpenClosedList< state_t, action_t >::openListSize ( ) const
inline

Returns the number of nodes in the open list.

Returns
The size of the open list.
template<class state_t , class action_t >
void OpenClosedList< state_t, action_t >::openNodeEvalChanged ( NodeID  id)
virtual

Adjusts the open list as needed because the node evaluation of the node with the given id has changed.

Parameters
idThe id of the node whose evaluation has changed.
template<class state_t , class action_t >
void OpenClosedList< state_t, action_t >::printOpen ( )
protected
template<class state_t , class action_t >
void OpenClosedList< state_t, action_t >::reopenNode ( NodeID  id)
virtual

Reopens the node with the given id.

Parameters
idThe id of the node to reopen.
template<class state_t , class action_t >
std::size_t OpenClosedList< state_t, action_t >::size ( ) const
inline

Returns the total number of nodes being stored.

Returns
The number of nodes being stored.
template<class state_t , class action_t >
void OpenClosedList< state_t, action_t >::swapOpenLocations ( BFSOpenLocation  loc_1,
BFSOpenLocation  loc_2 
)
inlineprotected

Swaps the elements in their locations in the heaps at the given locations, and updates the nodes accordingly.

Parameters
loc_1The first location in the heap.
loc_2The second location in the heap.

Member Data Documentation

template<class state_t , class action_t >
NodeTable<BFSNode<state_t, action_t> > OpenClosedList< state_t, action_t >::node_table
protected

The table of nodes being stored.

template<class state_t , class action_t >
std::vector<NodeID> OpenClosedList< state_t, action_t >::open_list_heap
protected

The heap holding node ids representing the open list.


The documentation for this class was generated from the following file: