-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_ordering.cpp
87 lines (83 loc) · 3.08 KB
/
value_ordering.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
75
76
77
78
79
80
81
82
83
84
85
86
87
namespace ValueOrdering {
const int SEQUENTIAL_ORDERING = 0;
const int DIAGONAL_FREQUENCY_ORDERING = 1;
int currentOrdering;
int dim;
const int dx[] = {1, 1, -1, -1};
const int dy[] = {1, -1, 1, -1};
vector<int> diagonalFrequencyWithDomain(const Matrix &cur, const Cell &c, int domain) {
vector< int >diagonallyAdjacentColors;
for (int k = 0; k < 4; k++) {
Cell e(c.first+dx[k], c.second+dy[k]);
if (min(e.first, e.second) < 0 || max(e.first, e.second) >= dim) continue;
if (cur[e.first][e.second]) {
diagonallyAdjacentColors.push_back(cur[e.first][e.second]);
}
}
vector< pair< int , int > >vp;
for (int x = 1; x <= dim; x++) {
if (domain&(1<<x)) {
///contains x
vp.emplace_back(0, x);
for (int y : diagonallyAdjacentColors) {
vp.back().first += x == y;
}
}
}
sort(vp.rbegin(), vp.rend());
vector< int >v(vp.size());
for (int i = 0; i < vp.size(); i++) v[i] = vp[i].second;
return v;
}
vector<int> diagonalFrequencyWithoutDomain(const Matrix &cur, const Cell &c) {
vector< int >diagonallyAdjacentColors;
for (int k = 0; k < 4; k++) {
Cell e(c.first+dx[k], c.second+dy[k]);
if (min(e.first, e.second) < 0 || max(e.first, e.second) >= dim) continue;
if (cur[e.first][e.second]) {
diagonallyAdjacentColors.push_back(cur[e.first][e.second]);
}
}
vector< pair< int , int > >vp;
for (int x = 1; x <= dim; x++) {
///contains x
vp.emplace_back(0, x);
for (int y : diagonallyAdjacentColors) {
vp.back().first += x == y;
}
}
sort(vp.rbegin(), vp.rend());
vector< int >v(vp.size());
for (int i = 0; i < vp.size(); i++) v[i] = vp[i].second;
return v;
}
vector< int >getValueOrderWithDomain(const Matrix &cur, const Cell &c, int domain) {
dim = cur.size();
if (currentOrdering == DIAGONAL_FREQUENCY_ORDERING) {
return diagonalFrequencyWithDomain(cur, c, domain);
} else {
///currentOrdering == SEQUENTIAL_ORDERING
vector< int >v;
for (int x = 1; x <= dim; x++) {
if (domain&(1<<x)) {
///contains x
v.push_back(x);
}
}
return v;
}
}
vector< int >getValueOrderWithoutDomain(const Matrix &cur, const Cell &c) {
dim = cur.size();
if (currentOrdering == DIAGONAL_FREQUENCY_ORDERING) {
return diagonalFrequencyWithoutDomain(cur, c);
} else {
///currentOrdering == SEQUENTIAL_ORDERING
vector< int >v(dim);
for (int x = 1; x <= dim; x++) {
v[x-1] = x;
}
return v;
}
}
}