HOG2
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
MNPuzzle< width, height > Class Template Reference

#include <MNPuzzle.h>

Inheritance diagram for MNPuzzle< width, height >:
Inheritance graph
[legend]
Collaboration diagram for MNPuzzle< width, height >:
Collaboration graph
[legend]

Public Member Functions

 MNPuzzle ()
 
 MNPuzzle (const std::vector< slideDir > op_order)
 
 ~MNPuzzle ()
 
void SetWeighted (puzzleWeight w)
 
puzzleWeight GetWeighted () const
 
void GetSuccessors (const MNPuzzleState< width, height > &stateID, std::vector< MNPuzzleState< width, height >> &neighbors) const
 
void GetActions (const MNPuzzleState< width, height > &stateID, std::vector< slideDir > &actions) const
 
slideDir GetAction (const MNPuzzleState< width, height > &s1, const MNPuzzleState< width, height > &s2) const
 
slideDir GetAction (const MNPuzzleState< width, height > &l1, point3d p)
 
void ApplyAction (MNPuzzleState< width, height > &s, slideDir a) const
 
bool InvertAction (slideDir &a) const
 
OccupancyInterface< MNPuzzleState< width, height >, slideDir > * GetOccupancyInfo ()
 
double HCost (const MNPuzzleState< width, height > &state1, const MNPuzzleState< width, height > &state2) const
 
double HCost (const MNPuzzleState< width, height > &state1) const
 
double DefaultH (const MNPuzzleState< width, height > &s) const
 
double GCost (const MNPuzzleState< width, height > &state1, const MNPuzzleState< width, height > &state2) const
 
double GCost (const MNPuzzleState< width, height > &, const slideDir &) const
 
bool GoalTest (const MNPuzzleState< width, height > &state, const MNPuzzleState< width, height > &goal) const
 
bool GoalTest (const MNPuzzleState< width, height > &s) const
 
double AdditiveGCost (const MNPuzzleState< width, height > &, const slideDir &) const
 
bool InPattern (int tile) const
 
void SetPattern (const std::vector< int > &pattern)
 
void GetStateFromPDBHash (uint64_t hash, MNPuzzleState< width, height > &s, int count, const std::vector< int > &pattern, std::vector< int > &dual)
 
uint64_t GetActionHash (slideDir act) const
 
void OpenGLDraw () const
 
void OpenGLDraw (const MNPuzzleState< width, height > &s) const
 
void OpenGLDraw (const MNPuzzleState< width, height > &l1, const MNPuzzleState< width, height > &l2, float v) const
 
void OpenGLDraw (const MNPuzzleState< width, height > &, const slideDir &) const
 
void Draw (Graphics::Display &display, const MNPuzzleState< width, height > &) const
 
void Draw (Graphics::Display &display, const MNPuzzleState< width, height > &l1, const MNPuzzleState< width, height > &l2, float v) const
 
void StoreGoal (MNPuzzleState< width, height > &)
 
MNPuzzleState< width, heightGet_Goal ()
 Returns stored goal state if it is stored. More...
 
virtual const std::string GetName ()
 
void ClearGoal ()
 
bool IsGoalStored () const
 
GraphGetGraph ()
 
void Change_Op_Order (const std::vector< slideDir > op_order)
 Changes the ordering of operators to the new inputted order. More...
 
std::vector< slideDirGet_Op_Order ()
 
virtual void GetStateFromHash (MNPuzzleState< width, height > &s, uint64_t hash) const
 
uint64_t GetStateHash (const MNPuzzleState< width, height > &s) const
 
uint64_t GetMaxStateHash () const
 
bool State_Check (const MNPuzzleState< width, height > &to_check)
 Checks that the given state is a valid state for this domain. More...
 
unsigned Get_Num_Of_Columns ()
 
unsigned Get_Num_Of_Rows ()
 
void Set_Use_Manhattan_Heuristic (bool to_use)
 
