9 #ifndef LexPermutationPDB_h
10 #define LexPermutationPDB_h
18 template <
class state,
class action,
class environment,
int bits = 8>
21 LexPermutationPDB(environment *e,
const state &s,
const std::vector<int> &distincts);
22 LexPermutationPDB(environment *e,
const std::vector<state> &s,
const std::vector<int> &distincts);
23 virtual uint64_t
GetPDBHash(
const state &s,
int threadID = 0)
const;
44 template <
class state,
class action,
class environment,
int bits>
51 template <
class state,
class action,
class environment,
int bits>
58 template <
class state,
class action,
class environment,
int bits>
61 std::vector<int> &locs = locsCache[threadID];
62 std::vector<int> &dual = dualCache[threadID];
64 locs.resize(distinct.size());
65 dual.resize(s.size());
68 for (
unsigned int x = 0; x < s.size(); x++)
70 if (s.puzzle[x] != -1)
71 dual[s.puzzle[x]] = x;
73 for (
size_t x = 0; x < distinct.size(); x++)
75 locs[x] = dual[distinct[x]];
79 int numEntriesLeft = (int)s.size();
81 for (
unsigned int x = 0; x < locs.size(); x++)
83 hashVal += locs[x]*FactorialUpperK(numEntriesLeft-1, s.size()-distinct.size());
87 for (
unsigned y = x; y < locs.size(); y++)
89 if (locs[y] > locs[x])
96 template <
class state,
class action,
class environment,
int bits>
99 uint64_t hashVal = hash;
100 std::vector<int> &dual = dualCache[threadID];
102 dual.resize(distinct.size());
104 int numEntriesLeft = puzzleSize-distinct.size()+1;
105 for (
int x = distinct.size()-1; x >= 0; x--)
107 dual[x] = hashVal%numEntriesLeft;
108 hashVal /= numEntriesLeft;
110 for (
size_t y = x+1; y < distinct.size(); y++)
112 if (dual[y] >= dual[x])
117 std::fill(&s.puzzle[0], &s.puzzle[s.size()], -1);
118 for (
int x = 0; x < dual.size(); x++)
119 s.puzzle[dual[x]] = distinct[x];
125 int numEntriesLeft = 1;
126 for (
int x = count-1; x >= 0; x--)
128 pieces[x] = hash%numEntriesLeft;
129 hash /= numEntriesLeft;
131 for (
int y = x+1; y < count; y++)
140 template <
class state,
class action,
class environment,
int bits>
143 static uint64_t table[21] =
144 { 1ll, 1ll, 2ll, 6ll, 24ll, 120ll, 720ll, 5040ll, 40320ll, 362880ll, 3628800ll, 39916800ll, 479001600ll,
145 6227020800ll, 87178291200ll, 1307674368000ll, 20922789888000ll, 355687428096000ll,
146 6402373705728000ll, 121645100408832000ll, 2432902008176640000ll };
152 template <
class state,
class action,
class environment,
int bits>
155 std::string fileName;
158 if (fileName.back() !=
'/' && prefix[0] != 0)
161 fileName +=
"-lex.pdb";
166 template <
class state,
class action,
class environment,
int bits>
170 assert(n >= 0 && k >= 0);
172 for (
int i = n; i > k; i--)