-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcoxiter.cpp
3505 lines (2887 loc) · 112 KB
/
coxiter.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
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 "coxiter.h"
CoxIter::CoxIter()
: checkCocompactness(false), checkCofiniteness(false), bCoutFile(false),
debug(false), isGramMatrixFieldKnown(false),
isGrowthSeriesComputed(false), hasBoldLine(false), hasDottedLine(false),
hasDottedLineWithoutWeight(0), bWriteInfo(false), isGraphExplored(false),
isGraphsProductsComputed(false), useOpenMP(true), brEulerCaracteristic(0),
graphsList_spherical(nullptr), graphsList_euclidean(nullptr),
dimension(0), euclideanMaxRankFound(0), sphericalMaxRankFound(0),
isDimensionGuessed(false), fVectorAlternateSum(0), isArithmetic(-1),
isCocompact(-2), isFiniteCovolume(-2), verticesAtInfinityCount(0),
verticesCount(0), outCout(0), sBufOld(0), error(""),
ouputMathematicalFormat("generic") {
#ifndef _OPENMP
this->useOpenMP = false;
#endif
}
CoxIter::CoxIter(const vector<vector<unsigned int>> &matrix,
const unsigned int &dimension)
: checkCocompactness(false), checkCofiniteness(false), bCoutFile(false),
isGramMatrixFieldKnown(false), isGraphExplored(false),
isGraphsProductsComputed(false), isGrowthSeriesComputed(false),
hasBoldLine(false), hasDottedLine(false), hasDottedLineWithoutWeight(0),
bWriteInfo(false), debug(false), useOpenMP(true), brEulerCaracteristic(0),
graphsList_spherical(nullptr), graphsList_euclidean(nullptr),
dimension(dimension), euclideanMaxRankFound(0), sphericalMaxRankFound(0),
isDimensionGuessed(false), fVectorAlternateSum(0), isCocompact(-2),
isFiniteCovolume(-2), verticesAtInfinityCount(0), verticesCount(0),
outCout(0), sBufOld(0), error(""), ouputMathematicalFormat("") {
verticesCount = matrix.size();
initializations();
coxeterMatrix = matrix;
maximalSubgraphRank = dimension ? dimension : verticesCount;
#ifndef _OPENMP
this->useOpenMP = false;
#endif
}
CoxIter::~CoxIter() {
if (graphsList_spherical)
delete graphsList_spherical;
if (graphsList_euclidean)
delete graphsList_euclidean;
// if cout is redirected to a file
if (bCoutFile) {
outCout->close();
cout.rdbuf(sBufOld); // we restore the cout
}
}
bool CoxIter::bRunAllComputations() {
if (!coxeterMatrix.size())
return false;
if (!isGraphExplored)
exploreGraph();
if (!isGraphsProductsComputed)
computeGraphsProducts();
if (!computeEulerCharacteristicFVector())
return false;
if (checkCofiniteness)
checkCovolumeFiniteness();
if (checkCocompactness)
isGraphCocompact();
return true;
}
#ifndef _COMPILE_WITHOUT_REGEXP_
bool CoxIter::parseGraph(istream &streamIn) {
string line;
PCRERegexp regexp;
PCREResult regexpRes;
// loops variable, first vertice, second vertice, weight, number of vertices,
// index of the current row
unsigned int i, i1, i2, i3, verticesFileCount, rowIndex(1);
vector<unsigned int> orders; // orders found
// ---------------------------------------------------------------------------
// Reading the number of vertices and, eventually, dimension
if (getline(streamIn, line)) {
if (regexp.preg_match_all("([[:digit:]]+)[[:space:]]?([[:digit:]]*)", line,
regexpRes) == 1) {
verticesFileCount = verticesCount = stoi(regexpRes[1][0]);
dimension = regexpRes[2][0] != "" ? stoi(regexpRes[2][0]) : 0;
} else {
error = "First line with number of vertices missing";
return false;
}
} else {
error = "EMPTY_FILE";
return false;
}
// ---------------------------------------------------------------------------
// first line
if (!getline(streamIn, line)) {
error = "EMPTY_FILE";
return false;
}
// names of the vertices
if (regexp.preg_match_all("^vertices labels:[[:space:]]?([[:alnum:]-_ ]+)$",
line, regexpRes)) {
vector<string> elements(explode(" ", regexpRes[1][0]));
if (elements.size() != verticesFileCount) {
error = "VERTICES_LABEL_COUNT";
return false;
}
for (i = 0; i < verticesFileCount; i++) {
map_vertices_labelToIndex[elements[i]] = i;
map_vertices_indexToLabel.push_back(elements[i]);
}
if (map_vertices_labelToIndex.size() != verticesFileCount) {
error = "VERTICES_LABEL_COUNT";
return false;
}
if (!getline(streamIn, line)) {
error = "EMPTY_FILE";
return false;
}
} else {
for (i = 0; i < verticesFileCount; i++) {
map_vertices_labelToIndex[to_string(i + 1)] = i;
map_vertices_indexToLabel.push_back(to_string(i + 1));
}
}
bool bRemoveDottedEdges(false); // If we want to remove dotted edges
// ---------------------------------------------------------------------------
// removed vertices
vector<unsigned int> verticesShift(verticesFileCount,
0); // Shifts for the removed vertices
unsigned int truncCount(0);
if (vertices.size()) // If we want to specify a subset of the vertices
{
auto allVertices(map_vertices_indexToLabel);
sort(allVertices.begin(), allVertices.end());
set_difference(allVertices.begin(), allVertices.end(), vertices.begin(),
vertices.end(), std::back_inserter(verticesToRemove));
sort(verticesToRemove.begin(), verticesToRemove.end());
}
for (const auto &vertexToRemove : verticesToRemove) {
if (vertexToRemove == "dotted" &&
map_vertices_labelToIndex.find("dotted") ==
map_vertices_labelToIndex.end()) // remove dotted edges?
{
bRemoveDottedEdges = true;
continue;
}
if (map_vertices_labelToIndex.find(vertexToRemove) ==
map_vertices_labelToIndex.end()) {
error = "This vertex does not exist: " + vertexToRemove;
return false;
}
truncCount++;
for (i = map_vertices_labelToIndex[vertexToRemove]; i < verticesFileCount;
i++)
verticesShift[i]++;
}
verticesCount -= truncCount;
// ---------------------------------------------------------------------------
// initializations
initializations(); // now that we know the real number of vertices
// ---------------------------------------------------------------------------
// reading the graph
do {
regexpRes.clear();
// Usual row: "first vertice" "second vertice" "weight"
if (regexp.preg_match_all(
"([[:alnum:]_-]+)[[:space:]]([[:alnum:]_-]+)[[:space:]]([[:digit:]]"
"+)([[:space:]]+#[[:space:]]*([^\n]+))?",
line, regexpRes)) {
if (map_vertices_labelToIndex.find(regexpRes[1][0]) ==
map_vertices_labelToIndex.end()) {
error = "The following vertex is unknown: " + regexpRes[1][0];
return false;
}
if (map_vertices_labelToIndex.find(regexpRes[2][0]) ==
map_vertices_labelToIndex.end()) {
error = "The following vertex is unknown: " + regexpRes[2][0];
return false;
}
i1 = map_vertices_labelToIndex[regexpRes[1][0]];
i2 = map_vertices_labelToIndex[regexpRes[2][0]];
i3 = stoi(regexpRes[3][0]);
if (i3 == 1 && bRemoveDottedEdges)
i3 = 2;
rowIndex++;
// Removed vertex?
if (binary_search(verticesToRemove.begin(), verticesToRemove.end(),
regexpRes[1][0]) ||
binary_search(verticesToRemove.begin(), verticesToRemove.end(),
regexpRes[2][0]))
continue;
// on tient compte du décalage lié à la troncation
i1 -= verticesShift[i1];
i2 -= verticesShift[i2];
// on garde le poids (pour corps engendré par les coefficients de la
// matrice de Gram)
if (find(orders.begin(), orders.end(), i3) == orders.end())
orders.push_back(i3);
if (i3 == 1) // Weight of the dotted line given?
{
if (regexpRes.size() > 5) {
unsigned int index(linearizationMatrix_index(min(i1, i2), max(i1, i2),
verticesCount));
weightsDotted[index] = regexpRes[5][0];
} else
hasDottedLineWithoutWeight = 1;
}
// si on avait déjà cette arête avec un ordre différent
if (coxeterMatrix[i1][i2] != 2 && coxeterMatrix[i1][i2] != i3) {
error = "Edge has multiple orders (" + regexpRes[1][0] + "," +
regexpRes[2][0] + ")";
return false;
}
coxeterMatrix[i1][i2] = i3;
coxeterMatrix[i2][i1] = i3;
if (i3 == 1) // dotted
hasDottedLine = true;
else if (i3 == 0)
hasBoldLine = true;
} else if (line != "") {
if (bWriteInfo)
cout << "Unread line (incorrect format): "
<< "#" << line << "#" << rowIndex << endl;
rowIndex++;
continue;
}
} while (getline(streamIn, line));
// ---------------------------------------------------------------------------
// Labels and co
auto v_ItL(map_vertices_indexToLabel);
map_vertices_indexToLabel.clear();
map_vertices_labelToIndex.clear();
unsigned int j(0);
for (unsigned int i(0); i < verticesFileCount; i++) {
if ((!i && !verticesShift[i]) ||
(i && verticesShift[i] == verticesShift[i - 1])) {
map_vertices_indexToLabel.push_back(v_ItL[i]);
map_vertices_labelToIndex[v_ItL[i]] = j++;
}
}
maximalSubgraphRank = dimension ? dimension : verticesCount;
// ---------------------------------------------------------------------------
// some information
if (bWriteInfo) {
cout << "Reading graph: " << endl;
cout << "\tNumber of vertices: " << verticesCount << endl;
cout << "\tDimension: " << (dimension ? to_string(dimension) : "?") << endl;
cout << "\tVertices: ";
for (vector<string>::const_iterator itStr(
map_vertices_indexToLabel.begin());
itStr != map_vertices_indexToLabel.end(); ++itStr)
cout << (itStr != map_vertices_indexToLabel.begin() ? ", " : "")
<< *itStr;
cout << endl;
}
// ---------------------------------------------------------------------------
// Field generated by the entries of the Gram matrix
bool hasDottedLine = false;
for (const auto &order : orders) {
if (order == 1) { // dotted line
hasDottedLine = true;
break;
} else if (order == 4)
gramMatrixField += (gramMatrixField == "" ? "sqrt(2)" : ", sqrt(2)");
else if (order == 5)
gramMatrixField += (gramMatrixField == "" ? "sqrt(5)" : ", sqrt(5)");
else if (order == 6)
gramMatrixField += (gramMatrixField == "" ? "sqrt(3)" : ", sqrt(3)");
else if (order >= 7) // le static_cast est là pour VC++
gramMatrixField +=
(gramMatrixField == ""
? "cos(pi/" + to_string(static_cast<long long>(order)) + ")"
: ", cos(pi/" + to_string(static_cast<long long>(order)) + ")");
}
if (!hasDottedLine) {
gramMatrixField =
gramMatrixField == "" ? "Q" : ("Q[" + gramMatrixField + "]");
isGramMatrixFieldKnown = true;
if (bWriteInfo)
cout << "\tField generated by the entries of the Gram matrix: "
<< gramMatrixField << endl;
} else {
if (bWriteInfo)
cout << "\tField generated by the entries of the Gram matrix: ?" << endl;
}
if (bWriteInfo)
cout << "File read\n" << endl;
return true;
}
bool CoxIter::readGraphFromFile(const string &inputFilename) {
// ---------------------------------------------------------------------------
// try to open the file
ifstream fileIn(inputFilename.c_str());
if (fileIn.fail()) {
error = "Cannot open file";
return false;
}
if (!parseGraph(fileIn))
return false;
fileIn.close();
return true;
}
#endif
void CoxIter::initializations() {
// ------------------------------------------------------
// de initializations
if (graphsList_spherical)
delete graphsList_spherical;
if (graphsList_euclidean)
delete graphsList_euclidean;
graphsProductsCount_spherical.clear();
graphsProductsCount_euclidean.clear();
factorials.clear();
powersOf2.clear();
isGraphExplored = false;
isGraphsProductsComputed = false;
// ------------------------------------------------------
// initializations
coxeterMatrix = vector<vector<unsigned int>>(
verticesCount, vector<unsigned int>(verticesCount, 2));
visitedVertices = vector<bool>(verticesCount, false);
visitedEdges =
vector<vector<bool>>(verticesCount, vector<bool>(verticesCount, false));
graphsList_spherical =
new GraphsList(verticesCount, &map_vertices_indexToLabel);
graphsList_euclidean =
new GraphsList(verticesCount, &map_vertices_indexToLabel);
graphsProductsCount_euclidean =
vector<map<vector<vector<short unsigned int>>, unsigned int>>(
verticesCount + 1,
map<vector<vector<short unsigned int>>, unsigned int>());
graphsProductsCount_spherical =
vector<map<vector<vector<short unsigned int>>, unsigned int>>(
verticesCount + 1,
map<vector<vector<short unsigned int>>, unsigned int>());
// ------------------------------------------------------------
// sauvegarde de quelques calculs
factorials = vector<mpz_class>(verticesCount + 2, 1);
powersOf2 = vector<mpz_class>(verticesCount + 2, 1);
for (unsigned int i(1); i <= verticesCount + 1; i++) {
factorials[i] = factorials[i - 1] * (long int)i;
powersOf2[i] = mpz_class(2) * powersOf2[i - 1];
}
}
bool CoxIter::writeGraph(const string &outFilenameBasis) {
if (outFilenameBasis == "") {
error = "No file specified for writing the graph";
return false;
}
map_vertices_labels_create();
string filename(outFilenameBasis + ".coxiter");
ofstream out(filename.c_str());
if (!out.is_open()) {
error = "Cannot open the file for writing the graph";
return false;
}
out << verticesCount << (dimension ? " " + to_string(dimension) : "") << endl;
out << "vertices labels: ";
for (vector<string>::const_iterator it(map_vertices_indexToLabel.begin());
it != map_vertices_indexToLabel.end(); ++it)
out << (it == map_vertices_indexToLabel.begin() ? "" : " ") << *it;
out << endl;
for (unsigned int i(0); i < verticesCount; i++) {
for (unsigned int j(0); j < i; j++) {
if (coxeterMatrix[i][j] != 2)
out << map_vertices_indexToLabel[j] << " "
<< map_vertices_indexToLabel[i] << " " << coxeterMatrix[i][j]
<< endl;
}
}
out.close();
return true;
}
void CoxIter::map_vertices_labels_create() {
if (map_vertices_indexToLabel.size())
return; // nothing to do
for (unsigned int i(0); i < verticesCount; i++) {
map_vertices_labelToIndex[to_string(i + 1)] = i;
map_vertices_indexToLabel.push_back(to_string(i + 1));
}
}
void CoxIter::map_vertices_labels_reinitialize() {
map_vertices_labelToIndex.clear();
map_vertices_indexToLabel.clear();
for (unsigned int i(0); i < verticesCount; i++) {
map_vertices_labelToIndex[to_string(i + 1)] = i;
map_vertices_indexToLabel.push_back(to_string(i + 1));
}
}
bool CoxIter::writeGraphToDraw(const string &outFilenameBasis) {
unsigned int i, j;
map_vertices_labels_create();
// ----------------------------------------------------------------------
// ouverture du fichier
if (outFilenameBasis == "") {
error = "No file specified for writing the graph";
return false;
}
string filename(outFilenameBasis + ".graphviz");
ofstream out(filename.c_str());
if (!out.is_open()) {
error = "Cannot open the file for writing the graph";
return false;
}
// ----------------------------------------------------------------------
// écriture à proprement parler
out << "graph G { " << endl;
for (i = 0; i < verticesCount; i++)
out << "\t\"" << map_vertices_indexToLabel[i] << "\";" << endl;
for (i = 0; i < verticesCount; i++) {
for (j = i + 1; j < verticesCount; j++) {
if (coxeterMatrix[i][j] > 3)
out << "\t\"" << map_vertices_indexToLabel[i] << "\" -- \""
<< map_vertices_indexToLabel[j] << "\" [label=\""
<< coxeterMatrix[i][j] << "\"];" << endl;
else if (coxeterMatrix[i][j] > 2)
out << "\t\"" << map_vertices_indexToLabel[i] << "\" -- \""
<< map_vertices_indexToLabel[j] << "\";" << endl;
else if (coxeterMatrix[i][j] == 1)
out << "\t\"" << map_vertices_indexToLabel[i] << "\" -- \""
<< map_vertices_indexToLabel[j] << "\" [style=dotted];" << endl;
else if (coxeterMatrix[i][j] == 0)
out << "\t\"" << map_vertices_indexToLabel[i] << "\" -- \""
<< map_vertices_indexToLabel[j] << "\" [label=\"inf\"];" << endl;
}
}
out << "}";
out.close();
return true;
}
void CoxIter::exploreGraph() {
vector<short unsigned int> vertices;
short unsigned int i, j, k, l;
if (!verticesCount)
throw(string("CoxIter::exploreGraph: No graph given"));
if (isGraphExplored)
return;
// -------------------------------------------------------------------
// pour chaque sommet, on cherche toutes les chaînes qui partent, ce qui donne
// les An, Bn, Dn, En, Hn
path.clear();
for (i = 0; i < verticesCount; i++) {
path.clear();
visitedVertices = vector<bool>(verticesCount, false);
visitedEdges =
vector<vector<bool>>(verticesCount, vector<bool>(verticesCount, false));
DFS(i, i);
}
// -------------------------------------------------------------------
// recherche des A_1, G_2^k avec k >= 4, F_4
vector<bool> linkableVertices, linkableVerticesTemp;
for (i = 0; i < verticesCount; i++) {
linkableVertices = vector<bool>(verticesCount, true);
for (j = 0; j < verticesCount; j++) {
if (coxeterMatrix[i][j] != 2)
linkableVertices[j] = false;
}
// ajout du sommet (A_1)
linkableVertices[i] = false;
graphsList_spherical->addGraph(vector<short unsigned int>(1, i),
linkableVertices, 0, true);
// on regarde si on trouve avec ce sommet: Gn, TA1 ,TC2
for (j = 0; j < verticesCount; j++) {
if (coxeterMatrix[i][j] >= 4 || !coxeterMatrix[i][j]) {
// ------------------------------------------------------------------
// G2 et TA1
if (i < j) {
vertices.clear();
vertices.push_back(i);
vertices.push_back(j);
linkableVerticesTemp = linkableVertices;
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[j][k] != 2)
linkableVerticesTemp[k] = false;
}
if (coxeterMatrix[i][j]) // ici, c'est un graphe sphérique
graphsList_spherical->addGraph(vertices, linkableVerticesTemp, 6,
true, 0, 0, coxeterMatrix[i][j]);
else // ici, graphe euclidien (TA1)
graphsList_euclidean->addGraph(vertices, linkableVerticesTemp, 0,
false, 0, 0, 0);
}
// ------------------------------------------------------------------
// TC2 = [ 4, 4 ]
if (coxeterMatrix[i][j] == 4) {
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[k][j] == 4 && i != k &&
coxeterMatrix[i][k] == 2) {
linkableVerticesTemp = linkableVertices;
for (l = 0; l < verticesCount; l++) {
if (coxeterMatrix[k][l] != 2)
linkableVerticesTemp[l] = false;
if (coxeterMatrix[j][l] != 2)
linkableVerticesTemp[l] = false;
}
graphsList_euclidean->addGraph(vector<short unsigned int>(1, j),
linkableVerticesTemp, 2, false, i,
k);
}
}
}
}
}
}
isGraphExplored = true;
}
void CoxIter::DFS(unsigned int root, unsigned int from) {
// -------------------------------------------------------------------
// initializations
bool subcall(false); // to know if we call DFS
unsigned int i;
/*
* We don't want cycles
* We mark neighbours of from as visited (to avoir cycles)
* We stock this in verticesVisited to restore it at the end
*/
vector<unsigned int> visitedVerticesIdx;
if (root != from) {
for (i = 0; i < verticesCount; i++) {
if (coxeterMatrix[from][i] != 2) {
if (!visitedVertices[i])
visitedVerticesIdx.push_back(i);
visitedVertices[i] = true;
}
}
} else
visitedVertices[root] = true; // obviously...
// -------------------------------------------------------------------
// DFS
path.push_back(root); // we add root to the path
for (i = 0; i < verticesCount; i++) {
// if we have an edge AND if i was not traversed AND if the edge (root,i)
// was not traversed
if (coxeterMatrix[root][i] == 3 && !visitedVertices[i] &&
!visitedEdges[root][i]) {
visitedEdges[root][i] = visitedEdges[i][root] = true;
subcall = true;
DFS(i, root);
}
}
// -------------------------------------------------------------------
// un-initializations
for (const auto &visitedVertex : visitedVerticesIdx)
visitedVertices[visitedVertex] = false;
visitedVertices[root] = false;
if (from != root) // If it is a recursive call
visitedEdges[root][from] = visitedEdges[from][root] = false;
// If DFS was not called, then the path is maximal
if (!subcall)
addGraphsFromPath();
path.pop_back();
}
void CoxIter::addGraphsFromPath() {
// sommets que l'on ne peut pas lier au graphe (n sommets);
vector<bool> linkableVertices(verticesCount, true);
// sommets que l'on ne peut pas lier au graphe (n-1 sommets), sommets que l'on
// ne peut pas lier au graphe (n-2 sommets)
vector<bool> linkableVertices_0_nMin1(verticesCount, true),
linkableVertices_0_nMin2(verticesCount, true);
// sommets que l'on ne peut pas lier au graphe (1 --> n), sommets que l'on ne
// peut pas lier au graphe (1 --> n-1), , sommets que l'on ne peut pas lier au
// graphe (2 --> n)
vector<bool> linkableVertices_1_n(verticesCount, true),
linkableVertices_1_nMin1(verticesCount, true),
linkableVertices_2_n(verticesCount, true);
// vecteur temporaire
vector<bool> linkableVerticesTemp, linkableVerticesTempTemp;
// chemin en cours de construction
vector<short unsigned int> pathTemp;
// i, j, k, l: variables de boucles
short unsigned int i, j, k, l, max(path.size()), iOrder;
for (i = 0; i < max; i++) {
pathTemp.push_back(path[i]);
// --------------------------------------------------------------------
// mise à jour des voisinages occupés
for (j = 0; j < verticesCount; j++) {
if (coxeterMatrix[path[i]][j] != 2)
linkableVertices[j] = false;
if (i >= 1 && coxeterMatrix[path[i]][j] != 2)
linkableVertices_1_n[j] = false;
if (i >= 2 && coxeterMatrix[path[i]][j] != 2)
linkableVertices_2_n[j] = false;
if (i >= 1 && coxeterMatrix[path[i - 1]][j] != 2)
linkableVertices_0_nMin1[j] = false;
if (i >= 2 && coxeterMatrix[path[i - 1]][j] != 2)
linkableVertices_1_nMin1[j] = false;
if (i >= 2 && coxeterMatrix[path[i - 2]][j] != 2)
linkableVertices_0_nMin2[j] = false;
}
// --------------------------------------------------------------------
// An
if (i != 0) // on ajoute pas les sommets
graphsList_spherical->addGraph(pathTemp, linkableVertices, 0, true);
// --------------------------------------------------------------------
// TAn, n >= 2
if (i >= 1) {
linkableVertices_1_nMin1[pathTemp[i - 1]] = false;
for (j = 0; j < verticesCount; j++) {
// si la partie centrale ne pose pas de problème ET qu'on est lié à
// chaque extrémité
if (linkableVertices_1_nMin1[j] && !linkableVertices[j] &&
coxeterMatrix[j][pathTemp[0]] == 3 &&
coxeterMatrix[j][pathTemp[i]] == 3) {
// mise à jour des linkables avec le somme trouvé
linkableVerticesTemp = linkableVertices;
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[k][j] != 2)
linkableVerticesTemp[k] = false;
}
graphsList_euclidean->addGraph(
pathTemp, linkableVerticesTemp, 0, false, j, 0,
1); // TODO OPTIMIZATION modifier ce 1 (relatif à une meilleure
// valeur que "0" par défaut pour les dernières variables)
}
}
}
// --------------------------------------------------------------------
// Dn, TBn, TDn
if (i >= 2) {
linkableVertices_0_nMin2[pathTemp[i - 2]] = false;
// --------------------------------------------------------------------
// Dn, TBn (n >= 4), TDn (n >= 4)
// on regarde les voisins de l'avant dernier sommet
for (j = 0; j < verticesCount; j++) {
// si y'a une arête ET si on est pas déjà dans le chemin ET si pas
// interdit ET pas lien entre deux extrémités
if (coxeterMatrix[j][pathTemp[i - 1]] == 3 &&
(pathTemp[i - 1] != j && pathTemp[i] != j) &&
linkableVertices_0_nMin2[j] && coxeterMatrix[j][pathTemp[i]] == 2) {
linkableVerticesTemp = linkableVertices;
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[k][j] != 2)
linkableVerticesTemp[k] = false;
}
graphsList_spherical->addGraph(pathTemp, linkableVerticesTemp, 3,
true, j); // Dn
// --------------------------------------------------------------------
// ici, on va tenter de trouver un TD_n (n >= 4) (i.e. prolonger par
// une arrête au 2ème sommet)
for (k = 0; k < verticesCount; k++) {
if (k != pathTemp[0] && k != j && k != pathTemp[i] &&
coxeterMatrix[pathTemp[1]][k] == 3 && linkableVertices_2_n[k] &&
coxeterMatrix[pathTemp[0]][k] == 2 &&
coxeterMatrix[k][j] == 2) {
linkableVerticesTempTemp = linkableVerticesTemp;
for (l = 0; l < verticesCount; l++) {
if (coxeterMatrix[k][l] != 2)
linkableVerticesTempTemp[l] = false;
}
graphsList_euclidean->addGraph(pathTemp, linkableVerticesTempTemp,
3, false, k, j); // TDn
}
}
// --------------------------------------------------------------------
// ici, on va tenter de trouver un TB_n (n >= 4) (i.e. prolonger par
// une arête de poids 4 à gauche)
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[pathTemp[0]][k] == 4 && linkableVertices_1_n[k] &&
coxeterMatrix[j][k] == 2) {
linkableVerticesTempTemp = linkableVerticesTemp;
for (l = 0; l < verticesCount; l++) {
if (coxeterMatrix[k][l] != 2)
linkableVerticesTempTemp[l] = false;
}
graphsList_euclidean->addGraph(pathTemp, linkableVerticesTempTemp,
1, false, j, k, 1); // TBn
}
}
}
// --------------------------------------------------------------------
// TB3
if (i == 2) {
if (coxeterMatrix[pathTemp[1]][j] == 4 &&
coxeterMatrix[pathTemp[0]][j] == 2 &&
coxeterMatrix[pathTemp[2]][j] == 2) {
linkableVerticesTemp = linkableVertices;
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[k][j] != 2)
linkableVerticesTemp[k] = false;
}
graphsList_euclidean->addGraph(pathTemp, linkableVerticesTemp, 1,
false, j); // TB3
}
}
}
}
// --------------------------------------------------------------------
// E6, E7, E8, TE6, TE7, TE8
if (i >= 4 && i <= 7) {
AnToEn_AnToTEn(pathTemp, linkableVertices);
}
// --------------------------------------------------------------------
// Bn, F4 et Hn, TG2, TCn et TF4
if (i >= 1) {
for (j = 0; j < verticesCount;
j++) // on regarde si on peut prolonger la chaîne de 1 avec une arête
// de poids 4
{
/*
* Le premier paquet de conditions donne:
* Prolonger par une arrête de poids 4 --> Cn ; sphérique
* Prolonger par une arrête de poids 5 si (2 ou 3 sommets)
* --> (H3 ou H4) ; sphérique Prolonger par une arrête de poids 6 --> [
* 3, 6 ] ; euclidien
*/
if (((coxeterMatrix[path[i]][j] == 4) ||
(coxeterMatrix[path[i]][j] == 5 && (i == 1 || i == 2)) ||
(coxeterMatrix[path[i]][j] == 6 && i == 1)) &&
linkableVertices_0_nMin1[j]) {
iOrder = coxeterMatrix[path[i]][j];
linkableVerticesTemp = linkableVertices;
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[k][j] != 2)
linkableVerticesTemp[k] = false;
}
if (coxeterMatrix[path[i]][j] < 6) // sphérique
graphsList_spherical->addGraph(pathTemp, linkableVerticesTemp,
(iOrder == 4 ? 1 : 7), true, j);
else
graphsList_euclidean->addGraph(pathTemp, linkableVerticesTemp, 6,
false, j, 0, 1);
auto linkableVerticesTemp_bck(
linkableVerticesTemp); // Contains info for: pathTemp + j
// ------------------------------------------
// on va tenter de prolonger cela en un TCn, n \geq 3
if (coxeterMatrix[path[i]][j] == 4) {
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[k][pathTemp[0]] == 4 && k != j &&
linkableVertices_1_n[k] && coxeterMatrix[k][j] == 2) {
// Additional info for vertex k
for (l = 0; l < verticesCount; l++) {
if (coxeterMatrix[k][l] != 2)
linkableVerticesTemp[l] = false;
}
graphsList_euclidean->addGraph(pathTemp, linkableVerticesTemp,
2, false, k, j);
linkableVerticesTemp =
linkableVerticesTemp_bck; // Restoring to info of pathTemp
// and j
}
}
}
// ------------------------------------------
// ici, on a un B3, que l'on va tenter de prolonger en F4 ou un B4 que
// l'on va tenter de prolonger en un TF4
if ((i == 1 || i == 2) && coxeterMatrix[path[i]][j] == 4)
B3ToF4_B4ToTF4(linkableVertices_0_nMin1, pathTemp, j);
} // if (((coxeterMatrix[ path[i] ][j] == 4) || (coxeterMatrix[
// path[i] ][j] == 5 && (i == 1 || i == 2)) || (coxeterMatrix[
// path[i] ][j] == 6 && i == 1)) && linkableVertices_0_nMin1[j])
}
}
}
}
void CoxIter::AnToEn_AnToTEn(const vector<short unsigned int> &pathTemp,
const vector<bool> &linkableVertices) {
unsigned int pathSize(pathTemp.size());
/*
* 2 pour le sommets 3 (i.e. cas sphérique: E6, E7, E8 ou car euclidien
* \tilde E8) 3 pour le sommet 4 (i.e. cas euclidien: \tilde E7)
*/
bool isSpherical(pathSize <= 7 ? true : false);
unsigned int iStart(isSpherical || pathSize == 8 ? 2 : 3);
// E6, E7, E8, \tilde E8
AnToEn_AnToTEn(pathTemp, linkableVertices, isSpherical, iStart);
if (pathSize == 7) // \tile E7
AnToEn_AnToTEn(pathTemp, linkableVertices, false, 3);
}
void CoxIter::AnToEn_AnToTEn(const vector<short unsigned int> &pathTemp,
const vector<bool> &linkableVertices,
const bool &isSpherical,
const short unsigned int &start) {
unsigned int pathSize(pathTemp.size()), j, k, l;
vector<bool> linkableVerticesTemp, linkableVerticesTempTemp;
/*
* Ici, on a donc un An (n=5, 6 ou 7) avec 1 -- 2 -- 3 -- 4 -- 5 ...
* On va cherche si iStart a un voisin admissible
*/
for (unsigned int i(0); i < verticesCount; i++) {
// si le sommet est pas utilisbale (s'il l'est c'est qu'il n'est pas voisin
// de la base) ET si y'a un lien
if (false == linkableVertices[i] &&
coxeterMatrix[i][pathTemp[start]] == 3) {
// on va chercher si c'est uniquement à cause d'un des sommets différents
// de iStart que le sommet n'est pas admissible
for (j = 0; j < pathSize; j++) {
if (j != start && coxeterMatrix[pathTemp[j]][i] != 2)
break;
}
if (j == pathSize) // admissible
{
linkableVerticesTemp = linkableVertices;
for (k = 0; k < verticesCount; k++) {
if (coxeterMatrix[i][k] != 2)
linkableVerticesTemp[k] = false;
}
if (isSpherical) {
graphsList_spherical->addGraph(pathTemp, linkableVerticesTemp, 4,
true, i); // En
// on a un E6 qu'on va tenter de prolonger en un TE6
if (pathSize == 5) {
for (j = 0; j < verticesCount; j++) {
if (coxeterMatrix[i][j] == 3 && linkableVertices[j]) {
linkableVerticesTempTemp = linkableVerticesTemp;
for (l = 0; l < verticesCount; l++) {
if (coxeterMatrix[j][l] != 2)
linkableVerticesTempTemp[l] = false;
}
graphsList_euclidean->addGraph(
pathTemp, linkableVerticesTempTemp, 4, false, i, j); // En
}
}
}
} else
graphsList_euclidean->addGraph(pathTemp, linkableVerticesTemp, 4,
false, i); // TEn
}
}
}
}