9 #ifndef hog2_glut_PDBHeuristic_h
10 #define hog2_glut_PDBHeuristic_h
38 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state = abstractState, u
int64_t pdbBits = 8>
52 void SetGoal(
const std::vector<state> &goals)
64 virtual double HCost(
const state &a,
const state &b)
const;
68 virtual uint64_t
GetPDBHash(
const abstractState &s,
int threadID = 0)
const = 0;
69 virtual uint64_t
GetAbstractHash(
const state &s,
int threadID = 0)
const = 0;
70 virtual void GetStateFromPDBHash(uint64_t hash, abstractState &s,
int threadID = 0)
const = 0;
73 virtual bool Load(
const char *prefix) = 0;
74 virtual void Save(
const char *prefix) = 0;
75 virtual bool Load(FILE *f);
76 virtual void Save(FILE *f);
77 virtual std::string
GetFileName(
const char *prefix) = 0;
82 void BuildPDB(
const state &goal,
int numThreads)
85 void BuildPDBForward(
const std::vector<state> &goal,
int numThreads,
bool useCoarseOpen =
true,
bool verbose =
false);
89 void BuildAdditivePDB(
const state &goal,
int numThreads,
bool useCourseOpen =
true);
93 void ModCompress(uint64_t newEntries,
bool print_histogram);
95 {
for (uint64_t s = 0; s <
PDB.
Size(); s++)
103 void ValueCompress(std::vector<int> cutoffs,
bool print_histogram);
134 std::vector<bool> &coarse,
139 std::vector<std::pair<abstractState, int>> &neighbors);
143 std::vector<bool> &coarse,
149 std::vector<bool> &coarse,
155 std::vector<bool> &coarseOpen,
156 std::vector<bool> &coarseClosed,
162 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
169 return PDB.Get(GetAbstractHash(a));
173 return PDB.Get(GetAbstractHash(a)/compressionValue);
177 return PDB.Get(GetAbstractHash(a)%compressionValue);
181 return vrcValues[PDB.Get(GetAbstractHash(a))];
185 return vrcValues[PDB.Get(GetAbstractHash(a)/compressionValue)];
188 assert(!
"Not implemented");
192 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
197 uint64_t COUNT = GetPDBSize();
201 uint64_t entries = goalState.size();
202 std::cout <<
"Num Entries: " << COUNT << std::endl;
203 std::cout <<
"Goal State: " << goalState[0] << std::endl;
205 std::cout <<
"PDB Hash of Goal: " << GetPDBHash(goalState[0]) << std::endl;
207 std::vector<abstractAction> acts;
211 for (
auto &i : goalState)
212 PDB.Set(GetPDBHash(i), 0);
215 uint64_t newEntries = 0;
216 abstractState s(goal), u(goal);
221 for (uint64_t i = 0; i < COUNT; i++)
223 if (PDB.Get(i) == depth)
225 GetStateFromPDBHash(i, s);
226 env->GetActions(s, acts);
227 for (
size_t y = 0; y < acts.size(); y++)
229 env->GetNextState(s, acts[y], u);
230 assert(env->InvertAction(acts[y]) ==
true);
232 uint64_t nextRank = GetPDBHash(u);
233 int newCost = depth+(env->GCost(u, acts[y]));
234 if (PDB.Get(nextRank) > newCost)
236 PDB.Set(nextRank, newCost);
244 printf(
"Depth %d complete; %1.2fs elapsed. %" PRId64
" new states written; %" PRId64
" of %" PRId64
" total\n",
245 depth, timer.
EndTimer(), total, entries, COUNT);
247 }
while (entries != COUNT);
249 printf(
"%1.2fs elapsed\n", t.
EndTimer());
250 if (entries != COUNT)
252 printf(
"Entries: %" PRId64
"; count: %" PRId64
"\n", entries, COUNT);
253 assert(entries == COUNT);
258 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
261 std::vector<state> tmp;
263 BuildPDBForward(tmp, numThreads, useCoarseOpen,
verbose);
266 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
274 uint64_t COUNT = GetPDBSize();
283 uint64_t entries = goalState.size();
284 std::cout <<
"Num Entries: " << COUNT << std::endl;
285 std::cout <<
"Goal State: " << goalState[0] << std::endl;
287 std::cout <<
"PDB Hash of Goal: " << GetPDBHash(goalState[0]) << std::endl;
289 std::deque<state> q_curr, q_next;
290 std::vector<state> children;
294 for (
auto &i : goalState)
296 PDB.Set(GetPDBHash(i), 0);
297 coarseOpenCurr[GetPDBHash(i)/
coarseSize] =
true;
302 std::vector<std::thread*> threads(numThreads);
303 printf(
"Creating %d threads\n", numThreads);
312 uint64_t smallestDepth = (1<<pdbBits)-1;
313 for (uint64_t x = 0; x < COUNT; x++)
315 uint64_t next = PDB.Get(x);
316 if (next >= depth && next < smallestDepth)
317 smallestDepth = next;
319 depth = smallestDepth;
322 for (
int x = 0; x < numThreads; x++)
326 x, depth, std::ref(PDB), std::ref(coarseOpenNext),
327 &workQueue, &resultQueue, &lock);
330 for (uint64_t x = 0; x < COUNT; x+=
coarseSize)
332 if ((useCoarseOpen && coarseOpenCurr[x/
coarseSize]) || !useCoarseOpen)
338 for (
int x = 0; x < numThreads; x++)
342 for (
int x = 0; x < numThreads; x++)
352 while (resultQueue.
Remove(val))
360 printf(
"Depth %d complete; %1.2fs elapsed. %" PRId64
" new states written; %" PRId64
" of %" PRId64
" total\n",
361 depth, s.
EndTimer(), total, entries, COUNT);
363 coarseOpenCurr.swap(coarseOpenNext);
364 }
while (entries != COUNT);
367 printf(
"%1.2fs elapsed\n", t.
EndTimer());
368 if (entries != COUNT)
371 printf(
"Entries: %" PRId64
"; count: %" PRId64
"\n", entries, COUNT);
372 assert(entries == COUNT);
378 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
386 uint64_t COUNT = GetPDBSize();
394 uint64_t entries = goalState.size();
395 std::cout <<
"Num Entries: " << COUNT << std::endl;
396 std::cout <<
"Goal State: " << goalState[0] << std::endl;
398 std::cout <<
"PDB Hash of Goal: " << GetPDBHash(goalState[0]) << std::endl;
400 std::deque<state> q_curr, q_next;
401 std::vector<state> children;
405 for (
auto &i : goalState)
406 PDB.Set(GetPDBHash(i), 0);
410 std::vector<std::thread*> threads(numThreads);
411 printf(
"Creating %d threads\n", numThreads);
416 for (
int x = 0; x < numThreads; x++)
420 x, depth, std::ref(PDB), std::ref(coarseClosed),
421 &workQueue, &resultQueue, &lock);
423 for (uint64_t x = 0; x < COUNT; x+=
coarseSize)
430 for (
int x = 0; x < numThreads; x++)
434 for (
int x = 0; x < numThreads; x++)
444 while (resultQueue.
Remove(val))
451 printf(
"Depth %d complete; %1.2fs elapsed. %" PRId64
" new states written; %" PRId64
" of %" PRId64
" total\n",
452 depth, s.
EndTimer(), total, entries, COUNT);
454 }
while (entries != COUNT);
456 printf(
"%1.2fs elapsed\n", t.
EndTimer());
457 if (entries != COUNT)
459 printf(
"Entries: %" PRId64
"; count: %" PRId64
"\n", entries, COUNT);
460 assert(entries == COUNT);
465 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
473 uint64_t COUNT = GetPDBSize();
483 uint64_t entries = goalState.size();
484 std::cout <<
"Num Entries: " << COUNT << std::endl;
485 std::cout <<
"Goal State: " << goalState[0] << std::endl;
487 std::cout <<
"PDB Hash of Goal: " << GetPDBHash(goalState[0]) << std::endl;
489 std::deque<state> q_curr, q_next;
490 std::vector<state> children;
491 std::vector<uint64_t> distribution;
496 for (
auto &i : goalState)
498 PDB.Set(GetPDBHash(i), 0);
499 coarseOpenCurr[GetPDBHash(i)/
coarseSize] =
true;
502 distribution.push_back(cnt);
505 bool searchForward =
true;
506 std::vector<std::thread*> threads(numThreads);
507 printf(
"Creating %d threads\n", numThreads);
511 for (
int x = 0; x < numThreads; x++)
515 x, depth, searchForward,
516 std::ref(PDB), std::ref(coarseOpenNext), std::ref(coarseClosed),
517 &workQueue, &resultQueue, &lock);
521 for (uint64_t x = 0; x < COUNT; x+=
coarseSize)
531 for (uint64_t x = 0; x < COUNT; x+=
coarseSize)
540 for (
int x = 0; x < numThreads; x++)
544 for (
int x = 0; x < numThreads; x++)
554 while (resultQueue.
Remove(val))
560 distribution.push_back(total);
561 printf(
"Depth %d complete; %1.2fs elapsed. %" PRId64
" new states written; %" PRId64
" of %" PRId64
" total [%s]\n",
562 depth, s.
EndTimer(), total, entries, COUNT, searchForward?
"forward":
"backward");
563 if (
double(total)*
double(total)*0.4 >
double(COUNT-entries)*
double(distribution[distribution.size()-2]))
564 searchForward =
false;
565 if (COUNT-entries <= total)
566 searchForward =
false;
568 coarseOpenCurr.swap(coarseOpenNext);
569 }
while (entries != COUNT);
571 printf(
"%1.2fs elapsed\n", t.
EndTimer());
572 if (entries != COUNT)
574 printf(
"Entries: %" PRId64
"; count: %" PRId64
"\n", entries, COUNT);
575 assert(entries == COUNT);
581 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
584 std::vector<bool> &coarse,
593 std::pair<uint64_t, uint64_t> p;
595 std::vector<abstractAction> acts;
596 abstractState s(goalState[0]), t(goalState[0]);
603 std::vector<writeInfo> cache;
607 if (p.first == p.second)
614 for (uint64_t x = start; x < end; x++)
616 int stateDepth = DB.
Get(x);
617 if (stateDepth == depth)
619 GetStateFromPDBHash(x, s, threadNum);
621 env->GetActions(s, acts);
622 for (
int y = 0; y < acts.size(); y++)
624 env->GetNextState(s, acts[y], t);
625 assert(env->InvertAction(acts[y]) ==
true);
628 uint64_t nextRank = GetPDBHash(t, threadNum);
629 int newCost = stateDepth+(env->GCost(t, acts[y]));
630 cache.push_back({nextRank, newCost});
638 if (
d.newGCost < DB.
Get(
d.rank))
640 if (DB.
Get(
d.rank) == (1<<pdbBits)-1)
643 DB.
Set(
d.rank,
d.newGCost);
655 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
658 std::vector<bool> &coarse,
663 std::pair<uint64_t, uint64_t> p;
665 std::vector<abstractAction> acts;
666 abstractState s(goalState[0]), t(goalState[0]);
668 int blankEntries = 0;
673 std::vector<writeInfo> cache;
677 if (p.first == p.second)
685 for (uint64_t x = start; x < end; x++)
687 int stateDepth = DB.
Get(x);
688 if (stateDepth == ((1<<pdbBits)-1))
691 GetStateFromPDBHash(x, s, threadNum);
693 env->GetActions(s, acts);
694 for (
int y = 0; y < acts.size(); y++)
696 env->GetNextState(s, acts[y], t);
700 uint64_t nextRank = GetPDBHash(t, threadNum);
701 if (DB.
Get(nextRank) == depth)
703 int newCost = depth+(env->GCost(t, acts[y]));
704 cache.push_back({x, newCost});
712 if (cache.size() > 0)
716 if (blankEntries == 0)
720 if (
d.newGCost < DB.
Get(
d.rank))
723 DB.
Set(
d.rank,
d.newGCost);
733 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
736 std::vector<bool> &coarseOpen,
737 std::vector<bool> &coarseClosed,
742 std::pair<uint64_t, uint64_t> p;
744 std::vector<abstractAction> acts;
745 abstractState s(goalState[0]), t(goalState[0]);
747 int blankEntries = 0;
752 std::vector<writeInfo> cache;
755 bool allEntriesWritten;
759 if (p.first == p.second)
766 allEntriesWritten =
true;
767 for (uint64_t x = start; x < end; x++)
769 int stateDepth = DB.
Get(x);
770 if (stateDepth > depth)
771 allEntriesWritten =
false;
772 if (stateDepth == depth)
774 GetStateFromPDBHash(x, s, threadNum);
776 env->GetActions(s, acts);
777 for (
size_t y = 0; y < acts.size(); y++)
779 env->GetNextState(s, acts[y], t);
780 assert(env->InvertAction(acts[y]) ==
true);
783 uint64_t nextRank = GetPDBHash(t, threadNum);
784 int newCost = stateDepth+(env->GCost(t, acts[y]));
785 cache.push_back({nextRank, newCost});
791 if (allEntriesWritten)
795 if (
d.newGCost < DB.
Get(
d.rank))
799 DB.
Set(
d.rank,
d.newGCost);
810 if (p.first == p.second)
818 for (uint64_t x = start; x < end; x++)
820 int stateDepth = DB.
Get(x);
821 if (stateDepth == ((1<<pdbBits)-1))
824 GetStateFromPDBHash(x, s, threadNum);
826 env->GetActions(s, acts);
827 for (
size_t y = 0; y < acts.size(); y++)
829 env->GetNextState(s, acts[y], t);
833 uint64_t nextRank = GetPDBHash(t, threadNum);
834 if (DB.
Get(nextRank) == depth)
836 int newCost = depth+(env->GCost(t, acts[y]));
837 cache.push_back({x, newCost});
845 if (cache.size() > 0)
849 if (blankEntries == 0)
853 if (
d.newGCost < DB.
Get(
d.rank))
856 DB.
Set(
d.rank,
d.newGCost);
867 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
875 uint64_t COUNT = GetPDBSize();
884 uint64_t entries = goalState.size();
885 std::cout <<
"Num Entries: " << COUNT << std::endl;
886 std::cout <<
"Goal State: " << goalState[0] << std::endl;
888 std::cout <<
"PDB Hash of Goal: " << GetPDBHash(goalState[0]) << std::endl;
890 std::deque<state> q_curr, q_next;
891 std::vector<state> children;
895 for (
auto &i : goalState)
897 PDB.Set(GetPDBHash(i), 0);
898 coarseOpenCurr[GetPDBHash(i)/
coarseSize] =
true;
902 std::vector<std::thread*> threads(numThreads);
903 printf(
"Creating %d threads\n", numThreads);
908 for (
int x = 0; x < numThreads; x++)
912 x, depth, std::ref(PDB), std::ref(coarseOpenNext),
913 &workQueue, &resultQueue, &lock);
916 for (uint64_t x = 0; x < COUNT; x+=
coarseSize)
918 if (!useCourseOpen || coarseOpenCurr[x/
coarseSize])
924 for (
int x = 0; x < numThreads; x++)
928 for (
int x = 0; x < numThreads; x++)
938 while (resultQueue.
Remove(val))
945 printf(
"Depth %d complete; %1.2fs elapsed. %" PRId64
" new states written; %" PRId64
" of %" PRId64
" total\n",
946 depth, s.
EndTimer(), total, entries, COUNT);
948 coarseOpenCurr.swap(coarseOpenNext);
963 }
while (entries != COUNT);
965 printf(
"%1.2fs elapsed\n", t.
EndTimer());
966 if (entries != COUNT)
968 printf(
"Entries: %" PRId64
"; count: %" PRId64
"\n", entries, COUNT);
969 assert(entries == COUNT);
974 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
977 std::vector<bool> &coarse,
982 std::pair<uint64_t, uint64_t> p;
984 std::vector<abstractAction> acts;
985 std::vector<std::pair<abstractState, int>> neighbors;
986 abstractState s(goalState[0]), t(goalState[0]);
993 std::vector<writeInfo> cache;
994 std::vector<uint64_t> zeroCostNeighbors;
998 if (p.first == p.second)
1004 for (uint64_t x = start; x < end; x++)
1006 int stateDepth = DB.
Get(x);
1007 if (stateDepth == depth)
1009 GetStateFromPDBHash(x, s, threadNum);
1011 env->GetActions(s, acts);
1013 for (
size_t y = 0; y < acts.size(); y++)
1015 env->GetNextState(s, acts[y], t);
1016 assert(env->InvertAction(acts[y]) ==
true);
1019 uint64_t nextRank = GetPDBHash(t, threadNum);
1020 int newCost = stateDepth+(env->AdditiveGCost(t, acts[y]));
1021 cache.push_back({nextRank, newCost});
1028 for (
auto d : cache)
1030 auto val = DB.
Get(
d.rank);
1031 if (
d.newGCost < val)
1036 DB.
Set(
d.rank,
d.newGCost);
1037 if (
d.newGCost == depth)
1038 zeroCostNeighbors.push_back(
d.rank);
1044 for (
auto i : zeroCostNeighbors)
1046 GetStateFromPDBHash(i, s, threadNum);
1047 env->GetActions(s, acts);
1049 for (
size_t y = 0; y < acts.size(); y++)
1051 env->GetNextState(s, acts[y], t);
1052 assert(env->InvertAction(acts[y]) ==
true);
1055 uint64_t nextRank = GetPDBHash(t, threadNum);
1056 int newCost = depth+(env->AdditiveGCost(t, acts[y]));
1057 cache.push_back({nextRank, newCost});
1061 zeroCostNeighbors.clear();
1062 }
while (cache.size() > 0);
1064 results->
Add(count);
1074 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1080 compressionValue = factor;
1082 PDB.Resize((PDB.Size()+compressionValue-1)/compressionValue);
1084 for (uint64_t x = 0; x < copy.
Size(); x++)
1086 uint64_t newIndex = x/compressionValue;
1087 PDB.Set(newIndex,
std::min(copy.
Get(x), PDB.Get(newIndex)));
1089 if (print_histogram)
1093 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1096 ModCompress((PDB.Size()+factor-1)/factor, print_histogram);
1099 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1103 compressionValue = newEntries;
1105 PDB.Resize(compressionValue);
1107 for (uint64_t x = 0; x < copy.
Size(); x++)
1109 uint64_t newIndex = x%compressionValue;
1110 PDB.Set(newIndex,
std::min(copy.
Get(x), PDB.Get(newIndex)));
1112 if (print_histogram)
1116 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1121 for (
size_t x = 0; x < PDB.Size(); x++)
1123 GetStateFromPDBHash(x, s);
1124 s1 = GetStateFromAbstractState(s);
1125 PDB.Set(x, PDB.Get(x) - h->
HCost(s1, goal));
1127 if (print_histogram)
1131 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1134 assert(!
"Not currently implemented.");
1137 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1140 assert(!
"Not currently implemented.");
1143 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1146 assert(!
"Not currently implemented.");
1149 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1152 std::vector<uint64_t> dist;
1153 if (print_histogram)
1155 printf(
"Setting boundaries [%d values]: ", cutoffs.size());
1156 for (
int x = 0; x < cutoffs.size(); x++)
1157 printf(
"%d ", cutoffs[x]);
1160 cutoffs.push_back(256);
1162 for (uint64_t x = 0; x < PDB.Size(); x++)
1164 for (
int y = 0; y < cutoffs.size(); y++)
1166 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1169 PDB.Set(x, cutoffs[y]);
1174 if (print_histogram)
1178 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1181 std::vector<int> cutoffs;
1183 if (print_histogram)
1185 printf(
"Setting boundaries [%d values]: ", (1<<numBits));
1186 for (
size_t x = 0; x < cutoffs.size(); x++)
1187 printf(
"%d ", cutoffs[x]);
1190 cutoffs.push_back(256);
1192 for (uint64_t x = 0; x < PDB.Size(); x++)
1194 for (
size_t y = 0; y < cutoffs.size(); y++)
1196 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1199 PDB.Set(x, cutoffs[y]);
1204 if (print_histogram)
1208 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1211 std::vector<uint64_t> dist;
1212 std::vector<int> cutoffs;
1215 if (print_histogram)
1217 printf(
"Setting boundaries [%d values]: ", (1<<numBits));
1218 for (
int x = 0; x < cutoffs.size(); x++)
1219 printf(
"%d ", cutoffs[x]);
1222 cutoffs.push_back(256);
1224 for (uint64_t x = 0; x < PDB.Size(); x++)
1226 for (
int y = 0; y < cutoffs.size(); y++)
1228 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1231 PDB.Set(x, cutoffs[y]);
1236 if (print_histogram)
1240 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1243 bool print_histogram)
1245 std::vector<uint64_t> dist;
1246 std::vector<int> cutoffs;
1249 if (print_histogram)
1251 printf(
"Setting boundaries [%d values]: ", (1<<4));
1252 for (
int x = 0; x < cutoffs.size(); x++)
1253 printf(
"%d ", cutoffs[x]);
1264 printf(
"Unknown PDB type: %d\n", type);
1266 for (
int x = 0; x < cutoffs.size(); x++)
1269 cutoffs.push_back(256);
1270 for (uint64_t x = 0; x < PDB.Size(); x++)
1272 for (
int y = 0; y < cutoffs.size(); y++)
1274 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1282 if (print_histogram)
1286 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1289 bool print_histogram)
1291 std::vector<uint64_t> dist;
1292 std::vector<int> cutoffs;
1295 if (print_histogram)
1297 printf(
"Setting boundaries [%d values]: ", (1<<4));
1298 for (
int x = 0; x < cutoffs.size(); x++)
1299 printf(
"%d ", cutoffs[x]);
1310 printf(
"Unknown PDB type: %d\n", type);
1312 for (
int x = 0; x < cutoffs.size(); x++)
1315 cutoffs.push_back(256);
1316 for (uint64_t x = 0; x < PDB.Size(); x++)
1318 for (
int y = 0; y < cutoffs.size(); y++)
1320 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1328 if (print_histogram)
1332 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1335 std::vector<uint64_t> dist;
1336 std::vector<int> cutoffs;
1339 if (print_histogram)
1341 printf(
"Setting boundaries [%d values]: ", (1<<4));
1342 for (
int x = 0; x < cutoffs.size(); x++)
1343 printf(
"%d ", cutoffs[x]);
1354 printf(
"Unknown PDB type: %d\n", type);
1357 for (
int x = 0; x < cutoffs.size(); x++)
1360 cutoffs.push_back(256);
1361 for (uint64_t x = 0; x < PDB.Size(); x++)
1363 for (
int y = 0; y < cutoffs.size(); y++)
1365 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1373 if (print_histogram)
1378 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1381 std::vector<uint64_t> dist;
1382 std::vector<int> cutoffs;
1385 if (print_histogram)
1387 printf(
"Setting boundaries [%d values]: ", (1<<4));
1388 for (
size_t x = 0; x < cutoffs.size(); x++)
1389 printf(
"%d ", cutoffs[x]);
1400 printf(
"Unknown PDB type: %d\n", type);
1403 for (
size_t x = 0; x < cutoffs.size(); x++)
1406 cutoffs.push_back(256);
1407 for (uint64_t x = 0; x < PDB.Size(); x++)
1409 for (
size_t y = 0; y < cutoffs.size(); y++)
1411 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1419 if (print_histogram)
1424 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1427 std::vector<uint64_t> dist;
1428 std::vector<int> cutoffs;
1431 if (print_histogram)
1433 printf(
"Setting boundaries [%d values]: ", (1<<4));
1434 for (
size_t x = 0; x < cutoffs.size(); x++)
1435 printf(
"%d ", cutoffs[x]);
1446 printf(
"Unknown PDB type: %d\n", type);
1449 for (
int x = 0; x < cutoffs.size(); x++)
1452 cutoffs.push_back(256);
1453 for (uint64_t x = 0; x < PDB.Size(); x++)
1455 for (
size_t y = 0; y < cutoffs.size(); y++)
1457 if (PDB.Get(x) >= cutoffs[y] && PDB.Get(x) < cutoffs[y+1])
1465 if (print_histogram)
1471 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1474 if (fread(&type,
sizeof(type), 1, f) != 1)
1476 goalState.resize(0);
1477 if (fread(&goalState[0],
sizeof(goalState[0]), 1, f) != 1)
1482 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1485 fwrite(&type,
sizeof(type), 1, f);
1486 fwrite(&goalState[0],
sizeof(goalState[0]), 1, f);
1490 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1493 histogram.resize(0);
1494 for (uint64_t x = 0; x < PDB.Size(); x++)
1496 if (PDB.Get(x)+1 > histogram.size())
1498 histogram.resize(PDB.Get(x)+1);
1500 histogram[PDB.Get(x)]++;
1504 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1509 factor = compressionValue;
1511 std::vector<uint64_t> histogram;
1514 for (uint64_t x = 0; x < PDB.Size(); x++)
1516 if (vrcValues[PDB.Get(x)]+1 > histogram.size())
1518 histogram.resize(vrcValues[PDB.Get(x)]+1);
1520 histogram[vrcValues[PDB.Get(x)]]+=factor;
1521 average += vrcValues[PDB.Get(x)];
1525 for (uint64_t x = 0; x < PDB.Size(); x++)
1527 if (PDB.Get(x)+1 > histogram.size())
1529 histogram.resize(PDB.Get(x)+1);
1531 histogram[PDB.Get(x)]+=factor;
1532 average += PDB.Get(x);
1535 for (
size_t x = 0; x < histogram.size(); x++)
1537 if (histogram[x] > 0)
1538 printf(
"%d: %" PRId64
"\n", (
int)x, histogram[x]);
1540 printf(
"Average: %f; count: %" PRId64
"\n", average/PDB.Size(), PDB.Size());
1541 return average/PDB.Size();
1544 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1548 for (uint64_t x = 0; x < PDB.Size(); x++)
1550 average += PDB.Get(x);
1552 return average/PDB.Size();
1555 template <
class abstractState,
class abstractAction,
class abstractEnvironment,
class state, u
int64_t pdbBits>
1558 for (uint64_t x = PDB.Size(); x > 0; x--)
1560 uint64_t index = (((uint64_t)random()<<32)^(uint64_t)random())%(x);
1561 uint64_t tmp = PDB.Get(x-1);
1562 PDB.Set(x-1, PDB.Get(index));
1563 PDB.Set(index, tmp);