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

Public Member Functions

 MapPathfindingTransitions (bool four_dirs=true)
 
 MapPathfindingTransitions (std::string file_name, bool four_dirs=true)
 
virtual ~MapPathfindingTransitions ()
 
virtual bool isApplicable (const MapLocation &state, const MapDir &action) const
 
virtual double getActionCost (const MapLocation &state, const MapDir &action) const
 
virtual void applyAction (MapLocation &state, const MapDir &action) const
 
virtual void getActions (const MapLocation &state, std::vector< MapDir > &actions) const
 
virtual bool isInvertible (const MapLocation &state, const MapDir &action) const
 
virtual MapDir getInverse (const MapLocation &state, const MapDir &action) const
 
MapDir getDummyAction () const
 
bool isDummyAction (const MapDir &action) const
 
bool loadMap (std::string file_name)
 
unsigned getMapWidth () const
 
unsigned getMapHeight () const
 
void set4Connected ()
 
void set8Connected ()
 
bool setDiagonalCost (double d_cost)
 
bool is4Connected () const
 
bool is8Connected () const
 
void clearMap ()
 
- Public Member Functions inherited from TransitionSystem< MapLocation, MapDir >
 TransitionSystem ()
 
virtual ~TransitionSystem ()
 
virtual bool isChildState (const MapLocation &parent, const MapLocation &child) const
 
virtual void getSuccessors (const MapLocation &state, std::vector< MapLocation > &children) const
 
bool applyActionSequence (MapLocation &state, const std::vector< MapDir > &actions) const
 
bool isApplicableSequence (const MapLocation &state, const std::vector< MapDir > &actions) const
 

Protected Member Functions

bool canNorth (const MapLocation &state) const
 
bool canEast (const MapLocation &state) const
 
bool canSouth (const MapLocation &state) const
 
bool canWest (const MapLocation &state) const
 
bool isNEEmpty (const MapLocation &state) const
 
bool isSEEmpty (const MapLocation &state) const
 
bool isSWEmpty (const MapLocation &state) const
 
bool isNWEmpty (const MapLocation &state) const
 

Protected Attributes

unsigned map_width
 The map width. More...
 
unsigned map_height
 The map height. More...
 
bool four_connected
 If the map is 4-connected or 8-connected. More...
 
double diag_cost
 The cost of a diagonal move. More...
 
std::vector< std::vector< bool > > grid_empty
 Indexed by location, indicates if it is empty or an obstacle. More...
 

Detailed Description

Defines the transitions for map pathfinding.

Currently sets the origin (0,0) as the upper left corner in keeping with benchmark standard. Locations are either empty or have an obstacle. If the transition system is set as 4-connected, then movement is only possible in the 4 cardinal directions (North, East, South, and West). If it is not 4-connected, it is 8-connected, which means it is possible to move in the 4 cardinal directions as well as Northeast, Southeast, Southwest, and Northwest.

Todo:

Set the bottom left corner to be (0, 0)?

Allow for different terrain types.

Allow for different terrain heights.

Constructor & Destructor Documentation

MapPathfindingTransitions::MapPathfindingTransitions ( bool  four_dirs = true)

A constructor for a map pathfinding transition system. Constructs a completely empty map.

Parameters
four_dirsWhether the system is 4-connected. Set as true by default.
MapPathfindingTransitions::MapPathfindingTransitions ( std::string  file_name,
bool  four_dirs = true 
)

A constructor for a map pathfinding transition system. Loads in the map from the file from the given file name.

Parameters
file_nameThe name of the file to load the map from.
four_dirsWhether the system is 4-connected. Set as true by default.
MapPathfindingTransitions::~MapPathfindingTransitions ( )
virtual

A destructor for a map pathfinding transition system. Does nothing.

Member Function Documentation