- Public Member Functions inherited from PermutationPuzzle::PermutationPuzzleEnvironment< MNPuzzleState< width, height >, slideDir >
 PermutationPuzzleEnvironment ()
 
double HCost (const MNPuzzleState< width, height > &s) const
 
virtual double AdditiveGCost (const MNPuzzleState< width, height > &s, const slideDir &d)
 
void GetStateFromHash (MNPuzzleState< width, height > &s, uint64_t hash) const
 
uint64_t GetStateHash (const MNPuzzleState< width, height > &s) const
 
MNPuzzleState< width, heightTranformToStandardGoal (const MNPuzzleState< width, height > &a, const MNPuzzleState< width, height > &b) const
 
virtual void FinishUnranking (MNPuzzleState< width, height > &s) const
 
bool Validate_Problems (std::vector< MNPuzzleState< width, height > > &puzzles)
 

Static Public Member Functions

static unsigned GetParity (const MNPuzzleState< width, height > &state)
 
static void Create_Random_MN_Puzzles (MNPuzzleState< width, height > &goal, std::vector< MNPuzzleState< width, height >> &puzzle_vector, unsigned num_puzzles)
 Creates num_puzzles random MN puzzles of the specified size and stores them in puzzle-vector. More...
 
static int read_in_mn_puzzles (const char *filename, bool first_counter, unsigned max_puzzles, std::vector< MNPuzzleState< width, height >> &puzzle_vector)
 Reads in the the desired number of puzzles from the given filename with the given dimensions and stores them in puzzle_vector. More...
 
static std::vector< slideDirGet_Op_Order_From_Hash (int order_num)
 Returns a possible ordering of the operators. More...
 
static MNPuzzleState< width, heightGenerate_Random_Puzzle ()
 Randomly generates a puzzle of the specified dimensions and returns that puzzle. More...
 
- Static Public Member Functions inherited from PermutationPuzzle::PermutationPuzzleEnvironment< MNPuzzleState< width, height >, slideDir >
static uint64_t Hash (const MNPuzzleState< width, height > &s)
 
static bool Check_Permutation (const std::vector< int > &to_check)
 Ensures that the state contains a valid permutation. More...
 
static bool Output_Puzzles (std::vector< MNPuzzleState< width, height > > &puzzle_vector, bool write_puzz_num)
 Outputs the set of puzzles in puzzle_vector to standard output. More...
 
static bool Read_In_Permutations (const char *filename, unsigned size, unsigned max_puzzles, std::vector< std::vector< int > > &permutations, bool puzz_num_start)
 
static std::vector< int > Get_Random_Permutation (unsigned size)
 

Private Attributes

bool pattern [width *height]
 
std::vector< std::vector< slideDir > > operators
 
std::vector< slideDirops_in_order
 
bool goal_stored
 
bool use_manhattan
 
puzzleWeight weight
 
std::vector< std::vector< unsigned > > h_increment
 
MNPuzzleState< width, heightgoal
 

Additional Inherited Members

- Public Attributes inherited from PermutationPuzzle::PermutationPuzzleEnvironment< MNPuzzleState< width, height >, slideDir >
bool additive
 
int maxItem
 
int minPattern
 
std::vector< std::vector< uint8_t > > PDB
 
std::vector< std::vector< int > > PDB_distincts
 
std::vector< PDBTreeNodelookups
 
std::vector< std::vector< uint64_t > > factorialCache
 
MR1KPermutation mr1
 
- Protected Member Functions inherited from PermutationPuzzle::PermutationPuzzleEnvironment< MNPuzzleState< width, height >, slideDir >
uint64_t Factorial (int val) const
 
uint64_t nUpperk (int n, int k) const
 Returns the value of n! / k! More...
 

Detailed Description

template<int width, int height>
class MNPuzzle< width, height >

Definition at line 137 of file MNPuzzle.h.

Constructor & Destructor Documentation

