29 #ifndef GUM_SEARCHSTRATEGY_H 30 #define GUM_SEARCHSTRATEGY_H 37 #include <agrum/tools/core/math/math_utils.h> 38 #include <agrum/tools/core/bijection.h> 39 #include <agrum/tools/core/sequence.h> 40 #include <agrum/tools/core/set.h> 42 #include <agrum/tools/graphs/diGraph.h> 44 #include <agrum/tools/graphs/algorithms/triangulations/partialOrderedTriangulation.h> 46 #include <agrum/PRM/gspan/edgeGrowth.h> 47 #include <agrum/PRM/gspan/interfaceGraph.h> 48 #include <agrum/PRM/gspan/pattern.h> 53 template <
typename GUM_SCALAR >
57 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
72 class SearchStrategy {
80 SearchStrategy< GUM_SCALAR >();
83 SearchStrategy< GUM_SCALAR >(
const SearchStrategy< GUM_SCALAR >& from);
86 virtual ~SearchStrategy< GUM_SCALAR >();
89 SearchStrategy< GUM_SCALAR >&
90 operator=(
const SearchStrategy< GUM_SCALAR >& from);
98 void setTree(DFSTree< GUM_SCALAR >* tree);
100 virtual bool accept_root(
const Pattern* r) = 0;
102 virtual bool accept_growth(
const Pattern* parent,
103 const Pattern* child,
104 const EdgeGrowth< GUM_SCALAR >& growth)
107 virtual bool operator()(LabelData* i, LabelData* j) = 0;
108 virtual bool operator()(Pattern* i, Pattern* j) = 0;
112 DFSTree< GUM_SCALAR >* tree_;
113 double computeCost_(
const Pattern& p);
125 template <
typename GUM_SCALAR >
126 class FrequenceSearch:
public SearchStrategy< GUM_SCALAR > {
134 explicit FrequenceSearch(Size freq);
137 FrequenceSearch(
const FrequenceSearch& from);
140 virtual ~FrequenceSearch();
143 FrequenceSearch& operator=(
const FrequenceSearch& from);
151 virtual bool accept_root(
const Pattern* r);
153 virtual bool accept_growth(
const Pattern* parent,
154 const Pattern* child,
155 const EdgeGrowth< GUM_SCALAR >& growth);
157 virtual bool operator()(LabelData* i, LabelData* j);
158 virtual bool operator()(Pattern* i, Pattern* j);
175 template <
typename GUM_SCALAR >
176 class StrictSearch:
public SearchStrategy< GUM_SCALAR > {
184 explicit StrictSearch(Size freq = 2);
187 StrictSearch(
const StrictSearch& from);
190 virtual ~StrictSearch();
193 StrictSearch& operator=(
const StrictSearch& from);
201 virtual bool accept_root(
const Pattern* r);
203 virtual bool accept_growth(
const Pattern* parent,
204 const Pattern* child,
205 const EdgeGrowth< GUM_SCALAR >& growth);
207 virtual bool operator()(LabelData* i, LabelData* j);
208 virtual bool operator()(Pattern* i, Pattern* j);
213 double inner_cost__(
const Pattern* p);
214 double outer_cost__(
const Pattern* p);
215 void compute_costs__(
const Pattern* p);
216 HashTable<
const Pattern*, std::pair<
double,
double > > map__;
222 NodeProperty< Size > mod;
227 Bijection< NodeId, std::string > node2attr;
231 Bijection< NodeId,
const DiscreteVariable* > vars;
238 std::string str__(
const PRMInstance< GUM_SCALAR >* i,
239 const PRMAttribute< GUM_SCALAR >* a)
const;
240 std::string str__(
const PRMInstance< GUM_SCALAR >* i,
241 const PRMAttribute< GUM_SCALAR >& a)
const;
242 std::string str__(
const PRMInstance< GUM_SCALAR >* i,
243 const PRMSlotChain< GUM_SCALAR >& a)
const;
244 void buildPatternGraph__(
245 typename StrictSearch< GUM_SCALAR >::PData& data,
246 Set< Potential< GUM_SCALAR >* >& pool,
247 const Sequence< PRMInstance< GUM_SCALAR >* >& match);
248 std::pair< Size, Size >
249 elimination_cost__(
typename StrictSearch< GUM_SCALAR >::PData& data,
250 Set< Potential< GUM_SCALAR >* >& pool);
262 template <
typename GUM_SCALAR >
263 class TreeWidthSearch:
public SearchStrategy< GUM_SCALAR > {
274 TreeWidthSearch(
const TreeWidthSearch& from);
277 virtual ~TreeWidthSearch();
280 TreeWidthSearch& operator=(
const TreeWidthSearch& from);
288 double cost(
const Pattern& p);
290 virtual bool accept_root(
const Pattern* r);
292 virtual bool accept_growth(
const Pattern* parent,
293 const Pattern* child,
294 const EdgeGrowth< GUM_SCALAR >& growth);
296 virtual bool operator()(LabelData* i, LabelData* j);
297 virtual bool operator()(Pattern* i, Pattern* j);
301 HashTable<
const Pattern*,
double > map__;
305 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 306 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 307 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 308 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 309 extern template class SearchStrategy<
double >;
314 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 315 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 316 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 317 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 318 extern template class FrequenceSearch<
double >;
323 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 324 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 325 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 326 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 327 extern template class StrictSearch<
double >;
332 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 333 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 334 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 335 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 336 extern template class TreeWidthSearch<
double >;
347 #include <agrum/PRM/gspan/searchStrategy_tpl.h>