|
PBeFS
Parallel Best-First Search
|
Header file for the pattern databases of the sliding-tile puzzles, i.e., the heuristics that store the exact distances of an abstraction of the puzzle. More...
#include <algorithm>#include <array>#include <atomic>#include <bit>#include <cstddef>#include <cstdint>#include <cstdio>#include <cstdlib>#include <cstring>#include <filesystem>#include <fstream>#include <iterator>#include <stdexcept>#include <string>#include <thread>#include <utility>#include <vector>#include "PBeFS/astar/SlidingTile.h"#include "PBeFS/astar/Structures.h"#include "PBeFS/core/SearchUtils.h"#include "ADS/succinct/PackedArray.h"#include "ADS/succinct/RankSelect.h"Go to the source code of this file.
Classes | |
| struct | PDBOptions |
| the options of the construction of an AdditivePDB More... | |
| class | TilePattern< W, H > |
| a pattern of the sliding-tile puzzle and the ranking of its placements More... | |
| struct | TilePattern< W, H >::Moves |
| the cells adjacent to a cell, in the order up, left, right, down More... | |
| class | ByteEntries |
| the entries of a pattern table, one byte each: the distance itself More... | |
| class | NibbleEntries |
| the entries of a pattern table, 4 bits each: the excess over Manhattan More... | |
| class | Mod3Entries |
| the entries of a pattern table, the distance modulo 3, five in a byte More... | |
| class | ParityBitEntries |
| the entries of a pattern table, the second bit of the distance, eight in a byte More... | |
| class | MinNibbleEntries |
| the entries of a pattern table, the least excess of each group of ranks More... | |
| class | SparseEntries |
| the entries of a pattern table whose excess is nonzero, by rank More... | |
| class | PatternTable< W, H, Enc > |
| the distances of a pattern of the sliding-tile puzzle, encoded by Enc More... | |
| class | AdditivePDB< W, H, Enc > |
| the additive heuristic of disjoint pattern tables More... | |
| class | SlidingTilePDB< W, H, Enc > |
| the sliding-tile puzzle with an additive pattern database heuristic More... | |
Namespaces | |
| namespace | PBeFS_di_unipi_it |
| namespace for the Parallel Best-First Search library | |
Typedefs | |
| using | Partition = std::vector< std::vector< int > > |
| a partition of the tiles into disjoint patterns | |
Enumerations | |
| enum class | BlankRule : std::uint8_t { ignored , minimized } |
| how the abstraction of a pattern treats the blank More... | |
Functions | |
| Partition | partition_15_7_8 (void) |
| the partition 7-8 of the 15-puzzle of Korf and Felner (AIJ 2002) | |
| Partition | partition_15_5_5_5 (void) |
| the partition 5-5-5 of the 15-puzzle of Felner, Korf and Hanan (JAIR 2004) | |
| Partition | partition_15_6_6_3 (void) |
| the partition 6-6-3 of the 15-puzzle of Felner, Korf and Hanan (JAIR 2004) | |
| Partition | partition_24_6_6_6_6 (void) |
| the partition 6-6-6-6 of the 24-puzzle of Korf and Felner (AIJ 2002) | |
Header file for the pattern databases of the sliding-tile puzzles, i.e., the heuristics that store the exact distances of an abstraction of the puzzle.
The class templates are TilePattern (a subset of the tiles and the perfect ranking of their placements), PatternTable (the distances of a pattern, built by a backward breadth-first search and stored by one of the encodings), AdditivePDB (the sum of the tables of a partition of the tiles, with the reflection about the main diagonal) and SlidingTilePDB, the domain SlidingTile with the additive heuristic in place of the Manhattan distance. The theory (the abstraction, the admissibility of the additive sum and of the reflection, the consistency, the encodings) is on the page "Pattern databases" of the documentation.
A pattern \( \pi \) is a set of \( k \) tiles of a board of \( n = W H \) cells. A placement of \( \pi \) is the vector \( p = ( p_1 , \ldots , p_k ) \) of the distinct cells of its tiles, and its rank is the lexicographic rank of the \( k \)-permutation \( p \) of \( n \) items, a bijection onto \( [ 0 , n! / ( n - k )! ) \). With the blank ignored, a move of the abstraction takes one tile of \( \pi \) to an adjacent cell that no tile of \( \pi \) holds, at cost 1; with the blank minimized, the blank is part of the abstract state, the moves of the blank into a cell that no tile of \( \pi \) holds cost 0 (they move a tile out of the pattern), and the table keeps the least distance over the cells of the blank. The table is filled by a breadth-first search backward from the goal placement, by layers, each layer scanned in parallel by blocks:
The states \( ( r , b ) \) of BUILD-MINIMIZED take 2 bits each, as in the two-bit breadth-first search of Korf (AAAI 2008); the cell of the blank is coded by its index among the \( n - k \) cells free of the pattern. The table of the distances takes 1 byte per placement during the construction, then it is encoded by one of the following classes, all of which store the excess \( e( p ) = ( h( p ) - m( p ) ) / 2 \) over the Manhattan distance \( m( p ) \) of the tiles of the pattern, which is a nonnegative integer since a move changes \( m \) by one unit at the cost of one unit, save ByteEntries (the distance itself) and Mod3Entries (the distance modulo 3):
The lookup of a state \( s \), whose tile \( t \) is in the cell \( q_t \), sums the tables of the partition \( \pi_1 , \ldots , \pi_m \) and, on a square board whose goal has the blank on the main diagonal, takes the maximum with the same sum on the reflection \( \phi( s ) \), which moves the tile \( t \) of the cell \( q_t \) to the transposed cell \( T( q_t ) \) and renames it \( \sigma( t ) \), the tile that the goal holds in the transposed goal cell of \( t \):
A table can be saved to a file and loaded back (a versioned header, the pattern, the goal, the encoding and a checksum of the whole file), and a cache directory keeps the tables built, so that the large ones (those of the 24-puzzle take minutes) are built once.