◆ MNPuzzle() [1/2]

template<int width, int height>
MNPuzzle< width, height >::MNPuzzle

Definition at line 272 of file MNPuzzle.h.

References kUnitWeight.

◆ MNPuzzle() [2/2]

template<int width, int height>
MNPuzzle< width, height >::MNPuzzle ( const std::vector< slideDir op_order)

Definition at line 282 of file MNPuzzle.h.

References kUnitWeight.

◆ ~MNPuzzle()

template<int width, int height>
MNPuzzle< width, height >::~MNPuzzle

Definition at line 291 of file MNPuzzle.h.

Member Function Documentation

◆ AdditiveGCost()

template<int width, int height>
double MNPuzzle< width, height >::AdditiveGCost ( const MNPuzzleState< width, height > &  s,
const slideDir d 
) const

◆ ApplyAction()

template<int width, int height>
void MNPuzzle< width, height >::ApplyAction ( MNPuzzleState< width, height > &  s,
slideDir  a 
) const

◆ Change_Op_Order()

template<int width, int height>
void MNPuzzle< width, height >::Change_Op_Order ( const std::vector< slideDir op_order)

Changes the ordering of operators to the new inputted order.

Definition at line 297 of file MNPuzzle.h.

References height, kDown, kLeft, kRight, kUp, and width.

◆ ClearGoal()

template<int width, int height>
void MNPuzzle< width, height >::ClearGoal

Definition at line 536 of file MNPuzzle.h.

◆ Create_Random_MN_Puzzles()

template<int width, int height>
void MNPuzzle< width, height >::Create_Random_MN_Puzzles ( MNPuzzleState< width, height > &  goal,
std::vector< MNPuzzleState< width, height >> &  puzzle_vector,
unsigned  num_puzzles 
)
static

Creates num_puzzles random MN puzzles of the specified size and stores them in puzzle-vector.

All random puzzles are unique and solvable for the standard goal of 0, 1, 2, ..., MN - 1. The method assumes that num_puzzles is no bigger than the total number of solvable problems for that size.

Definition at line 1408 of file MNPuzzle.h.

References MNPuzzle< width, height >::GetStateHash(), height, and width.

◆ DefaultH()

template<int width, int height>
double MNPuzzle< width, height >::DefaultH ( const MNPuzzleState< width, height > &  s) const
virtual

◆ Draw() [1/2]

template<int width, int height>
void MNPuzzle< width, height >::Draw ( Graphics::Display display,
const MNPuzzleState< width, height > &  s 
) const

◆ Draw() [2/2]

template<int width, int height>
void MNPuzzle< width, height >::Draw ( Graphics::Display display,
const MNPuzzleState< width, height > &  l1,
const MNPuzzleState< width, height > &  l2,
float  v 
) const

◆ GCost() [1/2]

template<int width, int height>
double MNPuzzle< width, height >::GCost ( const MNPuzzleState< width, height > &  s,
const slideDir d 
) const

◆ GCost() [2/2]

template<int width, int height>
double MNPuzzle< width, height >::GCost ( const MNPuzzleState< width, height > &  state1,
const MNPuzzleState< width, height > &  state2 
) const

◆ Generate_Random_Puzzle()

template<int width, int height>
MNPuzzleState< width, height > MNPuzzle< width, height >::Generate_Random_Puzzle
static

Randomly generates a puzzle of the specified dimensions and returns that puzzle.

Definition at line 1229 of file MNPuzzle.h.

References MNPuzzleState< width, height >::blank, height, MNPuzzleState< width, height >::puzzle, and width.

◆ Get_Goal()

template<int width, int height>
MNPuzzleState<width, height> MNPuzzle< width, height >::Get_Goal ( )
inline

Returns stored goal state if it is stored.

Definition at line 184 of file MNPuzzle.h.

References MNPuzzle< width, height >::goal, and MNPuzzle< width, height >::goal_stored.

