faif
Node.hpp
1 #ifndef FAIF_SEARCHING_NODE_HPP
2 #define FAIF_SEARCHING_NODE_HPP
3 
4 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
5 //msvc10.0 warnings for concepts
6 #pragma warning(disable:4510)
7 #pragma warning(disable:4610)
8 #endif
9 
10 #include <vector>
11 #include <ostream>
12 #include <algorithm>
13 #include <iterator>
14 #include <boost/bind.hpp>
15 #include <boost/smart_ptr.hpp>
16 #include <boost/concept_check.hpp>
17 
18 namespace faif {
19 
20  /**
21  \brief the namespace of searching algorithms and optimization algorithms
22  */
23  namespace search {
24 
25  /** \brief the struct to create node in search space from individual */
26  template<typename Individual> struct Node {
27  typedef boost::shared_ptr<Individual> PNode;
28  typedef std::vector<PNode> Path;
29  typedef std::vector<PNode> Children;
30  };
31 
32  /** \brief helping function for debugging */
33  template<typename Node>
34  inline std::ostream& operator<<(std::ostream& os, const std::vector<boost::shared_ptr<Node> >& path) {
35  std::transform( path.begin(), path.end(), std::ostream_iterator<Node>(os," "),
36  boost::bind(&boost::shared_ptr<Node>::operator*, _1) );
37  return os;
38  }
39 
40 
41  /** \brief the concept for node with children
42  */
43  template<typename Node>
44  struct NodeWithChildrenConcept : boost::EqualityComparable<Node> {
45  typedef typename Node::PNode PNode;
46  typedef typename Node::Children Children;
47 
48  BOOST_CONCEPT_USAGE(NodeWithChildrenConcept)
49  {
50  Children ch = n.getChildren(); //the method getChildren is required
51  ch.size(); //clear the warnings of unused variables
52  }
53  Node n;
54  };
55 
56  /** \brief the concept for node with final flag for search in tree-like structures
57  The function 'searchDepthFirst' and 'searchBreadthFirst' require this concept
58  */
59  template<typename Node>
60  struct NodeWithFinalFlagConcept : boost::EqualityComparable<Node> {
61  BOOST_CONCEPT_USAGE(NodeWithFinalFlagConcept)
62  {
63  bool fin = n.isFinal(); //the method isFinal is required
64  fin = fin == false; //clear the warnings of unused variables
65  }
66  Node n;
67  };
68 
69  /** \brief the concept for informed search algorithms, it check the presence of 'getWeight' method,
70  used by informed search functions e.g. 'searchUniformCost'
71  */
72  template<typename Node>
74  BOOST_CONCEPT_USAGE(TreeNodeWeightConcept)
75  {
76  n.getWeight();
77  }
78  Node n;
79  };
80 
81  /** \brief the concept for heuristic search algorithms, it check the presence of 'getHeuristic' method,
82  used by heuristic search functions e.g. 'searchAStar'
83  */
84  template<typename Node>
86  BOOST_CONCEPT_USAGE(TreeNodeHeuristicConcept)
87  {
88  n.getHeuristic();
89  }
90  Node n;
91  };
92 
93  } //namespace search
94 } //namespace faif
95 
96 #endif //FAIF_SEARCHING_NODE_HPP
Definition: Chain.h:17
the concept for heuristic search algorithms, it check the presence of &#39;getHeuristic&#39; method...
Definition: Node.hpp:85
the concept for node with children
Definition: Node.hpp:44
the struct to create node in search space from individual
Definition: Node.hpp:26
the concept for node with final flag for search in tree-like structures The function &#39;searchDepthFirs...
Definition: Node.hpp:60
the concept for informed search algorithms, it check the presence of &#39;getWeight&#39; method, used by informed search functions e.g. &#39;searchUniformCost&#39;
Definition: Node.hpp:73