PBeFS
Parallel Best-First Search
Loading...
Searching...
No Matches
OpenList.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File OpenList.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
17/*--------------------------------------------------------------------------*/
18/*------------------------------ DEFINITIONS -------------------------------*/
19/*--------------------------------------------------------------------------*/
20
21#ifndef __PBeFS_ads_OpenList
22 #define __PBeFS_ads_OpenList
23 /* self-identification: #endif at the end of the file */
24
25/*--------------------------------------------------------------------------*/
26/*-------------------------------- INCLUDES --------------------------------*/
27/*--------------------------------------------------------------------------*/
28
29#include <cstddef>
30
31#include <type_traits>
32
33#include "ADS/priority/BucketQueue.h"
34
35#include "ADS/priority/DaryHeap.h"
36
38
39/*--------------------------------------------------------------------------*/
40/*------------------------------- NAMESPACE --------------------------------*/
41/*--------------------------------------------------------------------------*/
42
44namespace PBeFS_di_unipi_it
45{
46
47/*--------------------------------------------------------------------------*/
48/*--------------------------- CLASS HeapOpenList ---------------------------*/
49/*--------------------------------------------------------------------------*/
51template< class NodeT , unsigned Arity = 4 >
53
54 using Cost = decltype( NodeT::g );
55
56 public:
57
59
60 void push( NodeT * node ) { push( node , node->g ); }
61
63
64 void push( NodeT * node , Cost g ) {
65 f_heap.push( Item{ g + node->h , g , node } );
66 }
67
69
70 [[nodiscard]] OpenEntry< NodeT > top( void ) const {
71 return( OpenEntry< NodeT >{ f_heap.top().node , f_heap.top().g } );
72 }
73
75
76 [[nodiscard]] Cost top_f( void ) const { return( f_heap.top().f ); }
77
79
81 const Item x = f_heap.pop();
82 return( OpenEntry< NodeT >{ x.node , x.g } );
83 }
84
86
87 [[nodiscard]] bool empty( void ) const noexcept {
88 return( f_heap.empty() );
89 }
90
92
93 [[nodiscard]] std::size_t size( void ) const noexcept {
94 return( f_heap.size() );
95 }
96
97 private:
98
100 struct Item {
101 Cost f;
102 Cost g;
103 NodeT * node;
104 };
105
107 struct Better {
108 bool operator()( const Item & a , const Item & b ) const noexcept {
109 return( ( a.f < b.f ) || ( ( a.f == b.f ) && ( a.g > b.g ) ) );
110 }
111 };
112
113 ADS::DaryHeap< Item , Better , Arity > f_heap;
114
115 }; // end( class( HeapOpenList ) )
116
117/*--------------------------------------------------------------------------*/
118/*-------------------------- CLASS BucketOpenList --------------------------*/
119/*--------------------------------------------------------------------------*/
121template< class NodeT >
123
124 using Cost = decltype( NodeT::g );
125
126 static_assert( std::is_integral_v< Cost > ,
127 "BucketOpenList requires an integer cost type" );
128
129 public:
130
132
133 void push( NodeT * node ) { push( node , node->g ); }
134
136
137 void push( NodeT * node , Cost g ) { f_queue.push( node , g + node->h , g ); }
138
140
141 [[nodiscard]] OpenEntry< NodeT > top( void ) {
142 return( OpenEntry< NodeT >{ f_queue.top() , f_queue.topG() } );
143 }
144
146
147 [[nodiscard]] Cost top_f( void ) { return( f_queue.topF() ); }
148
150
152 const auto e = f_queue.popEntry();
153 return( OpenEntry< NodeT >{ e.item , e.g } );
154 }
155
157
158 [[nodiscard]] bool empty( void ) const noexcept {
159 return( f_queue.empty() );
160 }
161
163
164 [[nodiscard]] std::size_t size( void ) const noexcept {
165 return( f_queue.size() );
166 }
167
168 private:
169
170 ADS::BucketQueue< NodeT * , Cost > f_queue;
171
172 }; // end( class( BucketOpenList ) )
173
174/*--------------------------------------------------------------------------*/
175
176} // end( namespace PBeFS_di_unipi_it )
177
178/*--------------------------------------------------------------------------*/
179
180#endif /* __PBeFS_ads_OpenList */
181
182/*--------------------------------------------------------------------------*/
183/*-------------------------- End File OpenList.h ---------------------------*/
184/*--------------------------------------------------------------------------*/
Header file for the priority queues of the OPEN list, taken from the set of data structures chosen [s...
the OPEN list on the BucketQueue of ADS, for integer costs
Definition OpenList.h:122
Cost top_f(void)
the f of top()
Definition OpenList.h:147
void push(NodeT *node)
pushes a node with its current f and g
Definition OpenList.h:133
std::size_t size(void) const noexcept
the number of entries, the stale ones included
Definition OpenList.h:164
void push(NodeT *node, Cost g)
pushes a node with the given g (and f = g + h), not reading node->g
Definition OpenList.h:137
OpenEntry< NodeT > pop(void)
removes and returns top()
Definition OpenList.h:151
bool empty(void) const noexcept
true if there is no entry
Definition OpenList.h:158
OpenEntry< NodeT > top(void)
the entry with the smallest f (and the largest g among those)
Definition OpenList.h:141
the OPEN list on the DaryHeap of ADS
Definition OpenList.h:52
Cost top_f(void) const
the f of top()
Definition OpenList.h:76
void push(NodeT *node)
pushes a node with its current f and g
Definition OpenList.h:60
std::size_t size(void) const noexcept
the number of entries, the stale ones included
Definition OpenList.h:93
void push(NodeT *node, Cost g)
pushes a node with the given g (and f = g + h), not reading node->g
Definition OpenList.h:64
OpenEntry< NodeT > pop(void)
removes and returns top()
Definition OpenList.h:80
OpenEntry< NodeT > top(void) const
the entry with the smallest f (and the largest g among those)
Definition OpenList.h:70
bool empty(void) const noexcept
true if there is no entry
Definition OpenList.h:87
namespace for the Parallel Best-First Search library
Definition AStar.h:83
an entry of the OPEN list: the node and the g it had when pushed
Definition OpenList.h:73