◆ Get_Num_Of_Columns()

template<int width, int height>
unsigned MNPuzzle< width, height >::Get_Num_Of_Columns ( )
inline

Definition at line 240 of file MNPuzzle.h.

References width.

◆ Get_Num_Of_Rows()

template<int width, int height>
unsigned MNPuzzle< width, height >::Get_Num_Of_Rows ( )
inline

Definition at line 241 of file MNPuzzle.h.

References height.

◆ Get_Op_Order()

template<int width, int height>
std::vector<slideDir> MNPuzzle< width, height >::Get_Op_Order ( )
inline

Definition at line 230 of file MNPuzzle.h.

References MNPuzzle< width, height >::ops_in_order.

◆ Get_Op_Order_From_Hash()

template<int width, int height>
std::vector< slideDir > MNPuzzle< width, height >::Get_Op_Order_From_Hash ( int  order_num)
static

Returns a possible ordering of the operators.

The orders are in a "lexicographic" with the original ordering being Up, Left, Right, Down. This is therefore the order returned with a call of order_num=0. This initial ordering is that used by Korf in his original IDA* experiments. The ordering originally used in HOG is returned with a call of order_num=15.

Definition at line 1460 of file MNPuzzle.h.

References kDown, kLeft, kRight, and kUp.

◆ GetAction() [1/2]

template<int width, int height>
slideDir MNPuzzle< width, height >::GetAction ( const MNPuzzleState< width, height > &  l1,
point3d  p 
)

◆ GetAction() [2/2]

template<int width, int height>
slideDir MNPuzzle< width, height >::GetAction ( const MNPuzzleState< width, height > &  s1,
const MNPuzzleState< width, height > &  s2 
) const

Definition at line 574 of file MNPuzzle.h.

References MNPuzzleState< width, height >::blank, height, kDown, kLeft, kRight, kUp, and width.

◆ GetActionHash()

template<int width, int height>
uint64_t MNPuzzle< width, height >::GetActionHash ( slideDir  act) const

Definition at line 904 of file MNPuzzle.h.

References kDown, kLeft, kRight, and kUp.

◆ GetActions()

template<int width, int height>
void MNPuzzle< width, height >::GetActions ( const MNPuzzleState< width, height > &  stateID,
std::vector< slideDir > &  actions 
) const

Definition at line 564 of file MNPuzzle.h.

References MNPuzzleState< width, height >::blank.

Referenced by STP::GetRandomInstance().

◆ GetGraph()

template<int width, int height>
Graph * MNPuzzle< width, height >::GetGraph

◆ GetMaxStateHash()

template<int width, int height>
uint64_t MNPuzzle< width, height >::GetMaxStateHash

Definition at line 1372 of file MNPuzzle.h.

References Factorial(), height, and width.

◆ GetName()

template<int width, int height>
const std::string MNPuzzle< width, height >::GetName
virtual

Definition at line 374 of file MNPuzzle.h.

References height, and width.

◆ GetOccupancyInfo()

template<int width, int height>
OccupancyInterface<MNPuzzleState<width, height>, slideDir>* MNPuzzle< width, height >::GetOccupancyInfo ( )
inline

Definition at line 152 of file MNPuzzle.h.

◆ GetParity()

template<int width, int height>
unsigned MNPuzzle< width, height >::GetParity ( const MNPuzzleState< width, height > &  state)
static

◆ GetStateFromHash()

template<int width, int height>
void MNPuzzle< width, height >::GetStateFromHash ( MNPuzzleState< width, height > &  s,
uint64_t  hash 
) const
virtual

◆ GetStateFromPDBHash()

template<int width, int height>
void MNPuzzle< width, height >::GetStateFromPDBHash ( uint64_t  hash,
MNPuzzleState< width, height > &  s,
int  count,
const std::vector< int > &  pattern,
std::vector< int > &  dual 
)

◆ GetStateHash()

