From 41d17d45b2a8380c2ff4b7a92771a79bd939dedc Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Wed, 15 Oct 2025 11:54:31 +0300 Subject: [PATCH 01/11] change 2 arguments with the same name --- search/TreePermutationPDB.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/TreePermutationPDB.h b/search/TreePermutationPDB.h index b8aa77508..427c07e41 100644 --- a/search/TreePermutationPDB.h +++ b/search/TreePermutationPDB.h @@ -42,7 +42,7 @@ class TreePermutationPDB : public PermutationPDB > locsCache; mutable std::vector > tempCache; - state example; + state st; }; inline int mylog2(int val) From 660b2570f2df6dadc833f374e659b7419e668836 Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Wed, 15 Oct 2025 12:40:16 +0300 Subject: [PATCH 02/11] TreePermutationPDB.h change --- search/TreePermutationPDB.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/search/TreePermutationPDB.h b/search/TreePermutationPDB.h index 427c07e41..5d3b5bf81 100644 --- a/search/TreePermutationPDB.h +++ b/search/TreePermutationPDB.h @@ -10,6 +10,8 @@ #define TreePermutationPDB_h #include "PermutationPDB.h" +#include + /** * This class does the basic permutation calculation in lexicographical order. @@ -22,14 +24,14 @@ class TreePermutationPDB : public PermutationPDB &distincts); - virtual uint64_t GetPDBHash(const state &s, int threadID = 0) const; - virtual void GetStateFromPDBHash(uint64_t hash, state &s, int threadID = 0) const; - virtual uint64_t GetAbstractHash(const state &s, int threadID = 0) const { return GetPDBHash(s); } - virtual state GetStateFromAbstractState(state &s) { return s; } + virtual uint64_t GetPDBHash(const state &s, int threadID = 0) const override; + virtual void GetStateFromPDBHash(uint64_t hash, state &s, int threadID = 0) const override; + virtual uint64_t GetAbstractHash(const state &s, int threadID = 0) const override { return GetPDBHash(s); } + virtual state GetStateFromAbstractState(state &s) const override { return s; } - std::string GetFileName(const char *prefix); + std::string GetFileName(const char *prefix) override; private: - using PermutationPDB::example; + // using PermutationPDB::example; using PermutationPDB::distinct; uint64_t Factorial(int val) const; @@ -42,7 +44,7 @@ class TreePermutationPDB : public PermutationPDB > locsCache; mutable std::vector > tempCache; - state st; + state goalState; }; inline int mylog2(int val) @@ -100,7 +102,7 @@ uint64_t TreePermutationPDB::GetPDBHash(const std::vector &values = locsCache[threadID]; std::vector &dual = dualCache[threadID]; // TODO: test definition - values.resize(distinct.size()); // vector for distinct item locations + values.resize(this->distinct.size()); // vector for distinct item locations dual.resize(s.puzzle.size()); // vector for distinct item locations // find item locations @@ -109,7 +111,7 @@ uint64_t TreePermutationPDB::GetPDBHash(const if (s.puzzle[x] != -1) dual[s.puzzle[x]] = x; } - for (int x = 0; x < distinct.size(); x++) + for (int x = 0; x < this->distinct.size(); x++) { values[x] = dual[distinct[x]]; } @@ -153,8 +155,8 @@ void TreePermutationPDB::GetStateFromPDBHash(u temp[x] = (1<<(k-mylog2(x+2)+1)); std::vector &values = locsCache[threadID]; - values.resize(distinct.size()); - int numEntriesLeft = s.puzzle.size()-distinct.size()+1; + values.resize(this->distinct.size()); + int numEntriesLeft = (int)s.puzzle.size()-(int)this->distinct.size()+1; for (int x = (int)values.size()-1; x >= 0; x--) { values[x] = hash%numEntriesLeft; @@ -182,7 +184,7 @@ void TreePermutationPDB::GetStateFromPDBHash(u } temp[node] = 0; values[x] = node - (1<distinct[x]; } s.FinishUnranking(); } From 795e4eade69be5bba9d84227ff2f2917be7c931c Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Wed, 15 Oct 2025 12:43:27 +0300 Subject: [PATCH 03/11] TreePermutationPDB.h change --- search/TreePermutationPDB.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/search/TreePermutationPDB.h b/search/TreePermutationPDB.h index 5d3b5bf81..17f54364b 100644 --- a/search/TreePermutationPDB.h +++ b/search/TreePermutationPDB.h @@ -31,7 +31,7 @@ class TreePermutationPDB : public PermutationPDB::example; + //using PermutationPDB::example; using PermutationPDB::distinct; uint64_t Factorial(int val) const; @@ -146,7 +146,7 @@ uint64_t TreePermutationPDB::GetPDBHash(const template void TreePermutationPDB::GetStateFromPDBHash(uint64_t hash, state &s, int threadID) const { - size_t count = example.puzzle.size(); + size_t count = goalState.puzzle.size(); s.puzzle.resize(count); int k = mylog2(count); std::vector &temp = tempCache[threadID]; From 4a8494a4d8ab00f54dbb4b97f5406b6a5d91c559 Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Wed, 15 Oct 2025 13:07:44 +0300 Subject: [PATCH 04/11] change MNPuzzle.h --- environments/MNPuzzle.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/environments/MNPuzzle.h b/environments/MNPuzzle.h index 9d8a5d5cc..3938251d0 100644 --- a/environments/MNPuzzle.h +++ b/environments/MNPuzzle.h @@ -12,15 +12,15 @@ #include #include -#include "SearchEnvironment.h" +#include "../search/SearchEnvironment.h" #include "PermutationPuzzleEnvironment.h" -#include "UnitSimulation.h" +#include "../simulation/UnitSimulation.h" #include "GraphEnvironment.h" -#include "Graph.h" +#include "../graph/Graph.h" #include "GraphEnvironment.h" #include #include -#include "LexPermutationPDB.h" +#include "../search/LexPermutationPDB.h" enum puzzleWeight { kDWSTP, @@ -839,6 +839,7 @@ double MNPuzzle::DCost(const MNPuzzleState &state1 } } hval = std::max(hval, man_dist); + return hval; } template @@ -1012,8 +1013,11 @@ void MNPuzzle::GetStateFromPDBHash(uint64_t hash, MNPuzzleState static_cast(s.puzzle.size())) + count = static_cast(s.puzzle.size()); for (int x = 0; x < dual.size(); x++) { s.puzzle[dual[x]] = pattern[x]; From 0746240081b5870720b90f33ed209d6e65db1032 Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Wed, 15 Oct 2025 13:11:46 +0300 Subject: [PATCH 05/11] PermutationPuzzleEnvironment.h change --- environments/PermutationPuzzleEnvironment.h | 46 ++++++++++----------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/environments/PermutationPuzzleEnvironment.h b/environments/PermutationPuzzleEnvironment.h index cec7cc394..ac00dbcb2 100644 --- a/environments/PermutationPuzzleEnvironment.h +++ b/environments/PermutationPuzzleEnvironment.h @@ -7,11 +7,11 @@ #include #include #include -#include "SearchEnvironment.h" -#include "Timer.h" -#include "SharedQueue.h" -#include "RangeCompression.h" -#include "MR1Permutation.h" +#include "../search/SearchEnvironment.h" +#include "../utils/Timer.h" +#include "../utils/SharedQueue.h" +#include "../utils/RangeCompression.h" +#include "../utils/MR1Permutation.h" #ifndef PERMPUZZ_H #define PERMPUZZ_H @@ -1357,30 +1357,28 @@ namespace PermutationPuzzle { n, each of the integers from 0 to n-1 occurs exactly once. **/ template - bool PermutationPuzzleEnvironment::Check_Permutation(const std::vector &to_check) + bool PermutationPuzzleEnvironment::Check_Permutation(const std::vector& to_check) { - const auto size = to_check.size(); - - bool in_puzzle[size]; - - for (size_t i = 0; i < size; i++) - { - in_puzzle[i] = false; - } - - for (size_t i = 0; i < size; i++) - { - in_puzzle[to_check[i]] = true; - } - - for (size_t i = 0; i < size; i++) - { - if (!in_puzzle[i]) + const size_t n = to_check.size(); + + // היה: bool in_puzzle[n]; // לא חוקי ב-MSVC + std::vector in_puzzle(n, 0); // "בדגל" לכל ערך 0..n-1 + + for (size_t i = 0; i < n; ++i) { + const int v = to_check[i]; + if (v < 0 || v >= static_cast(n)) // ערך מחוץ לטווח + return false; + if (in_puzzle[static_cast(v)]) // כפילות return false; + in_puzzle[static_cast(v)] = 1; } - + // לוודא שכל הערכים 0..n-1 הופיעו + for (size_t v = 0; v < n; ++v) + if (!in_puzzle[v]) return false; + return true; } + /** Outputs the set of puzzles in puzzle_vector to standard output. The output is of the From 146023c093ecc9aaf9375274c624e2c48c905919 Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Wed, 15 Oct 2025 13:14:17 +0300 Subject: [PATCH 06/11] PDBHeuristic.h change --- search/PDBHeuristic.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/search/PDBHeuristic.h b/search/PDBHeuristic.h index 861c66d17..7219ef757 100644 --- a/search/PDBHeuristic.h +++ b/search/PDBHeuristic.h @@ -15,10 +15,10 @@ #include #include "Heuristic.h" -#include "SharedQueue.h" -#include "NBitArray.h" -#include "Timer.h" -#include "RangeCompression.h" +#include "../utils/SharedQueue.h" +#include "../utils/NBitArray.h" +#include "../utils/Timer.h" +#include "../utils/RangeCompression.h" enum PDBLookupType { kPlain, @@ -244,7 +244,7 @@ void PDBHeuristic 0); printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) @@ -282,7 +282,7 @@ void PDBHeuristic 0); if (verbose) printf("%1.2fs elapsed\n", t.EndTimer()); @@ -369,7 +369,7 @@ void PDBHeuristic 0); printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) @@ -966,7 +966,7 @@ void PDBHeuristic 0); printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) From b554818ffa752e7a28be05d578c16384335fbe2d Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Tue, 28 Oct 2025 15:06:08 +0200 Subject: [PATCH 07/11] fix load function at PDBHeuristics.h --- search/PDBHeuristic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search/PDBHeuristic.h b/search/PDBHeuristic.h index 7219ef757..6312f7f4d 100644 --- a/search/PDBHeuristic.h +++ b/search/PDBHeuristic.h @@ -1479,7 +1479,7 @@ bool PDBHeuristic Date: Wed, 29 Oct 2025 11:10:27 +0200 Subject: [PATCH 08/11] change the PermutationPuzzleEnvironment.h file at func AdditiveGCost --- environments/PermutationPuzzleEnvironment.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/environments/PermutationPuzzleEnvironment.h b/environments/PermutationPuzzleEnvironment.h index ac00dbcb2..dfee66e52 100644 --- a/environments/PermutationPuzzleEnvironment.h +++ b/environments/PermutationPuzzleEnvironment.h @@ -61,7 +61,8 @@ namespace PermutationPuzzle { double HCost(const state &s) const; virtual double AdditiveGCost(const state &s, const action &d) - { assert(!"Additive Gost used but not defined for this class\n"); } + { assert(!"Additive Gost used but not defined for this class\n"); + return 0.0; } void GetStateFromHash(state &s, uint64_t hash) const; uint64_t GetStateHash(const state &s) const; From b2849e02234a2ed80ad12edd321185f46bb99178 Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Sun, 2 Nov 2025 17:52:08 +0200 Subject: [PATCH 09/11] return the source file-PDBHeuristic.h --- search/PDBHeuristic.h | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/search/PDBHeuristic.h b/search/PDBHeuristic.h index 6312f7f4d..dd2970b4c 100644 --- a/search/PDBHeuristic.h +++ b/search/PDBHeuristic.h @@ -307,33 +307,34 @@ void PDBHeuristic= depth && next < smallestDepth) - smallestDepth = next; - } - depth = smallestDepth; - } + // if (!useCoarseOpen) + // { + // uint64_t smallestDepth = (1<= depth && next < smallestDepth) + // smallestDepth = next; + // } + // depth = smallestDepth; + // } for (int x = 0; x < numThreads; x++) { - threads[x] = new std::thread(&PDBHeuristic::ForwardThreadWorker, + threads[x] = new std::thread(&PDBHeuristic::BackwardThreadWorker, this, - x, depth, std::ref(PDB), std::ref(coarseOpenNext), + x, depth, std::ref(PDB), std::ref(coarseClosed), &workQueue, &resultQueue, &lock); } for (uint64_t x = 0; x < COUNT; x+=coarseSize) { - if ((useCoarseOpen && coarseOpenCurr[x/coarseSize]) || !useCoarseOpen) + // if ((useCoarseOpen && coarseOpenCurr[x/coarseSize]) || !useCoarseOpen) + if (coarseClosed[x/coarseSize] == false) { workQueue.WaitAdd({x, std::min(COUNT, x+coarseSize)}); } - coarseOpenCurr[x/coarseSize] = false; + // coarseOpenCurr[x/coarseSize] = false; } for (int x = 0; x < numThreads; x++) { @@ -356,13 +357,13 @@ void PDBHeuristic 0); - + // coarseOpenCurr.swap(coarseOpenNext); +} while (entries != COUNT); + if (verbose) printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) From 5d27cc9fbcbd1137bac30dbc29074a31a361bc07 Mon Sep 17 00:00:00 2001 From: MiriShulman Date: Mon, 3 Nov 2025 10:42:23 +0200 Subject: [PATCH 10/11] update PDBHeuristic.h file --- search/PDBHeuristic.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/search/PDBHeuristic.h b/search/PDBHeuristic.h index dd2970b4c..f210903f1 100644 --- a/search/PDBHeuristic.h +++ b/search/PDBHeuristic.h @@ -323,18 +323,19 @@ void PDBHeuristic::BackwardThreadWorker, this, - x, depth, std::ref(PDB), std::ref(coarseClosed), + x, depth, std::ref(PDB), std::ref(coarseOpenNext), &workQueue, &resultQueue, &lock); } for (uint64_t x = 0; x < COUNT; x+=coarseSize) { // if ((useCoarseOpen && coarseOpenCurr[x/coarseSize]) || !useCoarseOpen) - if (coarseClosed[x/coarseSize] == false) + if ((useCoarseOpen && coarseOpenCurr[x / coarseSize]) || !useCoarseOpen) { workQueue.WaitAdd({x, std::min(COUNT, x+coarseSize)}); } - // coarseOpenCurr[x/coarseSize] = false; + if (useCoarseOpen) + coarseOpenCurr[x/coarseSize] = false; } for (int x = 0; x < numThreads; x++) { @@ -361,7 +362,7 @@ void PDBHeuristic Date: Wed, 5 Nov 2025 12:01:35 +0200 Subject: [PATCH 11/11] update PDBHeuristic.h and TreePermutationPDB.h files --- search/PDBHeuristic.h | 81 +++++++++++++++++++++++-------------- search/TreePermutationPDB.h | 28 ++++++------- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/search/PDBHeuristic.h b/search/PDBHeuristic.h index f210903f1..5e373b23d 100644 --- a/search/PDBHeuristic.h +++ b/search/PDBHeuristic.h @@ -15,10 +15,10 @@ #include #include "Heuristic.h" -#include "../utils/SharedQueue.h" -#include "../utils/NBitArray.h" -#include "../utils/Timer.h" -#include "../utils/RangeCompression.h" +#include "SharedQueue.h" +#include "NBitArray.h" +#include "Timer.h" +#include "RangeCompression.h" enum PDBLookupType { kPlain, @@ -244,7 +244,7 @@ void PDBHeuristic 0); + } while (entries != COUNT); printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) @@ -282,7 +282,7 @@ void PDBHeuristic= depth && next < smallestDepth) - // smallestDepth = next; - // } - // depth = smallestDepth; - // } + if (!useCoarseOpen) + { + // std::cout << "Im here 9 \n"; + + uint64_t smallestDepth = (1<= depth && next < smallestDepth) + smallestDepth = next; + } + depth = smallestDepth; + } for (int x = 0; x < numThreads; x++) { - threads[x] = new std::thread(&PDBHeuristic::BackwardThreadWorker, + threads[x] = new std::thread(&PDBHeuristic::ForwardThreadWorker, this, x, depth, std::ref(PDB), std::ref(coarseOpenNext), &workQueue, &resultQueue, &lock); } - + // std::cout << "Im here 10 \n"; + int added = 0; + for (uint64_t x = 0; x < COUNT; x+=coarseSize) { - // if ((useCoarseOpen && coarseOpenCurr[x/coarseSize]) || !useCoarseOpen) - if ((useCoarseOpen && coarseOpenCurr[x / coarseSize]) || !useCoarseOpen) + if ((useCoarseOpen && coarseOpenCurr[x/coarseSize]) || !useCoarseOpen) { workQueue.WaitAdd({x, std::min(COUNT, x+coarseSize)}); + added++; } - if (useCoarseOpen) - coarseOpenCurr[x/coarseSize] = false; + coarseOpenCurr[x/coarseSize] = false; } + std::cout << "Added " << added << " work ranges to queue\n"; + for (int x = 0; x < numThreads; x++) { workQueue.WaitAdd({0,0}); @@ -348,11 +354,14 @@ void PDBHeuristic 0); + } while (entries != COUNT); printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) @@ -563,7 +572,7 @@ void PDBHeuristic double(COUNT-entries)*double(distribution[distribution.size()-2]))// || depth == 8) @@ -643,18 +652,28 @@ void PDBHeuristiclock(); for (auto d : cache) { + // std::cout << "im hereeeeeeeeee " << "\n"; + if (d.newGCost < DB.Get(d.rank)) // shorter path { if (DB.Get(d.rank) == (1<unlock(); + // std::cout << "countttttttttttttttttt " << count << "\n"; + cache.resize(0); } + // std::cout << "im hereeeeee countttt" << count << "\n"; results->Add(count); + // lock->lock(); // printf("Thread %d offline\n", threadNum); // lock->unlock(); @@ -968,7 +987,7 @@ void PDBHeuristic 0); + } while (entries != COUNT); printf("%1.2fs elapsed\n", t.EndTimer()); if (entries != COUNT) @@ -1481,7 +1500,7 @@ bool PDBHeuristic - /** * This class does the basic permutation calculation in lexicographical order. @@ -24,14 +22,14 @@ class TreePermutationPDB : public PermutationPDB &distincts); - virtual uint64_t GetPDBHash(const state &s, int threadID = 0) const override; - virtual void GetStateFromPDBHash(uint64_t hash, state &s, int threadID = 0) const override; - virtual uint64_t GetAbstractHash(const state &s, int threadID = 0) const override { return GetPDBHash(s); } + virtual uint64_t GetPDBHash(const state &s, int threadID = 0) const; + virtual void GetStateFromPDBHash(uint64_t hash, state &s, int threadID = 0) const; + virtual uint64_t GetAbstractHash(const state &s, int threadID = 0) const { return GetPDBHash(s); } virtual state GetStateFromAbstractState(state &s) const override { return s; } - - std::string GetFileName(const char *prefix) override; + + std::string GetFileName(const char *prefix); private: - //using PermutationPDB::example; + using PermutationPDB::example; using PermutationPDB::distinct; uint64_t Factorial(int val) const; @@ -44,7 +42,7 @@ class TreePermutationPDB : public PermutationPDB > locsCache; mutable std::vector > tempCache; - state goalState; + state new_example; }; inline int mylog2(int val) @@ -102,7 +100,7 @@ uint64_t TreePermutationPDB::GetPDBHash(const std::vector &values = locsCache[threadID]; std::vector &dual = dualCache[threadID]; // TODO: test definition - values.resize(this->distinct.size()); // vector for distinct item locations + values.resize(distinct.size()); // vector for distinct item locations dual.resize(s.puzzle.size()); // vector for distinct item locations // find item locations @@ -111,7 +109,7 @@ uint64_t TreePermutationPDB::GetPDBHash(const if (s.puzzle[x] != -1) dual[s.puzzle[x]] = x; } - for (int x = 0; x < this->distinct.size(); x++) + for (int x = 0; x < distinct.size(); x++) { values[x] = dual[distinct[x]]; } @@ -146,7 +144,7 @@ uint64_t TreePermutationPDB::GetPDBHash(const template void TreePermutationPDB::GetStateFromPDBHash(uint64_t hash, state &s, int threadID) const { - size_t count = goalState.puzzle.size(); + size_t count = example.puzzle.size(); s.puzzle.resize(count); int k = mylog2(count); std::vector &temp = tempCache[threadID]; @@ -155,8 +153,8 @@ void TreePermutationPDB::GetStateFromPDBHash(u temp[x] = (1<<(k-mylog2(x+2)+1)); std::vector &values = locsCache[threadID]; - values.resize(this->distinct.size()); - int numEntriesLeft = (int)s.puzzle.size()-(int)this->distinct.size()+1; + values.resize(distinct.size()); + int numEntriesLeft = s.puzzle.size()-distinct.size()+1; for (int x = (int)values.size()-1; x >= 0; x--) { values[x] = hash%numEntriesLeft; @@ -184,7 +182,7 @@ void TreePermutationPDB::GetStateFromPDBHash(u } temp[node] = 0; values[x] = node - (1<distinct[x]; + s.puzzle[values[x]] = distinct[x]; } s.FinishUnranking(); }