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