template<int width, int height>
uint64_t MNPuzzle< width, height >::GetStateHash ( const MNPuzzleState< width, height > &  s) const

◆ GetSuccessors()

template<int width, int height>
void MNPuzzle< width, height >::GetSuccessors ( const MNPuzzleState< width, height > &  stateID,
std::vector< MNPuzzleState< width, height >> &  neighbors 
) const

Definition at line 551 of file MNPuzzle.h.

References MNPuzzleState< width, height >::blank.

◆ GetWeighted()

template<int width, int height>
puzzleWeight MNPuzzle< width, height >::GetWeighted ( ) const
inline

Definition at line 143 of file MNPuzzle.h.

References MNPuzzle< width, height >::weight.

◆ GoalTest() [1/2]

template<int width, int height>
bool MNPuzzle< width, height >::GoalTest ( const MNPuzzleState< width, height > &  s) const

Definition at line 530 of file MNPuzzle.h.

◆ GoalTest() [2/2]

template<int width, int height>
bool MNPuzzle< width, height >::GoalTest ( const MNPuzzleState< width, height > &  state,
const MNPuzzleState< width, height > &  goal 
) const

Definition at line 898 of file MNPuzzle.h.

◆ HCost() [1/2]

template<int width, int height>
double MNPuzzle< width, height >::HCost ( const MNPuzzleState< width, height > &  state1) const

Definition at line 671 of file MNPuzzle.h.

◆ HCost() [2/2]

template<int width, int height>
double MNPuzzle< width, height >::HCost ( const MNPuzzleState< width, height > &  state1,
const MNPuzzleState< width, height > &  state2 
) const

◆ InPattern()

template<int width, int height>
bool MNPuzzle< width, height >::InPattern ( int  tile) const

Definition at line 823 of file MNPuzzle.h.

◆ InvertAction()

template<int width, int height>
bool MNPuzzle< width, height >::InvertAction ( slideDir a) const

Definition at line 658 of file MNPuzzle.h.

References kDown, kLeft, kRight, and kUp.

◆ IsGoalStored()

template<int width, int height>
bool MNPuzzle< width, height >::IsGoalStored ( ) const
inline

Definition at line 196 of file MNPuzzle.h.

References MNPuzzle< width, height >::goal_stored.

◆ OpenGLDraw() [1/4]

template<int width, int height>
void MNPuzzle< width, height >::OpenGLDraw

Definition at line 948 of file MNPuzzle.h.

◆ OpenGLDraw() [2/4]

template<int width, int height>
void MNPuzzle< width, height >::OpenGLDraw ( const MNPuzzleState< width, height > &  ,
const slideDir  
) const
inline

Definition at line 176 of file MNPuzzle.h.

◆ OpenGLDraw() [3/4]

template<int width, int height>
void MNPuzzle< width, height >::OpenGLDraw ( const MNPuzzleState< width, height > &  l1,
const MNPuzzleState< width, height > &  l2,
float  v 
) const

◆ OpenGLDraw() [4/4]

template<int width, int height>
void MNPuzzle< width, height >::OpenGLDraw ( const MNPuzzleState< width, height > &  s) const

Definition at line 1093 of file MNPuzzle.h.

References DrawFrame(), DrawTile(), height, MNPuzzleState< width, height >::puzzle, and width.

◆ read_in_mn_puzzles()

template<int width, int height>
int MNPuzzle< width, height >::read_in_mn_puzzles ( const char *  filename,
bool  first_counter,
unsigned  max_puzzles,
std::vector< MNPuzzleState< width, height >> &  puzzle_vector 
)
static

Reads in the the desired number of puzzles from the given filename with the given dimensions and stores them in puzzle_vector.

Reads in MNPuzzle states from the given filename.

Only the first max_puzzles are stored. first_counter should be set to true if the first element on every row is the index of the puzzle. The input format is the entries in each of the puzzle positions separated by a space, with the optional index entry described above.

