Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
CombinationWithoutRepetition.h
Go to the documentation of this file.
1/* This file is part of MoDELib, the Mechanics Of Defects Evolution Library.
2 *
3 *
4 * MoDELib is distributed without any warranty under the
5 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
6 */
7
8#ifndef model_CombinationWithoutRepetition_H_
9#define model_CombinationWithoutRepetition_H_
10
11#include <Eigen/Dense>
12#include <Binomial.h>
13
14namespace model
15{
16
17 /**************************************************************************/
18 /**************************************************************************/
25 template <int N, int k>
27 {
28 static_assert(N>0,"N MUST BE >0.");
29 static_assert(k>0,"k MUST BE >0.");
30 static_assert(k<=N,"k MUST BE <=N.");
31 static constexpr int value=Binomial<N,k>::value;
32// enum{value=Binomial<N,k>::value};
33
34
35 template <typename T>
36 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
37 {
40 Eigen::Matrix<T,value,k> temp;
41 // Use Pascal rule to fill the combinations: bin(N,k) = bin(n-1,k-1) + bin(n-1,k)
42 temp<<(Eigen::Matrix<T,k,Binomial<N-1,k-1>::value>() << Eigen::Matrix<T,1,Binomial<N-1,k-1>::value>().Constant(pool(0)),
43 CombinationWithoutRepetition<N-1,k-1>::template combine<T>(pool.template segment<N-1>(1)).transpose()).finished().transpose(),
44 CombinationWithoutRepetition<N-1,k>::template combine<T>(pool.template segment<N-1>(1));
45
46
47 return temp;
48
49 }
50
51 };
52
53 /**************************************************************************/
54 /**************************************************************************/
55 // SPECIALIZATION FOR THE TERM BIN(N-1,k). The stop condition is reached at BIN(k,k)
56 template <int k>
58 {
59 static_assert(k>0,"k MUST BE >0.");
60 enum{N=k};
61 enum{value=Binomial<N,k>::value};
62
63
64 template <typename T>
65 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
66 {
68 return pool;
69 }
70
71 };
72
73 /**************************************************************************/
74 /**************************************************************************/
75 // SPECIALIZATION FOR THE TERM BIN(N-1,k-1). The stop condition is reached at BIN(N,1)
76 template <int N>
78 {
79 static_assert(N>0,"N MUST BE >0.");
80 enum{k=1};
81 enum{value=Binomial<N,k>::value};
82
83 template <typename T>
84 static Eigen::Matrix<T,value,k> combine(const Eigen::Matrix<T,1,N>& pool)
85 {
87 return pool;
88 }
89
90 };
91
92 /**************************************************************************/
93} // end namespace ctmath
94
95#endif
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
static Eigen::Matrix< T, value, k > combine(const Eigen::Matrix< T, 1, N > &pool)
int k
vertex temp