-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex2.cpp
172 lines (138 loc) · 5.49 KB
/
index2.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
Copyright (C) 2013-2017
Rafael Guglielmetti, rafael.guglielmetti@unifr.ch
*/
/*
This file is part of CoxIter.
CoxIter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
CoxIter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CoxIter. If not, see <http://www.gnu.org/licenses/>.
*/
#include "index2.h"
Index2::Index2(CoxIter *ci)
: ci(ci), verticesCount(ci->get_verticesCount()), iNewVerticesCount(0),
coxeterMatrix(ci->get_coxeterMatrix()) {}
bool Index2::isVertexAdmissible(const string &vertexLabel) {
if (!ci->isVertexValid(vertexLabel)) {
error = "Invalid vertex name: " + vertexLabel;
return false;
}
unsigned int index(ci->get_vertexIndex(vertexLabel));
for (unsigned int i(0); i < verticesCount; i++) {
if (coxeterMatrix[index][i] != 0 && coxeterMatrix[index][i] != 1 &&
(coxeterMatrix[index][i] % 2)) {
error =
"m(" + vertexLabel + "," + ci->get_vertexLabel(i) + ") is not even";
return false;
}
}
return true;
}
bool Index2::removeVertex(const string &vertexName) {
unsigned int weight;
// -------------------------------------------------------
// some verifications, firsts constructions
if (!isVertexAdmissible(vertexName))
return false;
vertex = ci->get_vertexIndex(vertexName);
// Remark: we don't merge the previous and the next loop. Thus, if there is a
// problem, we do not change the CoxIter object.
// -------------------------------------------------------
// new vertices
for (unsigned int i(0); i < verticesCount; i++) {
// If they don't commute, this will add a new vertex
if (coxeterMatrix[vertex][i] != 2) {
NewVertex nv;
nv.index = verticesCount + iNewVerticesCount - 1;
nv.originVertex = i;
nv.label = ci->get_vertexLabel(vertex) + "_" + ci->get_vertexLabel(i);
newVertices.push_back(nv);
ci->map_vertices_labels_addReference(nv.label);
iNewVerticesCount++;
}
}
ci->map_vertices_labels_removeReference(vertex);
// -------------------------------------------------------
// new adjacency matrix
for (unsigned int i(0); i <= (verticesCount + iNewVerticesCount - 1);
i++) // the -1 is for the vertex we removed
{
if (i == vertex)
continue;
iNewCox.push_back(
vector<unsigned int>(verticesCount + iNewVerticesCount - 1,
2)); // TODO: tout construire en une fois
}
// we fill the old values (upper left square)
for (unsigned int i(0); i < verticesCount; i++) {
if (i == vertex)
continue;
for (unsigned int j(0); j <= i; j++)
iNewCox[i > vertex ? i - 1 : i][j > vertex ? j - 1 : j] =
iNewCox[j > vertex ? j - 1 : j][i > vertex ? i - 1 : i] =
coxeterMatrix[i][j];
}
// -------------------------------------------------------
// weights of the new edges
for (vector<NewVertex>::const_iterator itNew(newVertices.begin());
itNew != newVertices.end();
++itNew) // Going through the set of new vertices
{
// A new vertex is of the form: t0 * sj * t0, where sj =
// NewVertex.iOriginVertex
// for every old vertex
for (unsigned int i(0); i < verticesCount;
i++) // Goal: find m(t0 * sj * t0, si)
{
if (i == vertex) // we removed this vertex
continue;
if ((*itNew).originVertex == i) // m(t0 * si * t0, si) = m(t0, si) / 2
weight = coxeterMatrix[vertex][i] == 0 || coxeterMatrix[vertex][i] == 1
? coxeterMatrix[vertex][i]
: coxeterMatrix[vertex][i] / 2;
else {
if (coxeterMatrix[i][vertex] ==
2) // If si commutes with t0, then m(t0 * sj * t0, si) = m(sj, si)
weight = coxeterMatrix[(*itNew).originVertex][i];
else if (coxeterMatrix[(*itNew).originVertex][vertex] != 2) {
if (coxeterMatrix[vertex][i] == 4 &&
coxeterMatrix[vertex][(*itNew).originVertex] == 4 &&
coxeterMatrix[i][(*itNew).originVertex] == 2)
weight = 0;
else
weight = 1;
} else
throw(string("Index2::removeVertex: Error")); // TODO: idem
}
iNewCox[i > vertex ? i - 1 : i][(*itNew).index] = weight;
iNewCox[(*itNew).index][i > vertex ? i - 1 : i] = weight;
}
// for every new vertex t0 * si * t0
for (vector<NewVertex>::const_iterator itNewSub(newVertices.begin());
itNewSub != itNew; ++itNewSub) {
iNewCox[(*itNew).index][(*itNewSub).index] =
coxeterMatrix[(*itNew).originVertex][(*itNewSub).originVertex];
iNewCox[(*itNewSub).index][(*itNew).index] =
coxeterMatrix[(*itNew).originVertex][(*itNewSub).originVertex];
}
}
ci->set_coxeterMatrix(iNewCox);
return true;
}
void Index2::printMatrix(vector<vector<unsigned int>> *iMatrix) {
for (vector<vector<unsigned int>>::const_iterator itRow(iMatrix->begin());
itRow != iMatrix->end(); ++itRow) {
for (vector<unsigned int>::const_iterator itCol((*itRow).begin());
itCol != (*itRow).end(); ++itCol)
cout << *itCol << " ";
cout << endl;
}
}
string Index2::get_error() const { return error; }