39#ifndef __PBeFS_Distribution
40 #define __PBeFS_Distribution
61#if defined( _MSC_VER )
67#include "ADS/dictionary/RandomHashing.h"
85[[nodiscard]]
inline unsigned reduce( std::uint64_t h ,
unsigned p )
noexcept
87 #if defined( __SIZEOF_INT128__ )
88 __extension__
using u128 =
unsigned __int128;
89 return(
unsigned( ( u128( h ) * p ) >> 64 ) );
90 #elif defined( _MSC_VER )
91 return(
unsigned( __umulh( h , p ) ) );
93 return(
unsigned( h % p ) );
102[[nodiscard]]
inline unsigned key_owner( std::uint32_t k ,
unsigned p )
105 return(
reduce( std::uint64_t( k ) << 32 , p ) );
121template< FeatureDomain D >
129 : f_domain( domain ) , f_r( domain.num_features() , 1 , seed ) {}
135 f_domain.for_each_feature( s , [ & ]( std::size_t i ) {
144 return( std::uint32_t(
hash( s ) >> 32 ) );
160 f_domain.for_each_feature_change( s , t , [ & ]( std::size_t i ) {
161 k ^= std::uint32_t( f_r( i , 0 ) >> 32 );
168 [[nodiscard]]
static std::string
name(
void ) {
return(
"Z" ); }
173 ADS::ZobristTable f_r;
190template< AbstractFeatureDomain D >
198 std::uint64_t seed = 1 )
199 : f_domain( domain ) , v_r( domain.num_features() ) {
200 const ADS::ZobristTable r0( domain.num_abstract_features() , 1 , seed );
201 for( std::size_t i = 0 ; i < v_r.size() ; ++i )
202 v_r[ i ] = r0( domain.abstract_feature( i ) , 0 );
209 f_domain.for_each_feature( s , [ & ]( std::size_t i ) { z ^= v_r[ i ]; } );
216 return( std::uint32_t(
hash( s ) >> 32 ) );
232 f_domain.for_each_feature_change( s , t , [ & ]( std::size_t i ) {
233 k ^= std::uint32_t( v_r[ i ] >> 32 );
240 [[nodiscard]]
static std::string
name(
void ) {
return(
"AZ" ); }
245 std::vector< std::uint64_t > v_r;
257template< AbstractStateDomain D >
263 std::uint64_t seed = 1 )
264 : f_domain( domain ) , f_seed( ADS::splitmix64( seed ) ) {}
269 return(
reduce( ADS::splitmix64( f_domain.abstract_state( s ) ^
275 [[nodiscard]]
static std::string
name(
void ) {
return(
"A" ); }
280 std::uint64_t f_seed;
293template< PerfectHashDomain D >
299 : f_domain( domain ) {}
302 return(
unsigned( f_domain.perfect_hash( s ) % p ) );
305 [[nodiscard]]
static std::string
name(
void ) {
return(
"P" ); }
327 : f_domain( domain ) , f_seed( ADS::splitmix64( seed ) ) {}
330 return(
reduce( ADS::splitmix64( f_domain.hash( s ) ^ f_seed ) , p ) );
333 [[nodiscard]]
static std::string
name(
void ) {
return(
"H" ); }
338 std::uint64_t f_seed;
360 return(
reduce( f_gen() , p ) );
363 [[nodiscard]]
static std::string
name(
void ) {
return(
"R" ); }
370 mutable std::mt19937_64 f_gen;
384template<
class X ,
class D >
386 requires(
const X & x ,
const state_t< D > & s , std::uint32_t k ,
388 { x.key( s ) } -> std::same_as< std::uint32_t >;
389 { x.key( k , s , s ) } -> std::same_as< std::uint32_t >;
390 { x.owner( s , p ) } -> std::convertible_to< unsigned >;
398template< Domain D ,
class X >
402 return( x.key( s ) );
413template< Domain D ,
class X >
415 std::uint32_t k ,
unsigned p ) {
417 return( [ & x , & s , k , p ](
const state_t< D > & t ) {
418 const std::uint32_t kt = x.key( k , s , t );
419 return( std::pair(
key_owner( kt , p ) , kt ) );
423 return( std::pair(
unsigned( x.owner( t , p ) ) , std::uint32_t( 0 ) ) );
Header file for the concepts a search problem has to satisfy in order to be searched by the algorithm...
static std::string name(void)
the name in the notation of Jinnai and Fukunaga
Definition Distribution.h:275
unsigned owner(const state_t< D > &s, unsigned p) const
the owner of s among p workers
Definition Distribution.h:268
AbstractStateDistribution(const D &domain, std::uint64_t seed=1)
Definition Distribution.h:262
static std::string name(void)
the name in the notation of Jinnai and Fukunaga
Definition Distribution.h:240
AbstractZobristDistribution(const D &domain, std::uint64_t seed=1)
constructor, drawing the table of the abstract features from the seed
Definition Distribution.h:197
std::uint32_t key(const state_t< D > &s) const
the key of s, the high 32 bits of its hash
Definition Distribution.h:215
unsigned owner(const state_t< D > &s, unsigned p) const
the owner of s among p workers, that of its key
Definition Distribution.h:221
std::uint64_t hash(const state_t< D > &s) const
the abstract Zobrist hash of s
Definition Distribution.h:207
std::uint32_t key(std::uint32_t k, const state_t< D > &s, const state_t< D > &t) const
the key of t, a successor of s whose key is k
Definition Distribution.h:229
static std::string name(void)
Definition Distribution.h:305
PerfectHashDistribution(const D &domain, std::uint64_t=1)
Definition Distribution.h:298
unsigned owner(const state_t< D > &s, unsigned p) const
Definition Distribution.h:301
static std::string name(void)
Definition Distribution.h:363
static constexpr bool per_worker
true: each worker needs its own copy
Definition Distribution.h:366
unsigned owner(const state_t< D > &, unsigned p) const
Definition Distribution.h:359
RandomDistribution(const D &, std::uint64_t seed=1)
Definition Distribution.h:356
static std::string name(void)
Definition Distribution.h:333
StateHashDistribution(const D &domain, std::uint64_t seed=1)
Definition Distribution.h:326
unsigned owner(const state_t< D > &s, unsigned p) const
Definition Distribution.h:329
static std::string name(void)
the name in the notation of Jinnai and Fukunaga
Definition Distribution.h:168
std::uint32_t key(const state_t< D > &s) const
the key of s, the high 32 bits of its hash
Definition Distribution.h:143
unsigned owner(const state_t< D > &s, unsigned p) const
the owner of s among p workers, that of its key
Definition Distribution.h:149
std::uint64_t hash(const state_t< D > &s) const
the Zobrist hash of s
Definition Distribution.h:133
std::uint32_t key(std::uint32_t k, const state_t< D > &s, const state_t< D > &t) const
the key of t, a successor of s whose key is k
Definition Distribution.h:157
ZobristDistribution(const D &domain, std::uint64_t seed=1)
constructor, drawing the table of D from the seed
Definition Distribution.h:128
a distribution whose owners follow the moves
Definition Distribution.h:385
a FeatureDomain that also gives the features changed by a move
Definition Domain.h:143
namespace for the Parallel Best-First Search library
Definition AStar.h:83
std::uint32_t distribution_key(const X &x, const state_t< D > &s)
the key of s for x, 0 if X is not an IncrementalDistribution
Definition Distribution.h:399
typename D::state_type state_t
the state type of a Domain
Definition Domain.h:241
unsigned reduce(std::uint64_t h, unsigned p) noexcept
the worker in of a 64-bit hash value
Definition Distribution.h:85
auto successor_owners(const X &x, const state_t< D > &s, std::uint32_t k, unsigned p)
the owner among p workers and the key of each successor of s
Definition Distribution.h:414
unsigned key_owner(std::uint32_t k, unsigned p) noexcept
the worker in of a 32-bit key
Definition Distribution.h:102