Each line of the input file contains a puzzle state of the given width and height. The state is written in the form of listing the tile in each puzzle position from 1 to width*height. The blank is represented by the 0 character.

If any line is found to not be legitimate, either because it does not have the proper number of tiles, or the proper tiles, it is simply not added to the list of puzzles.

The function will return 1 if reading from the given filename failed, and 0 otherwise.

puzz_num_start - should be set as true if the first non-whitespace element on each line is the puzzle number, otherwise should be set to false.

max_puzzles - the maximum number of puzzles that will be added to the puzzle list.

Definition at line 1170 of file MNPuzzle.h.

References MNPuzzleState< width, height >::blank, height, MNPuzzleState< width, height >::puzzle, and width.

◆ Set_Use_Manhattan_Heuristic()

template<int width, int height>
void MNPuzzle< width, height >::Set_Use_Manhattan_Heuristic ( bool  to_use)
inline

Definition at line 243 of file MNPuzzle.h.

References MNPuzzle< width, height >::use_manhattan.

◆ SetPattern()

template<int width, int height>
void MNPuzzle< width, height >::SetPattern ( const std::vector< int > &  pattern)

Definition at line 814 of file MNPuzzle.h.

References height, and width.

◆ SetWeighted()

template<int width, int height>
void MNPuzzle< width, height >::SetWeighted ( puzzleWeight  w)
inline

Definition at line 142 of file MNPuzzle.h.

References MNPuzzle< width, height >::weight.

◆ State_Check()

template<int width, int height>
bool MNPuzzle< width, height >::State_Check ( const MNPuzzleState< width, height > &  to_check)
virtual

Checks that the given state is a valid state for this domain.

Note, is not a check of solvability, just legality (ie. has the right size, dimensions). Note, this method should be a quick check that can be used for debugging purposes and so should not call Check_Permutation which is O(state size)

Implements PermutationPuzzle::PermutationPuzzleEnvironment< MNPuzzleState< width, height >, slideDir >.

Definition at line 1439 of file MNPuzzle.h.

References MNPuzzleState< width, height >::blank, height, MNPuzzleState< width, height >::puzzle, and width.

◆ StoreGoal()

template<int width, int height>
void MNPuzzle< width, height >::StoreGoal ( MNPuzzleState< width, height > &  s)

Definition at line 476 of file MNPuzzle.h.

References height, MNPuzzleState< width, height >::puzzle, and width.

Member Data Documentation

◆ goal

template<int width, int height>
MNPuzzleState<width, height> MNPuzzle< width, height >::goal
private

Definition at line 257 of file MNPuzzle.h.

Referenced by MNPuzzle< width, height >::Get_Goal().

◆ goal_stored

template<int width, int height>
bool MNPuzzle< width, height >::goal_stored
private

◆ h_increment

template<int width, int height>
std::vector<std::vector<unsigned> > MNPuzzle< width, height >::h_increment
private

Definition at line 256 of file MNPuzzle.h.

◆ operators

template<int width, int height>
std::vector<std::vector<slideDir> > MNPuzzle< width, height >::operators
private

Definition at line 249 of file MNPuzzle.h.

◆ ops_in_order

template<int width, int height>
std::vector<slideDir> MNPuzzle< width, height >::ops_in_order
private

Definition at line 250 of file MNPuzzle.h.

Referenced by MNPuzzle< width, height >::Get_Op_Order().

◆ pattern

template<int width, int height>
bool MNPuzzle< width, height >::pattern[width *height]
private

Definition at line 245 of file MNPuzzle.h.

◆ use_manhattan

template<int width, int height>
bool MNPuzzle< width, height >::use_manhattan
private

Definition at line 252 of file MNPuzzle.h.

Referenced by MNPuzzle< width, height >::Set_Use_Manhattan_Heuristic().

◆ weight

template<int width, int height>
puzzleWeight MNPuzzle< width, height >::weight
private

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