20#ifndef __PBeFS_VacuumWorld
21 #define __PBeFS_VacuumWorld
85 : f_n( n ) , f_start( start ) , f_dirty( dirty ) {
86 if( ( n < 1 ) || ( n > 32 ) || ( start < 0 ) || ( start >= n ) )
87 throw( std::invalid_argument(
"VacuumWorld::VacuumWorld: bad sizes" ) );
88 if( ( n < 32 ) && ( dirty >> n ) )
89 throw( std::invalid_argument(
"VacuumWorld::VacuumWorld: dirt out of "
96 [[nodiscard]]
static int robot( std::uint64_t s )
noexcept {
97 return(
int( s >> 32 ) );
102 [[nodiscard]]
static std::uint32_t
dirt( std::uint64_t s )
noexcept {
103 return( std::uint32_t( s ) );
109 return( pack( f_start , f_dirty ) );
112 [[nodiscard]]
bool is_goal( std::uint64_t s )
const noexcept {
113 return(
dirt( s ) == 0 );
116 [[nodiscard]] std::uint64_t
hash( std::uint64_t s )
const noexcept {
117 return( ADS::splitmix64( s ) );
120 [[nodiscard]]
int heuristic( std::uint64_t s )
const noexcept {
121 return( std::popcount(
dirt( s ) ) );
129 const int r =
robot( s );
130 const std::uint32_t d =
dirt( s );
131 if( d & ( std::uint32_t( 1 ) << r ) )
132 f( pack( r , d & ~( std::uint32_t( 1 ) << r ) ) , 1 , h - 1 );
134 f( pack( r - 1 , d ) , 1 , h );
136 f( pack( r + 1 , d ) , 1 , h );
143 return( 2 * std::size_t( f_n ) );
150 for( std::uint32_t d =
dirt( s ) ; d ; d &= d - 1 )
151 f( std::size_t( std::countr_zero( d ) ) );
152 f( std::size_t( f_n +
robot( s ) ) );
158 return( std::size_t( f_n ) + 1 );
165 return( i < std::size_t( f_n ) ? i : std::size_t( f_n ) );
179 return( std::size_t( f_n ) );
184 [[nodiscard]] std::size_t
nblock( std::uint64_t s )
const noexcept {
185 return( std::size_t(
robot( s ) ) );
194 if( b + 1 < std::size_t( f_n ) )
203 return( std::popcount(
dirt( s ) & ~
dirt( t ) ) );
208 [[nodiscard]] std::uint64_t
perfect_hash( std::uint64_t s )
const noexcept {
215 [[nodiscard]]
int size(
void )
const noexcept {
return( f_n ); }
222 static std::uint64_t pack(
int r , std::uint32_t d )
noexcept {
223 return( ( std::uint64_t( r ) << 32 ) | d );
228 std::uint32_t f_dirty;
Header file for the concepts a search problem has to satisfy in order to be searched by the algorithm...
std::size_t num_nblocks(void) const noexcept
the number of nblocks: the cells
Definition VacuumWorld.h:178
std::uint64_t abstract_state(std::uint64_t s) const noexcept
the abstract state of AHDA*: the dirty cells
Definition VacuumWorld.h:171
std::size_t num_abstract_features(void) const noexcept
the number of abstract features: the dirty cells and the robot
Definition VacuumWorld.h:157
std::size_t abstract_feature(std::size_t i) const noexcept
the abstract feature of a feature: the dirty cell, or n for the robot
Definition VacuumWorld.h:163
bool is_goal(std::uint64_t s) const noexcept
Definition VacuumWorld.h:112
static int robot(std::uint64_t s) noexcept
the cell of the robot in the state s
Definition VacuumWorld.h:96
VacuumWorld(int n, int start, std::uint32_t dirty)
constructor of the row of n cells, with the robot in the cell start and the dirty cells given by the ...
Definition VacuumWorld.h:84
std::uint64_t hash(std::uint64_t s) const noexcept
Definition VacuumWorld.h:116
void for_each_feature(std::uint64_t s, F &&f) const
calls f( i ) for each dirty cell i and f( n + r ) for the robot in r
Definition VacuumWorld.h:149
int pairwise_heuristic(std::uint64_t s, std::uint64_t t) const noexcept
the heuristic of PA*SE: the cells dirty in s and clean in t
Definition VacuumWorld.h:201
std::uint64_t state_type
the packed state
Definition VacuumWorld.h:76
static std::uint32_t dirt(std::uint64_t s) noexcept
the dirty cells in the state s
Definition VacuumWorld.h:102
void for_each_nblock_successor(std::size_t b, F &&f) const
calls f( b' ) for each cell b' next to the cell b
Definition VacuumWorld.h:191
int cost_type
the cost type
Definition VacuumWorld.h:77
std::uint64_t perfect_hash(std::uint64_t s) const noexcept
the perfect hash: the packed state
Definition VacuumWorld.h:208
std::size_t num_features(void) const noexcept
the number of features: the dirty cells and the cells of the robot
Definition VacuumWorld.h:142
int size(void) const noexcept
the number of cells
Definition VacuumWorld.h:215
void for_each_successor(std::uint64_t s, int h, F &&f) const
calls f( t , 1 , h( t ) ) for Suck, Left and Right, if possible
Definition VacuumWorld.h:128
std::size_t nblock(std::uint64_t s) const noexcept
the nblock of PBNF: the cell of the robot
Definition VacuumWorld.h:184
std::uint64_t initial_state(void) const noexcept
Definition VacuumWorld.h:108
int heuristic(std::uint64_t s) const noexcept
Definition VacuumWorld.h:120
namespace for the Parallel Best-First Search library
Definition AStar.h:83