HOG2
|
#include <MNPuzzle.h>
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, height > | Get_Goal () |
Returns stored goal state if it is stored. More... | |
virtual const std::string | GetName () |
void | ClearGoal () |
bool | IsGoalStored () const |
Graph * | GetGraph () |
void | Change_Op_Order (const std::vector< slideDir > op_order) |
Changes the ordering of operators to the new inputted order. More... | |
std::vector< slideDir > | Get_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, height > | TranformToStandardGoal (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< slideDir > | Get_Op_Order_From_Hash (int order_num) |
Returns a possible ordering of the operators. More... | |
static MNPuzzleState< width, height > | Generate_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< slideDir > | ops_in_order |
bool | goal_stored |
bool | use_manhattan |
puzzleWeight | weight |
std::vector< std::vector< unsigned > > | h_increment |
MNPuzzleState< width, height > | goal |
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< PDBTreeNode > | lookups |
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... | |
Definition at line 137 of file MNPuzzle.h.
Definition at line 272 of file MNPuzzle.h.
References kUnitWeight.
MNPuzzle< width, height >::MNPuzzle | ( | const std::vector< slideDir > | op_order | ) |
Definition at line 282 of file MNPuzzle.h.
References kUnitWeight.
Definition at line 291 of file MNPuzzle.h.
double MNPuzzle< width, height >::AdditiveGCost | ( | const MNPuzzleState< width, height > & | s, |
const slideDir & | d | ||
) | const |
Definition at line 831 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, d, kDown, kLeft, kNoSlide, kRight, kUp, MNPuzzleState< width, height >::puzzle, and width.
void MNPuzzle< width, height >::ApplyAction | ( | MNPuzzleState< width, height > & | s, |
slideDir | a | ||
) | const |
Definition at line 592 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, kDown, kLeft, kRight, kUp, MNPuzzleState< width, height >::puzzle, MNPuzzleState< width, height >::size(), and width.
Referenced by STP::GetRandomInstance().
Definition at line 536 of file MNPuzzle.h.
|
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.
|
virtual |
Reimplemented from PermutationPuzzle::PermutationPuzzleEnvironment< MNPuzzleState< width, height >, slideDir >.
Definition at line 756 of file MNPuzzle.h.
References height, MNPuzzleState< width, height >::puzzle, and width.
void MNPuzzle< width, height >::Draw | ( | Graphics::Display & | display, |
const MNPuzzleState< width, height > & | s | ||
) | const |
Definition at line 956 of file MNPuzzle.h.
References Colors::blue, Colors::darkblue, Graphics::Display::DrawText(), Graphics::Display::FillRect(), Graphics::Display::FrameRect(), Colors::gray, height, Colors::lightgray, max, MNPuzzleState< width, height >::puzzle, Graphics::textAlignCenter, Graphics::textBaselineMiddle, Colors::white, and width.
void MNPuzzle< width, height >::Draw | ( | Graphics::Display & | display, |
const MNPuzzleState< width, height > & | l1, | ||
const MNPuzzleState< width, height > & | l2, | ||
float | v | ||
) | const |
Definition at line 1035 of file MNPuzzle.h.
References Colors::blue, Colors::darkblue, Graphics::Display::DrawText(), Graphics::Display::FillRect(), Graphics::Display::FrameRect(), Colors::gray, height, kDown, kLeft, kRight, kUp, Colors::lightgray, max, MNPuzzleState< width, height >::puzzle, Graphics::textAlignCenter, Graphics::textBaselineMiddle, Colors::white, width, Graphics::point::x, and Graphics::point::y.
double MNPuzzle< width, height >::GCost | ( | const MNPuzzleState< width, height > & | s, |
const slideDir & | d | ||
) | const |
Definition at line 845 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, d, kDown, kLeft, kRight, kSquared, kSquarePlusOneRoot, kSquareRoot, kUnitPlusFrac, kUnitWeight, kUp, MNPuzzleState< width, height >::puzzle, and width.
double MNPuzzle< width, height >::GCost | ( | const MNPuzzleState< width, height > & | state1, |
const MNPuzzleState< width, height > & | state2 | ||
) | const |
Definition at line 793 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, kSquared, kSquarePlusOneRoot, kSquareRoot, kUnitPlusFrac, kUnitWeight, and MNPuzzleState< width, height >::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.
|
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.
Definition at line 240 of file MNPuzzle.h.
References width.
Definition at line 241 of file MNPuzzle.h.
References height.
|
inline |
Definition at line 230 of file MNPuzzle.h.
References MNPuzzle< width, height >::ops_in_order.
|
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.
slideDir MNPuzzle< width, height >::GetAction | ( | const MNPuzzleState< width, height > & | l1, |
point3d | p | ||
) |
Definition at line 984 of file MNPuzzle.h.
References height, kNoSlide, max, Graphics::PointInRect(), MNPuzzleState< width, height >::puzzle, and width.
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.
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().
Definition at line 417 of file MNPuzzle.h.
References Graph::AddEdge(), Graph::AddNode(), Graph::FindEdge(), Graph::GetNode(), GetStateFromHash(), GraphSearchConstants::kXCoordinate, GraphSearchConstants::kYCoordinate, GraphSearchConstants::kZCoordinate, and node::SetLabelF().
Definition at line 1372 of file MNPuzzle.h.
References Factorial(), height, and width.
Definition at line 374 of file MNPuzzle.h.
|
inline |
Definition at line 152 of file MNPuzzle.h.
|
static |
Definition at line 1382 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, height, MNPuzzleState< width, height >::puzzle, and width.
|
virtual |
Definition at line 1245 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, height, MNPuzzleState< width, height >::puzzle, and width.
void MNPuzzle< width, height >::GetStateFromPDBHash | ( | uint64_t | hash, |
MNPuzzleState< width, height > & | s, | ||
int | count, | ||
const std::vector< int > & | pattern, | ||
std::vector< int > & | dual | ||
) |
Definition at line 917 of file MNPuzzle.h.
References MNPuzzleState< width, height >::blank, and MNPuzzleState< width, height >::puzzle.
uint64_t MNPuzzle< width, height >::GetStateHash | ( | const MNPuzzleState< width, height > & | s | ) | const |
Definition at line 1334 of file MNPuzzle.h.
References Factorial(), height, MNPuzzleState< width, height >::puzzle, and width.
Referenced by MNPuzzle< width, height >::Create_Random_MN_Puzzles().
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.
|
inline |
Definition at line 143 of file MNPuzzle.h.
References MNPuzzle< width, height >::weight.
bool MNPuzzle< width, height >::GoalTest | ( | const MNPuzzleState< width, height > & | s | ) | const |
Definition at line 530 of file MNPuzzle.h.
bool MNPuzzle< width, height >::GoalTest | ( | const MNPuzzleState< width, height > & | state, |
const MNPuzzleState< width, height > & | goal | ||
) | const |
Definition at line 898 of file MNPuzzle.h.
double MNPuzzle< width, height >::HCost | ( | const MNPuzzleState< width, height > & | state1 | ) | const |
Definition at line 671 of file MNPuzzle.h.
double MNPuzzle< width, height >::HCost | ( | const MNPuzzleState< width, height > & | state1, |
const MNPuzzleState< width, height > & | state2 | ||
) | const |
Definition at line 677 of file MNPuzzle.h.
References height, kSquared, kSquarePlusOneRoot, kSquareRoot, kUnitPlusFrac, kUnitWeight, max, MNPuzzleState< width, height >::puzzle, and width.
Definition at line 823 of file MNPuzzle.h.
Definition at line 196 of file MNPuzzle.h.
References MNPuzzle< width, height >::goal_stored.
Definition at line 948 of file MNPuzzle.h.
|
inline |
Definition at line 176 of file MNPuzzle.h.
void MNPuzzle< width, height >::OpenGLDraw | ( | const MNPuzzleState< width, height > & | l1, |
const MNPuzzleState< width, height > & | l2, | ||
float | v | ||
) | const |
Definition at line 1114 of file MNPuzzle.h.
References DrawFrame(), DrawTile(), height, kDown, kLeft, kRight, kUp, MNPuzzleState< width, height >::puzzle, and width.
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.
|
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.
|
inline |
Definition at line 243 of file MNPuzzle.h.
References MNPuzzle< width, height >::use_manhattan.
void MNPuzzle< width, height >::SetPattern | ( | const std::vector< int > & | pattern | ) |
Definition at line 814 of file MNPuzzle.h.
|
inline |
Definition at line 142 of file MNPuzzle.h.
References MNPuzzle< width, height >::weight.
|
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.
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.
|
private |
Definition at line 257 of file MNPuzzle.h.
Referenced by MNPuzzle< width, height >::Get_Goal().
Definition at line 251 of file MNPuzzle.h.
Referenced by MNPuzzle< width, height >::Get_Goal(), and MNPuzzle< width, height >::IsGoalStored().
|
private |
Definition at line 256 of file MNPuzzle.h.
|
private |
Definition at line 249 of file MNPuzzle.h.
|
private |
Definition at line 250 of file MNPuzzle.h.
Referenced by MNPuzzle< width, height >::Get_Op_Order().
Definition at line 245 of file MNPuzzle.h.
Definition at line 252 of file MNPuzzle.h.
Referenced by MNPuzzle< width, height >::Set_Use_Manhattan_Heuristic().
|
private |
Definition at line 253 of file MNPuzzle.h.
Referenced by MNPuzzle< width, height >::GetWeighted(), and MNPuzzle< width, height >::SetWeighted().