Assignment Search Framework
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
TilePuzzleTransitions Class Reference
Inheritance diagram for TilePuzzleTransitions:

Public Member Functions

 TilePuzzleTransitions (unsigned rows, unsigned cols, TileCostType cost=TileCostType::unit)
 
 TilePuzzleTransitions (unsigned rows, unsigned cols, const std::vector< double > &tile_costs)
 
virtual ~TilePuzzleTransitions ()
 
virtual bool isApplicable (const TilePuzzleState &state, const BlankSlide &action) const
 
virtual double getActionCost (const TilePuzzleState &state, const BlankSlide &action) const
 
virtual void applyAction (TilePuzzleState &state, const BlankSlide &action) const
 
virtual void getActions (const TilePuzzleState &state, std::vector< BlankSlide > &actions) const
 
virtual bool isInvertible (const TilePuzzleState &state, const BlankSlide &action) const
 
virtual BlankSlide getInverse (const TilePuzzleState &state, const BlankSlide &action) const
 
BlankSlide getDummyAction () const
 
bool isDummyAction (const BlankSlide &action) const
 
void setStandardTileCostType (const TileCostType cost_type)
 
void setCustomTileCostType (const std::vector< double > &tile_costs)
 
void setProperties (unsigned rows, unsigned cols, TileCostType cost_type=TileCostType::unit)
 
void setProperties (unsigned rows, unsigned cols, const std::vector< double > &tile_costs)
 
double getTileMoveCost (unsigned tile) const
 
- Public Member Functions inherited from TransitionSystem< TilePuzzleState, BlankSlide >
 TransitionSystem ()
 
virtual ~TransitionSystem ()
 
virtual bool isChildState (const TilePuzzleState &parent, const TilePuzzleState &child) const
 
virtual void getSuccessors (const TilePuzzleState &state, std::vector< TilePuzzleState > &children) const
 
bool applyActionSequence (TilePuzzleState &state, const std::vector< BlankSlide > &actions) const
 
bool isApplicableSequence (const TilePuzzleState &state, const std::vector< BlankSlide > &actions) const
 

Protected Member Functions

void setActionList (unsigned rows, unsigned cols)
 
bool isApplicableInLocation (const BlankSlide &action, unsigned blank_loc) const
 
unsigned getMovingTile (const TilePuzzleState &state, const BlankSlide &action) const
 

Protected Attributes

unsigned num_rows
 Number of rows in the puzzle. More...
 
unsigned num_cols
 Number of columns in the puzzle. More...
 
std::vector< std::vector
< BlankSlide > > 
loc_actions
 Caches the actions applicable for each blank location. More...
 
std::vector< BlankSlideops_in_order
 An ordering of all the possible actions. More...
 
std::vector< double > tile_move_cost
 Caches the cost of moving each tile. More...
 

Detailed Description

Defines the transition system for the sliding tile puzzle.

Todo:

Add operator ordering options.

Check what the default operator ordering should be.

Constructor & Destructor Documentation

TilePuzzleTransitions::TilePuzzleTransitions ( unsigned  rows,
unsigned  cols,
TileCostType  cost = TileCostType::unit 
)

Builds a tile puzzle transition system with the given number of rows, columns, and cost type.

Parameters
rowsThe number of rows in the puzzle.
colsThe number of columns in the puzzle.
costThe action cost type.
TilePuzzleTransitions::TilePuzzleTransitions ( unsigned  rows,
unsigned  cols,
const std::vector< double > &  tile_costs 
)

Builds a tile puzzle transition system with the given number of rows, columns, and custom tile cost type.

The custom tile cost type is defined as list of numbers, where the value at index i is the cost of moving tile i. The value at index 0 is ignored.

Parameters
rowsThe number of rows in the puzzle.
colsThe number of columns in the puzzle.
tile_costsA list defining the custom tile cost.
TilePuzzleTransitions::~TilePuzzleTransitions ( )
virtual

Destructor for tile puzzle transition system. Destructor is empty.

Member Function Documentation

void TilePuzzleTransitions::applyAction ( TilePuzzleState state,
const BlankSlide action 
) const
virtual

Applies the given action to the given state.

Assumes the given action is applicable in the given state.

Parameters
stateThe state to update.
actionThe action to apply.

Implements TransitionSystem< TilePuzzleState, BlankSlide >.

double TilePuzzleTransitions::getActionCost ( const TilePuzzleState state,
const BlankSlide action 
) const
virtual

Returns the cost of applying the given action in the given state.

Assumes the action is actually applicable in that state.

Parameters
stateThe state to apply the action in.
actionThe action to apply.
Returns
The cost of applying the action in the given state.

Implements TransitionSystem< TilePuzzleState, BlankSlide >.

void TilePuzzleTransitions::getActions ( const TilePuzzleState state,
std::vector< BlankSlide > &  actions 
) const
virtual

