libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNCombinatorics.h
Go to the documentation of this file.
1 /* Copyright 2008-2014 INSA Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNCombinatorics.h
19  * \author Jean DUONG
20  */
21 
22 #ifndef CRNCOMBINATORICS_HEADER
23 #define CRNCOMBINATORICS_HEADER
24 
25 #include <CRN.h>
26 #include <vector>
27 
28 namespace crn
29 {
30  /****************************************************************************/
40  namespace Combinatorics
41  {
43  int CountCombinations(int n, int p) noexcept;
45  int CountArrangements(int n, int p) noexcept;
46 
48  template <class ITER, class CMP> std::vector<typename std::iterator_traits<ITER>::value_type> Minimals(ITER i_begin, ITER i_end, CMP comp = std::less<typename std::iterator_traits<ITER>::value_type>())
49  {
50  std::vector<typename std::iterator_traits<ITER>::value_type> minimals;
51 
52  for (ITER i = i_begin; i != i_end; ++i)
53  {
54  ITER j = i_begin;
55  bool is_minimal = true;
56 
57  while ((j != i_end) && is_minimal)
58  {
59  if (j != i)
60  {
61  if(comp(*j, *i))
62  {
63  is_minimal = false;
64  }
65  else
66  {
67  ++j;
68  }
69  }
70  else
71  {
72  ++j;
73  }
74  }
75 
76  if (is_minimal)
77  {
78  minimals.push_back(*i);
79  }
80  }
81 
82  return minimals;
83  }
84  }
85 }
86 
87 #endif
int CountCombinations(int n, int p) noexcept
std::vector< typename std::iterator_traits< ITER >::value_type > Minimals(ITER i_begin, ITER i_end, CMP comp=std::less< typename std::iterator_traits< ITER >::value_type >())
int CountArrangements(int n, int p) noexcept