Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Librarian.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/fragment/picking_old/concepts/Librarian.hh
11 /// @brief Librarian template for sorting through and extracting desired fragments
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 #ifndef INCLUDED_core_fragment_picking_old_concepts_Librarian_hh
15 #define INCLUDED_core_fragment_picking_old_concepts_Librarian_hh
16 
17 // unit headers
19 
24 
25 // type headers
26 #include <core/types.hh>
27 
28 // utility headers
29 // AUTO-REMOVED #include <utility/pointer/owning_ptr.hh>
30 // AUTO-REMOVED #include <utility/vector1.hh>
31 
32 // C++ headers
33 #include <algorithm>
34 #include <functional>
35 
36 #include <utility/vector1.fwd.hh>
37 #include <utility/pointer/owning_ptr.fwd.hh>
38 
39 namespace core {
40 namespace fragment {
41 namespace picking_old {
42 namespace concepts {
43 
44 
45 /// @brief Librarian template for sorting through and extracting desired fragments
46 template< typename Bookmark, typename ExtentEvaluator, typename ExtentGenerator, typename Library >
47 class Librarian {
48 
49 
50 public: // typedefs
51 
52 
53  typedef core::Size Size;
54 
57  typedef typename Library::Book Book;
58 
60  typedef typename Book::PageIterator PageIterator;
61  typedef typename Book::Page Page;
62 
63  typedef typename ExtentGenerator::Extent Extent;
64 
69 
71  typedef typename Bookmarks::const_iterator BookmarkConstIterator;
72  typedef typename Bookmarks::iterator BookmarkIterator;
73 
74 
75 protected: // typedefs
76 
77 
80 
81 
82 public: // construct/destruct
83 
84 
85  /// @brief default constructor
86  inline
87  Librarian() {}
88 
89 
90  /// @brief default destructor
91  inline
92  virtual
94 
95 
96 private: // disallow copy
97 
98 
99  /// @brief disallow copy constructor
100  // NOTE: If implementing copy in the future, remember to clone OPs.
101  Librarian( Librarian const & rval );
102 
103 
104  /// @brief disallow copy assignment
105  // NOTE: If implementing copy in the future, remember to clone OPs.
106  Librarian & operator =( Librarian const & rval );
107 
108 
109 public: // library operations
110 
111 
112  /// @brief create sorted list corresponding to fragments in Library
113  /// @details uses Bookmark < for evaluation
114  /// @return true if creation successful, false otherwise (e.g. no ExtentEvaluators or ExtentGenerators found)
115  inline
116  bool catalog( Library const & library ) {
117  return catalog( library, std::less< Bookmark >() );
118  }
119 
120 
121  /// @brief create sorted list corresponding to fragments in Library
122  /// @tparam LessThan predicate <tt> Pr( left, right ) </tt> evaluating <tt> left < right <tt> for Bookmarks
123  /// @return true if creation successful, false otherwise (e.g. no ExtentEvaluators or ExtentGenerators found)
124  template< typename LessThan >
125  bool catalog( Library const & library, LessThan const & lt ) {
126  using std::push_heap;
127  using std::sort_heap;
128 
129  if ( egen_.size() == 0 || eeval_.size() == 0 ) {
130  return false;
131  }
132 
133  bookmarks_.clear();
134 
135  for ( BookConstIterator book = library.begin(), end_of_library = library.end(); book != end_of_library; ++book ) {
136  for ( PageConstIterator page = book->begin(), end_of_book = book->end(); page != end_of_book; ++page ) {
137 
138  // run through extents generated from this page
139  for ( typename ExtentGenOPs::const_iterator e = egen_.begin(), ee = egen_.end(); e != ee; ++e ) {
140  Extent const extent = (**e)( page, end_of_book );
141 
142  if ( extent.valid ) {
143  Bookmark mark;
144  if ( evaluate_extent( extent, mark ) ) {
145  bookmarks_.push_back( mark );
146  push_heap( bookmarks_.begin(), bookmarks_.end(), lt ); // maintain heap property
147  }
148  }
149  } // foreach extent
150 
151  } // foreach page
152  } // foreach book
153 
154  // sort heap with ordering '<'
155  sort_heap( bookmarks_.begin(), bookmarks_.end(), lt );
156 
157  return true;
158  }
159 
160 
161 public: // extent management
162 
163 
164  /// @brief add an extent generator
165  inline
166  void add_extent_gen( ExtentGenCOP const & gen ) {
167  egen_.push_back( gen->clone() );
168  }
169 
170 
171  /// @brief clear list of generators
172  inline
174  egen_.clear();
175  }
176 
177 
178 public: // evaluator management
179 
180 
181  /// @brief add extent evaluator
182  inline
184  eeval_.push_back( val->clone() );
185  }
186 
187 
188  /// @brief clear list of evaluators
189  inline
191  eeval_.clear();
192  }
193 
194 
195 protected: // methods
196 
197 
198  /// @brief evaluate a fragment starting from Page at iterator
199  /// @return Bookmark containing scores for fragment
200  /// @remarks at least one helper needs to score the fragment extent
201  inline
202  bool evaluate_extent( Extent const & extent, Bookmark & mark ) {
203  bool extent_allowed = true;
204 
205  for ( typename ExtentEvalOPs::iterator i = eeval_.begin(), ie = eeval_.end(); extent_allowed && i != ie; ++i ) {
206  extent_allowed = extent_allowed && (**i)( extent, mark );
207  }
208 
209  return extent_allowed;
210  }
211 
212 
213  /// @brief get the current bookmark heap
214  inline
215  Bookmarks const & bookmarks() const {
216  return bookmarks_;
217  }
218 
219 
220  /// @brief get the current bookmark heap
221  inline
223  return bookmarks_;
224  }
225 
226 
227  /// @brief the list of extent generators
228  inline
229  ExtentGenOPs const & extent_gen() const {
230  return egen_;
231  }
232 
233 
234  /// @brief the list of extent generators
235  inline
237  return egen_;
238  }
239 
240 
241  /// @brief the list of extent evaluators
242  inline
243  ExtentEvalOPs const & extent_eval() const {
244  return eeval_;
245  }
246 
247 
248  /// @brief the list of extent evaluators
249  inline
251  return eeval_;
252  }
253 
254 
255 private: // data
256 
257 
258  /// @brief heap of bookmarks
259  /// @brief after catalog(), will be sorted w/respect to operator < of Bookmark
261 
262 
263  /// @brief generators for page extents
265 
266 
267  /// @brief list of page extent evaluators
269 
270 
271 };
272 
274 Librarian<core::fragment::picking_old::vall::scores::VallFragmentScore,
275  core::fragment::picking_old::vall::eval::VallFragmentEval,
276  core::fragment::picking_old::vall::gen::VallFragmentGen,
277  core::fragment::picking_old::vall::VallLibrary> {};
278 
279 } // concepts
280 } // picking_old
281 } // fragment
282 } // core
283 
284 
285 #endif /* INCLUDED_core_fragment_picking_old_concepts_Librarian_HH */