9 #ifndef MR1PermutationPDB_h
10 #define MR1PermutationPDB_h
24 template <
class state,
class action,
class environment,
int bits = 8>
27 MR1PermutationPDB(environment *e,
const state &s,
const std::vector<int> &distincts);
29 virtual uint64_t
GetPDBHash(
const state &s,
int threadID = 0)
const;
46 template <
class state,
class action,
class environment,
int bits>
53 inline void swap(
int &a,
int &b)
60 template <
class state,
class action,
class environment,
int bits>
63 std::vector<int> &locs = locsCache[threadID];
64 std::vector<int> &dual = dualCache[threadID];
65 std::vector<int> &values = valueStack[threadID];
66 locs.resize(example.size());
67 dual.resize(example.size());
69 memset(&locs[0], 0xFF, locs.size()*
sizeof(locs[0]));
70 memset(&dual[0], 0xFF, dual.size()*
sizeof(dual[0]));
71 int puzzleSize = (int)example.size();
74 for (
unsigned int x = 0; x < puzzleSize; x++)
76 if (s.puzzle[x] != -1)
77 dual[s.puzzle[x]] = x;
80 for (
size_t x = 0; x < distinct.size(); x++)
82 locs[puzzleSize-x-1] = dual[distinct[distinct.size()-x-1]];
85 memset(&dual[0], 0xFF, dual.size()*
sizeof(dual[0]));
87 for (
int x = puzzleSize-distinct.size(); x < puzzleSize; x++)
92 size_t last = puzzleSize-distinct.size();
93 for (
size_t i = puzzleSize; i > last; i--)
95 values.push_back(locs[i-1]);
99 swap(locs[i-1], locs[dual[i-1]]);
100 swap(dual[values.back()], dual[i-1]);
108 while (values.size() > 0)
111 result += values.back();
118 template <
class state,
class action,
class environment,
int bits>
121 int puzzleSize = (int)example.size();
123 std::vector<int> &dual = dualCache[threadID];
124 dual.resize(puzzleSize);
125 for (
size_t x = 0; x < dual.size(); x++)
128 size_t last = (puzzleSize-distinct.size());
129 memset(&s.puzzle[0], 0xFF, puzzleSize*
sizeof(s.puzzle[0]));
131 for (
size_t i = puzzleSize; i > last; i--)
133 swap(dual[hash%i], dual[i-1]);
135 s.puzzle[dual[i-1]] = distinct[i-last-1];
140 template <
class state,
class action,
class environment,
int bits>
143 std::string fileName;
146 if (fileName.back() !=
'/' && prefix[0] != 0)
149 fileName +=
"-MR1.pdb";