oILAB
Loading...
Searching...
No Matches
OrderedTuplet.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 2/23/24.
3//
4
5#ifndef OILAB_ORDEREDTUPLET_H
6#define OILAB_ORDEREDTUPLET_H
7#include<Eigen/Eigen>
8#include<LatticeCore.h>
9
10namespace gbLAB {
11 template <int dim>
12 class OrderedTuplet : public Eigen::Matrix<typename LatticeCore<dim>::IntScalarType,dim,1>
13 {
14 public:
15
16 OrderedTuplet() = default;
17
18 // Define < operator to use std::map<OrderedTuplet,std::vector<int>>
19 bool operator<(const OrderedTuplet &rhs) const {
20 for(int i=0; i<dim-1; ++i)
21 {
22 if (this->operator()(i) < rhs(i)) return true;
23 if (rhs(i) < this->operator()(i)) return false;
24 }
25 if (this->operator()(dim-1) < rhs(dim-1)) return true;
26 return false;
27 /*
28 if (this->operator()(0) < rhs(0)) return true;
29 if (rhs(0) < this->operator()(0)) return false;
30 if (this->operator()(1) < rhs(1)) return true;
31 if (rhs(1) < this->operator()(1)) return false;
32 if (this->operator()(2) < rhs(2)) return true;
33 if (rhs(2) < this->operator()(2)) return false;
34 if (this->operator()(3) < rhs(3)) return true;
35 return false;
36 */
37 }
38
39 virtual ~OrderedTuplet() {}
40 };
41
42 class XTuplet : public Eigen::Matrix<int,Eigen::Dynamic,1>
43 {
44 public:
45 XTuplet(const int& sz) : Eigen::Matrix<int,Eigen::Dynamic,1>(sz)
46 {}
47
48 static void generate_tuples(int n, int k, std::vector<XTuplet>& results, XTuplet& current_tuple, int index) {
49 if (index == k) {
50 results.push_back(current_tuple); // Add current tuple to results
51 } else {
52 for (int i = 0; i < n; ++i) {
53 current_tuple(index) = i; // Assign current element
54 generate_tuples(n, k, results, current_tuple, index + 1); // Recursively generate next element
55 }
56 }
57 }
58
68 static std::vector<XTuplet> generate_tuples(int n, int k) {
69 std::vector<XTuplet> results;
70 XTuplet current_tuple(k); // Initialize a vector of size k with 0s
71 current_tuple.setZero();
72
73
74 generate_tuples(n, k, results, current_tuple, 0); // Start generating tuples from index 0
75
76 return results;
77 }
78
79 static void generate_tuples(std::vector<int> n, int k, std::vector<XTuplet>& results, XTuplet& current_tuple, int index) {
80 if (index == k) {
81 results.push_back(current_tuple); // Add current tuple to results
82 } else {
83 for (int i = 0; i < n[index]; ++i) {
84 current_tuple(index) = i; // Assign current element
85 generate_tuples(n, k, results, current_tuple, index + 1); // Recursively generate next element
86 }
87 }
88 }
89
99 static std::vector<XTuplet> generate_tuples(std::vector<int> n, int k) {
100 assert(n.size() == k);
101 std::vector<XTuplet> results;
102 XTuplet current_tuple(k); // Initialize a vector of size k with 0s
103 current_tuple.setZero();
104
105
106 generate_tuples(n, k, results, current_tuple, 0); // Start generating tuples from index 0
107
108 return results;
109 }
110
111 // Define < operator to use std::map<OrderedTuplet,std::vector<int>>
112 bool operator<(const XTuplet& rhs) const {
113 for (int i = 0; i < rhs.size()-1; ++i) {
114 if (this->operator()(i) < rhs(i)) return true;
115 if (rhs(i) < this->operator()(i)) return false;
116 }
117 if (this->operator()(rhs.size()- 1) < rhs(rhs.size()- 1)) return true;
118 return false;
119 }
120
121
122 // this is a temporary fix
123 double density() const
124 {
125 double density= 0.0;
126 for (int stateIndex = 0; stateIndex < (*this).size(); ++stateIndex) {
127 if(stateIndex==0 or stateIndex==1)
128 if((*this).operator()(stateIndex) == 2 )
129 density= density - 1;
130 if(stateIndex>=2 and stateIndex<=(*this).size()/2) {
131 if ((*this).operator()(stateIndex) == 1)
132 density = density - 1;
133 if ((*this).operator()(stateIndex) == 2)
134 density = density - 2;
135 }
136 if(stateIndex>=(*this).size()/2+1 and stateIndex<(*this).size())
137 if((*this).operator()(stateIndex) == 1 )
138 density= density + 1;
139 }
140 return density;
141 }
142 };
143
144 static std::basic_ostream<char>& operator<<(std::basic_ostream<char>& s, const XTuplet& m) {
145 return s << m.transpose() ;
146 }
147}
148
149#endif //OILAB_ORDEREDTUPLET_H
bool operator<(const OrderedTuplet &rhs) const
XTuplet(const int &sz)
static void generate_tuples(int n, int k, std::vector< XTuplet > &results, XTuplet &current_tuple, int index)
static std::vector< XTuplet > generate_tuples(int n, int k)
double density() const
bool operator<(const XTuplet &rhs) const
static void generate_tuples(std::vector< int > n, int k, std::vector< XTuplet > &results, XTuplet &current_tuple, int index)
static std::vector< XTuplet > generate_tuples(std::vector< int > n, int k)
basic_ostream< char > & operator<<(basic_ostream< char > &s, const LatticeDirection< dim > &m)