Repository navigation
Cache the node hash and allocate children with make_shared in the other tree searches - #881
Merged
Merged
Conversation
…er tree searches The history maps of the beam searches hashed a node's whole item_number_of_copies vector on every lookup. The hash is now stored in the node and updated incrementally when items are packed: the sum over the item types of their numbers of copies times a random 64-bit key per item type (modulo 2^64, fixed seed, see ItemCopiesHashKeys). Node equality is unchanged, so the searches explore the same nodes. This applies to the tree searches of box, boxstacks, onedimensional, rectangle and irregular, and to the maximal spaces tree searches of box, rectangle, rectangleguillotine and irregular, and to the irregular periodic packing tree search. The child() functions that allocated a node and then copied it into a shared pointer now use std::make_shared. New tests NodeHashFollowsItemNumberOfCopies for each branching scheme: over the nodes of a small expanded tree, the same numbers of copies give the same hash, different numbers of copies different hashes. Breaking an update makes only the test of that scheme fail. Deterministic mode: identical solutions before and after on the 476 instances of data/*/tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up of #880, which did this for the rectangleguillotine tree search.
Changes
The history maps of the beam searches hashed a node's whole
item_number_of_copiesvector on every lookup. The hash is now stored in the node (item_number_of_copies_hash) and updated incrementally when items are packed.The hash is the sum over the item types of their number of copies times a random 64-bit key per item type, modulo 2^64. The keys come from a fixed seed and live in the new
src/algorithms/item_copies_hash.hpp(ItemCopiesHashKeys). Unlike the Zobrist hash of #880, it needs one key per item type, whatever the number of copies. Node equality is unchanged: a collision only puts two nodes in the same bucket, so the searches explore the same nodes.Schemes updated:
The
child()functions that built a node and then copied it into a shared pointer now usestd::make_shared(box, boxstacks, onedimensional, rectangle and irregular tree searches).In box, boxstacks and onedimensional, the hasher still returns 0 for unbounded knapsack instances, as before.
Tests
NodeHashFollowsItemNumberOfCopiesfor each scheme, with a shared helper intest/node_hash_test.hpp. Over the nodes of a small expanded tree, it checks that the same numbers of copies give the same hash and that different numbers of copies give different hashes. When an update is deliberately broken, only the test of that scheme fails.test/boxstacks/tree_search_test.cppwas empty. It now holds this test and is registered in CMake.not-anytime-sequential): identical solutions on master and this branch on the 476 instances ofdata/*/tests.Speed
Not measured meaningfully yet: