forked from sanshar/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OccRestrictions.cpp
75 lines (62 loc) · 2.08 KB
/
OccRestrictions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "global.h"
#include "OccRestrictions.h"
#include "input.h"
void OccRestrictions::setElec(vector<int>& closed) {
currentElec = 0;
for (int i=0; i<closed.size(); i++)
for (int x=0; x<orbs.size(); x++)
if (closed[i] == orbs[x]) currentElec++;
}
void OccRestrictions::setElec(int elec){
currentElec = elec;
}
bool OccRestrictions::oneElecAllowed(int i, int a) {
int elec = currentElec;
for (int x=0; x<orbs.size(); x++) {
if (orbs[x] == i) elec--;
if (orbs[x] == a) elec++;
}
if (elec < minElec || elec > maxElec) return false;
return true;
}
bool OccRestrictions::twoElecAllowed(int i, int j, int a, int b) {
int elec = currentElec;
for (int x=0; x<orbs.size(); x++) {
if (orbs[x] == i || orbs[x] == j) elec--;
if (orbs[x] == a || orbs[x] == b) elec++;
}
if (elec < minElec || elec > maxElec) return false;
return true;
}
void initiateRestrictions(vector<OccRestrictions>& restrictions, vector<int>& closed) {
for (int i=0; i< restrictions.size(); i++) {
OccRestrictions& res = restrictions[i];
res.setElec(closed);
if (res.currentElec < res.minElec ||
res.currentElec > res.maxElec ) {
Determinant det;
for (int k=0; k<closed.size(); k++)
det.setocc(closed[k], true);
cout << "Determinant: "<<det<<endl;
cout << "num elecs in orbs: "<<res.currentElec<<endl;
cout << "does not satisfy the restriction "<<restrictions[i]<<endl;
cout << "most likely the occupation of the initial determinant does not satisfy the restriction"<<endl;
exit(0);
}
}
}
bool satisfiesRestrictions(vector<OccRestrictions>& restrictions, int i, int a) {
for (int x=0; x<restrictions.size(); x++) {
OccRestrictions& res = restrictions[x];
if (!res.oneElecAllowed(i, a)) return false;
}
return true;
}
bool satisfiesRestrictions(vector<OccRestrictions>& restrictions,
int i, int j, int a, int b) {
for (int x=0; x<restrictions.size(); x++) {
OccRestrictions& res = restrictions[x];
if (!res.twoElecAllowed(i, j, a, b)) return false;
}
return true;
}