void MapPathfindingTransitions::applyAction ( MapLocation state,
const MapDir 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< MapLocation, MapDir >.

bool MapPathfindingTransitions::canEast ( const MapLocation state) const
protected

Returns true of it is possible to move east from the current location.

Parameters
stateThe state currently located at.
Returns
If it is possible to move east from the given location.
bool MapPathfindingTransitions::canNorth ( const MapLocation state) const
protected

Returns true of it is possible to move north from the current location.

Parameters
stateThe state currently located at.
Returns
If it is possible to move north from the given location.
bool MapPathfindingTransitions::canSouth ( const MapLocation state) const
protected

Returns true of it is possible to move south from the current location.

Parameters
stateThe state currently located at.
Returns
If it is possible to move south from the given location.
bool MapPathfindingTransitions::canWest ( const MapLocation state) const
protected

Returns true of it is possible to move west from the current location.

Parameters
stateThe state currently located at.
Returns
If it is possible to move west from the given location.
void MapPathfindingTransitions::clearMap ( )

Clears the current map.

double MapPathfindingTransitions::getActionCost ( const MapLocation state,
const MapDir 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< MapLocation, MapDir >.

void MapPathfindingTransitions::getActions ( const MapLocation state,
std::vector< MapDir > &  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< MapLocation, MapDir >.

MapDir MapPathfindingTransitions::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< MapLocation, MapDir >.

MapDir MapPathfindingTransitions::getInverse ( const MapLocation state,
const MapDir 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< MapLocation, MapDir >.

unsigned MapPathfindingTransitions::getMapHeight ( ) const

Returns the height of the map.

Returns
The height of the map.
unsigned MapPathfindingTransitions::getMapWidth ( ) const

Returns the width of the map.

Returns
The width of the map.
bool MapPathfindingTransitions::is4Connected ( ) const

Checks if the given map is 4-connected.

Returns
If the map is set as 4-connected or 8-connected.
bool MapPathfindingTransitions::is8Connected ( ) const

Checks if the given map is 8-connected.

Returns
If the map is set as 8-connected or not.
bool MapPathfindingTransitions::isApplicable ( const MapLocation state,
const MapDir 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< MapLocation, MapDir >.

bool MapPathfindingTransitions::isDummyAction ( const MapDir 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< MapLocation, MapDir >.

bool MapPathfindingTransitions::isInvertible ( const MapLocation state,
const MapDir 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< MapLocation, MapDir >.

bool MapPathfindingTransitions::isNEEmpty ( const MapLocation state) const
protected

Checks if the location northeast of the given location is empty.

Parameters
stateThe state currently located at.
Returns
If the location northeast of the given location is empty.
bool MapPathfindingTransitions::isNWEmpty ( const MapLocation state) const
protected

Checks if the location northwest of the given location is empty.

Parameters
stateThe state currently located at.
Returns
If the location northwest of the given location is empty.
bool MapPathfindingTransitions::isSEEmpty ( const MapLocation state) const
protected

Checks if the location southeast of the given location is empty.

Parameters
stateThe state currently located at.
Returns
If the location southeast of the given location is empty.
bool MapPathfindingTransitions::isSWEmpty ( const MapLocation state) const
protected

Checks if the location southwest of the given location is empty.

Parameters
stateThe state currently located at.
Returns
If the location southwest of the given location is empty.
bool MapPathfindingTransitions::loadMap ( std::string  file_name)

Loads the map from the file with the given file name.

If reading fails, the map is cleared and false is returned.

The file format is as follows. There must be a line that contains only the word "map", which indicates that the remainder of the file is a representation of the map. An empty location is indicated by any of the symbols '.' 'G' or 'S'. An obstacle is indicated by any of the symbols '@', 'O', 'W', or 'T.' Any other symbol will cause an error.

Prior to the line that says map, there must be at least two lines, one of which is of the form "width n" and the other of which is "height m", where n and m are positive integers. These indicate the size of the map. The reading will fail if these are not included.

All other lines before the "map" line will be discarded.

Parameters
file_nameThe name of the file to read.
Returns
If the map loading succeeding or not.
void MapPathfindingTransitions::set4Connected ( )

Sets the map to be 4-connected.

void MapPathfindingTransitions::set8Connected ( )

Sets the map to be 8-connected.

bool MapPathfindingTransitions::setDiagonalCost ( double  d_cost)

Sets the cost of diagonal move (ie. northeast, southeast, southwest, or northwest). By default, set as square root two, as defined in floating_point_utils.h.

Ignores the given value if it is non-positive.

Parameters
d_costThe cost of a diagonal move.
Returns
If the diagonal value was set properly.

Member Data Documentation

double MapPathfindingTransitions::diag_cost
protected

The cost of a diagonal move.

bool MapPathfindingTransitions::four_connected
protected

If the map is 4-connected or 8-connected.

std::vector<std::vector<bool> > MapPathfindingTransitions::grid_empty
protected

Indexed by location, indicates if it is empty or an obstacle.

unsigned MapPathfindingTransitions::map_height
protected

The map height.

unsigned MapPathfindingTransitions::map_width
protected

The map width.


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