9 #ifndef hog2_glut_PermutationPDB_h
10 #define hog2_glut_PermutationPDB_h
18 template <
class state,
class action,
class environment,
int bits = 8>
21 PermutationPDB(environment *e,
const state &s,
const std::vector<int> &distincts);
25 virtual uint64_t
GetPDBHash(
const state &s,
int threadID = 0)
const = 0;
27 virtual uint64_t
GetAbstractHash(
const state &s,
int threadID = 0)
const = 0;
32 bool Load(
const char *prefix);
33 void Save(
const char *prefix);
34 virtual std::string
GetFileName(
const char *prefix);
46 template <
class state,
class action,
class environment,
int bits>
48 :
PDBHeuristic<state, action, environment, state,
bits>(e), distinct(distincts), puzzleSize(s.size()), example(s)
51 for (
int x = (
int)s.size(); x > s.size()-distincts.size(); x--)
57 template <
class state,
class action,
class environment,
int bits>
64 template <
class state,
class action,
class environment,
int bits>
70 if (fileName.back() !=
'/' && prefix[0] != 0)
74 for (
size_t x = 0; x < PDBHeuristic<state, action, environment, state, bits>::goalState.size(); x++)
81 for (
size_t x = 0; x < distinct.size(); x++)
83 fileName += std::to_string(distinct[x]);
88 fileName += std::to_string(
bits);
93 template <
class state,
class action,
class environment,
int bits>
96 FILE *f = fopen(GetFileName(prefix).c_str(),
"r+");
99 printf(
"Unable to open for loading '%s'\n", GetFileName(prefix).c_str());
102 bool result = Load(f);
107 template <
class state,
class action,
class environment,
int bits>
110 FILE *f = fopen(GetFileName(prefix).c_str(),
"w+");
113 fprintf(stderr,
"Error saving");
120 template <
class state,
class action,
class environment,
int bits>
127 if (fread(&puzzleSize,
sizeof(puzzleSize), 1, f) != 1)
129 if (fread(&pdbSize,
sizeof(pdbSize), 1, f) != 1)
131 if (fread(&example,
sizeof(example), 1, f) != 1)
133 size_t distinctSize = distinct.size();
134 if (fread(&distinctSize,
sizeof(distinctSize), 1, f) != 1)
136 distinct.resize(distinctSize);
137 if (fread(&distinct[0],
sizeof(distinct[0]), distinct.size(), f) != distinctSize)
142 template <
class state,
class action,
class environment,
int bits>
146 fwrite(&puzzleSize,
sizeof(puzzleSize), 1, f);
147 fwrite(&pdbSize,
sizeof(pdbSize), 1, f);
148 fwrite(&example,
sizeof(example), 1, f);
149 size_t distinctSize = distinct.size();
150 fwrite(&distinctSize,
sizeof(distinctSize), 1, f);
151 fwrite(&distinct[0],
sizeof(distinct[0]), distinct.size(), f);
154 template <
class state,
class action,
class environment,
int bits>
158 assert(n >= 0 && k >= 0);
160 for (
int i = n; i > k; i--)