Gets the actions applicable in a given state and appends them to the given list.

Parameters
stateThe state to generate actions in.
actionsThe list of actions to append to.

Implements TransitionSystem< TilePuzzleState, BlankSlide >.

BlankSlide TilePuzzleTransitions::getDummyAction ( ) const
virtual

Returns the dummy action for this domain.

The dummy action should never actually be applicable and is not invertible.

Returns
The domain's dummy action.

Implements TransitionSystem< TilePuzzleState, BlankSlide >.

BlankSlide TilePuzzleTransitions::getInverse ( const TilePuzzleState state,
const BlankSlide action 
) const
virtual

Returns the inverse of a given action.

If no inverse exists, returns the dummy action.

Parameters
stateThe state the action is being applied in.
actionThe action to invert.
Returns
The inverse of the given action.

Reimplemented from TransitionSystem< TilePuzzleState, BlankSlide >.

unsigned TilePuzzleTransitions::getMovingTile ( const TilePuzzleState state,
const BlankSlide action 
) const
protected

Gets the identity of the tile being moved by the given action.

Assumes the action is applicable in the given state.

Parameters
stateThe state in which the move is being applied.
actionThe action to apply.
Returns
The identity of the tile being moved.
double TilePuzzleTransitions::getTileMoveCost ( unsigned  tile) const

Returns the cost of moving the specified tile.

Parameters
tileThe tile to move.
Returns
The cost of moving the given tile.
bool TilePuzzleTransitions::isApplicable ( const TilePuzzleState state,
const BlankSlide action 
) const
virtual

Checks if the action is applicable in the given state.

Parameters
stateThe state in the domain.
actionThe action to test for applicability.
Returns
If the given action is applicable in the given state.

Reimplemented from TransitionSystem< TilePuzzleState, BlankSlide >.

bool TilePuzzleTransitions::isApplicableInLocation ( const BlankSlide action,
unsigned  blank_loc 
) const
protected

Checks if the given action is applicable given the current location of the blank.

Parameters
actionThe action to check.
blank_locThe location of the blank.
Returns
If the given action is applicable given where the blank currently is.
bool TilePuzzleTransitions::isDummyAction ( const BlankSlide action) const
virtual

Checks if the given action is the dummy action for this domain.

Parameters
actionThe action to check.
Returns
If the given action is the dummy action.

Implements TransitionSystem< TilePuzzleState, BlankSlide >.

bool TilePuzzleTransitions::isInvertible ( const TilePuzzleState state,
const BlankSlide action 
) const
virtual

Checks if the given action is invertible in the given state.

Assumes the action is either the dummy action, or is applicable in the given state.

Parameters
stateThe state the action is being applied in.
actionThe action to check.
Returns
If the action is invertible.

Reimplemented from TransitionSystem< TilePuzzleState, BlankSlide >.

void TilePuzzleTransitions::setActionList ( unsigned  rows,
unsigned  cols 
)
protected

Caches the set of actions applicable for each location of the blank.

Actions are generated according to the operator ordering currently in use.

Parameters
rowsThe number of rows in the puzzle.
colsThe number of columns in the puzzle.
void TilePuzzleTransitions::setCustomTileCostType ( const std::vector< double > &  tile_costs)

Sets the tile_costs to a custom cost type.

The function takes in a list of double values, such that the value at index i is the cost of moving tile i.

Parameters
tile_costsA list of the tile costs.
void TilePuzzleTransitions::setProperties ( unsigned  rows,
unsigned  cols,
TileCostType  cost_type = TileCostType::unit 
)

Sets the properties of the problem, including a cost type selected from the standard options.

Parameters
rowsThe number of rows.
colsThe number of columns.
cost_typeThe action cost type.
void TilePuzzleTransitions::setProperties ( unsigned  rows,
unsigned  cols,
const std::vector< double > &  tile_costs 
)

Sets the properties of the problem, including a custom tile cost type.

Parameters
rowsThe number of rows.
colsThe number of columns.
tile_costsA list of numbers defining the cost of moving each tile.
void TilePuzzleTransitions::setStandardTileCostType ( const TileCostType  cost_type)

Sets the tile costs to one of the standard types.

Parameters
cost_typeThe cost type for the transitions.

Member Data Documentation

std::vector<std::vector<BlankSlide> > TilePuzzleTransitions::loc_actions
protected

Caches the actions applicable for each blank location.

unsigned TilePuzzleTransitions::num_cols
protected

Number of columns in the puzzle.

unsigned TilePuzzleTransitions::num_rows
protected

Number of rows in the puzzle.

std::vector<BlankSlide> TilePuzzleTransitions::ops_in_order
protected

An ordering of all the possible actions.

std::vector<double> TilePuzzleTransitions::tile_move_cost
protected

Caches the cost of moving each tile.


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