Repository navigation
Expand file tree
/
Copy pathesch_tuples.cpp
More file actions
215 lines (201 loc) · 7.28 KB
/
Copy pathesch_tuples.cpp
File metadata and controls
215 lines (201 loc) · 7.28 KB
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
#include "esch_tuples.h"
using std::deque;
#include <vector>
using std::vector;
#include "aux_feedback.h"
#include <algorithm>
//////////////////////////////////////////////////
void SpaceTuple::print(FILE* file) const
{
for(const Space& E : *this)
{
E.print(file);
}
return;
}
void SpaceTupleList::print(const char* filename, const size_t& max_tuples)
{
Feedback feedback;
FILE *file = fopen(filename, "w");
if (file == NULL) feedback.message("Error opening file!\n");
//// sort tuples by size, in descending order:
feedback.message("Sorting ...\r");
std::stable_sort(this->begin(),this->end());
feedback.message("Counting ...\r");
// count total number of pairs, triples, tuples of length 3, ...:
// counter_[0] = number of singletons (already known)
// counter_[1] = number of pairs
// conuter_[2] = ...
size_t counter_total = singletons;
vector< std::size_t > counter(1);
counter[0] = singletons;
for(const SpaceTuple& F : *this)
{
std::size_t s = F.size();
if (s > counter.size())
counter.resize(s,0);
++counter[s-1];
++counter_total;
}
//size_t counter_C_failures = test_condition_C();
// print "statistics" to screen and to file (number of tuples of each length):
if (this->indeterminacies == 0)
{
std::string text = ">> %9lld different " + description + " in this range (no problem with condition C)\n";
printf( text.c_str(),(long long)counter_total);
fprintf(file, text.c_str(),(long long)counter_total);
}
else
{
std::string text_screen = ">> %9lld to %lld different " + description + " in this range\n";
std::string text_file = text_screen;
text_screen += "! failure of condition C leads to %lld indeterminacies !\n";
text_file += "\n!! The count is imprecise because, for some spaces, condition C fails, and the";
text_file += "\n!! computable parameters do not suffice to determine their " + description + ". \n\n";
text_file += "In the statistics and the lists below, the " + description + " of these spaces\n";
text_file += "are (probably incorrectly) identified with " + description + " of other spaces.\n";
text_file += "So the actual number of singletons may be higher than the number displayed, while\n";
text_file += " the actual number of pairs/triples/... may be smaller.\n\n";
printf( text_screen.c_str(), (long long)counter_total,(long long)(counter_total+this->indeterminacies),(long long)(this->indeterminacies));
fprintf(file, text_file.c_str(), (long long)counter_total,(long long)(counter_total+this->indeterminacies),(long long)(this->indeterminacies));
}
for(std::size_t c = 1; c <= counter.size(); ++c)
{
std::string text;
if (c == 1)
text = ">> %9lld " + description + " defined by just %ld parameter vector (k1,k2,k3,l1,l2,l3)\n";
else if (c >= 2)
text = ">> %9lld " + description + " defined by %ld different parameter vectors\n";
printf(text.c_str(), counter[c-1], (long long)c);
fprintf(file,text.c_str(), counter[c-1], (long long)c);
}
// Print tuples to file, grouped by tuple length
printf("Writing to file %s ...",filename);
fflush(stdout);
for(std::size_t c = counter.size(); c >= 2; --c)
{
fprintf(file,"\n\n\n############################################ Tuples of length %ld ############################################\n",(long)c);
// As tuples are ordered by size in DESCENDING ORDER,
// start position = number of tuples of larger sizes:
std::size_t start = 0;
for(std::size_t i = c; i < counter.size(); ++i)
start += counter[i];
for(std::size_t i = 0; i < counter[c-1]; ++i)
{
fprintf(file," \nTuple %ld: \n", (long)i+1);
this->at(start + i).print(file);
if (i+11 >= max_tuples && i+11 < counter[c-1])
{
fprintf(file,"\n .\n .\n . skipping some tuples of length %ld \n .\n .\n",(long)c);
i = counter[c-1]-11;
}
}
fprintf(file,"\n\n\n");
}
fclose(file);
printf(" ... done.\n\n");
}
std::size_t SpaceTuple::compute_KS_invariants()
// (return value = number of spaces for which condition C fails)
{
std::size_t failures = 0;
for(Space& E : *this)
if (! E.compute_KS_invariants())
++failures;
return failures;
}
std::size_t SpaceTuple::test_condition_C()
// (return value = number of spaces for which condition C fails)
{
std::size_t failures = 0;
for(Space& E : *this)
if (! E.test_condition_C())
++failures;
return failures;
}
std::size_t SpaceTupleList::compute_KS_invariants()
// (return value = number of spaces for which condition C fails)
{
printf("Computing Kreck-Stolz-invariants s2 and s22 for non-singletons ...\n");
std::size_t failures = 0;
Feedback feedback;
feedback.start(this->size());
for(std::size_t i = 0; i < this->size(); ++i)
{
feedback.update(i);
failures += this->at(i).compute_KS_invariants();
}
feedback.finish();
printf("Invariants computed. ");
if(failures == 0)
printf("All spaces satisfy condition C.\n\n");
else
printf("\nWARNING: Condition C fails for %ld non-singletons.\n\n",(long)failures);
return failures;
}
std::size_t SpaceTupleList::test_condition_C()
// (return value = number of spaces for which condition C fails)
{
std::size_t failures = 0;
for(std::size_t i = 0; i < this->size(); ++i)
failures += this->at(i).test_condition_C();
return failures;
}
bool operator<(const SpaceTuple& T1, const SpaceTuple& T2) {
if (T1.size() > T2.size()) return true;// sort tuple sizes in descending order!
if (T1.size() < T2.size()) return false;
if (!(T1.empty()) && !(T2.empty())){
Space::comp tht = Space::compareTangentialHomotopyType(T1[0],T2[0]);
if (tht == Space::comp::SMALLER || tht == Space::comp::MAYBE_SMALLER) return true;
}
return false;
}
SpaceTupleList::SpaceTupleList(SpaceTupleList& original_list,
std::function<Space::comp(const Space& E1, const Space& E2)> compareFunction,
std::string description)
{
printf("%s\n",("Looking for " + description + " ...").c_str());
this->description = description;
this->indeterminacies = 0;
this->singletons = original_list.singletons;
Feedback feedback;
feedback.start(original_list.size());
for(std::size_t i = 0; i < original_list.size(); ++i)
{
feedback.update(i);
SpaceTuple& T = original_list[i];
std::stable_sort(T.begin(),T.end(),[&compareFunction](const Space& E1, const Space& E2) -> bool
{
Space::comp c = compareFunction(E1,E2);
return (c == Space::comp::GREATER || c == Space::comp::MAYBE_GREATER);
} );
for(std::size_t i1 = 0; i1 < T.size(); )// i1 is incremented indirectly via i2
{
std::size_t i2 = i1+1;
while (i2 < T.size())
{
Space::comp c = compareFunction(T[i1],T[i2]);
if(c == Space::comp::EQUAL)
++i2;
else if (c == Space::comp::MAYBE_EQUAL || c == Space::comp::MAYBE_GREATER)
{
++i2;
++(this->indeterminacies);
}
else break;
}
if(i2 > i1+1)
{
//all_spaces with indexes i1,...,i2 define spaces with the same invariants
SpaceTuple new_tuple;
for(std::size_t j = i1; j < i2; ++j)
new_tuple.push_back(T[j]);
this->push_back(new_tuple);
}
else if (i2 = i1+1)
++singletons;
i1 = i2;
}
}
feedback.finish();
}