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 >& operator=(
const SearchStrategy< GUM_SCALAR >& from);
97 void setTree(DFSTree< GUM_SCALAR >* tree);
99 virtual bool accept_root(
const Pattern* r) = 0;
101 virtual bool accept_growth(
const Pattern* parent,
102 const Pattern* child,
103 const EdgeGrowth< GUM_SCALAR >& growth)
106 virtual bool operator()(LabelData* i, LabelData* j) = 0;
107 virtual bool operator()(Pattern* i, Pattern* j) = 0;
111 DFSTree< GUM_SCALAR >* tree_;
112 double computeCost_(
const Pattern& p);
124 template <
typename GUM_SCALAR >
125 class FrequenceSearch:
public SearchStrategy< GUM_SCALAR > {
133 explicit FrequenceSearch(Size freq);
136 FrequenceSearch(
const FrequenceSearch& from);
139 virtual ~FrequenceSearch();
142 FrequenceSearch& operator=(
const FrequenceSearch& from);
150 virtual bool accept_root(
const Pattern* r);
152 virtual bool accept_growth(
const Pattern* parent,
153 const Pattern* child,
154 const EdgeGrowth< GUM_SCALAR >& growth);
156 virtual bool operator()(LabelData* i, LabelData* j);
157 virtual bool operator()(Pattern* i, Pattern* j);
174 template <
typename GUM_SCALAR >
175 class StrictSearch:
public SearchStrategy< GUM_SCALAR > {
183 explicit StrictSearch(Size freq = 2);
186 StrictSearch(
const StrictSearch& from);
189 virtual ~StrictSearch();
192 StrictSearch& operator=(
const StrictSearch& from);
200 virtual bool accept_root(
const Pattern* r);
202 virtual bool accept_growth(
const Pattern* parent,
203 const Pattern* child,
204 const EdgeGrowth< GUM_SCALAR >& growth);
206 virtual bool operator()(LabelData* i, LabelData* j);
207 virtual bool operator()(Pattern* i, Pattern* j);
212 double _inner_cost_(
const Pattern* p);
213 double _outer_cost_(
const Pattern* p);
214 void _compute_costs_(
const Pattern* p);
215 HashTable<
const Pattern*, std::pair<
double,
double > > _map_;
221 NodeProperty< Size > mod;
226 Bijection< NodeId, std::string > node2attr;
230 Bijection< NodeId,
const DiscreteVariable* > vars;
237 std::string _str_(
const PRMInstance< GUM_SCALAR >* i,
238 const PRMAttribute< GUM_SCALAR >* a)
const;
239 std::string _str_(
const PRMInstance< GUM_SCALAR >* i,
240 const PRMAttribute< GUM_SCALAR >& a)
const;
241 std::string _str_(
const PRMInstance< GUM_SCALAR >* i,
242 const PRMSlotChain< GUM_SCALAR >& a)
const;
243 void _buildPatternGraph_(
typename StrictSearch< GUM_SCALAR >::PData& data,
244 Set< Potential< GUM_SCALAR >* >& pool,
245 const Sequence< PRMInstance< GUM_SCALAR >* >& match);
246 std::pair< Size, Size > _elimination_cost_(
typename StrictSearch< GUM_SCALAR >::PData& data,
247 Set< Potential< GUM_SCALAR >* >& pool);
259 template <
typename GUM_SCALAR >
260 class TreeWidthSearch:
public SearchStrategy< GUM_SCALAR > {
271 TreeWidthSearch(
const TreeWidthSearch& from);
274 virtual ~TreeWidthSearch();
277 TreeWidthSearch& operator=(
const TreeWidthSearch& from);
285 double cost(
const Pattern& p);
287 virtual bool accept_root(
const Pattern* r);
289 virtual bool accept_growth(
const Pattern* parent,
290 const Pattern* child,
291 const EdgeGrowth< GUM_SCALAR >& growth);
293 virtual bool operator()(LabelData* i, LabelData* j);
294 virtual bool operator()(Pattern* i, Pattern* j);
298 HashTable<
const Pattern*,
double > _map_;
302 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 303 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 304 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 305 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 306 extern template class SearchStrategy<
double >;
311 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 312 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 313 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 314 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 315 extern template class FrequenceSearch<
double >;
320 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 321 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 322 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 323 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 324 extern template class StrictSearch<
double >;
329 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 330 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 331 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 332 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 333 extern template class TreeWidthSearch<
double >;
344 #include <agrum/PRM/gspan/searchStrategy_tpl.h>