Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

1035599 views
1
//
2
// reduce_complex.cpp
3
// Bistellar
4
//
5
// Created by Alexander Thumm on 22.10.11.
6
// Copyright 2011 -. All rights reserved.
7
//
8
9
10
#include "reduce_complex.h"
11
12
#include <iostream>
13
#include <stdlib.h>
14
#include <time.h>
15
16
const unsigned int baseHeating = 4;
17
const unsigned int baseRelaxation = 3;
18
19
20
void reduce_complex(MovableComplex & complex, unsigned int rounds, int heating, int relaxation)
21
{
22
if (complex.dimension() == 0)
23
return;
24
25
// initialize the RNG
26
srand(static_cast<unsigned int>(time(0)));
27
28
MovableComplex minimalComplex = complex;
29
30
for (int currentRound = 1; currentRound < rounds; currentRound++)
31
{
32
// select move
33
bistellar_move_list_t moves;
34
35
if (complex.dimension() < 3)
36
{
37
unsigned int i = complex.dimension();
38
while (moves.empty())
39
{
40
moves = complex.validMoves(i);
41
i--;
42
}
43
}
44
else if (complex.dimension() == 3)
45
{
46
if (heating > 0)
47
{
48
if (heating % 15 == 0)
49
{
50
moves = complex.validMoves(0);
51
}
52
else
53
{
54
moves = complex.validMoves(1);
55
if (moves.empty())
56
{
57
moves = complex.validMoves(2);
58
heating = 0;
59
}
60
}
61
heating--;
62
}
63
else
64
{
65
moves = complex.validMoves(3);
66
if (moves.empty())
67
{
68
moves = complex.validMoves(2);
69
if (moves.empty())
70
{
71
moves = complex.validMoves(1);
72
if (relaxation == 10)
73
{
74
heating = 15;
75
relaxation = 0;
76
}
77
relaxation++;
78
}
79
}
80
}
81
}
82
else if (complex.dimension() == 4)
83
{
84
if (heating > 0)
85
{
86
if (heating % 20 == 0)
87
{
88
moves = complex.validMoves(0);
89
}
90
else
91
{
92
moves = complex.validMoves(1);
93
bistellar_move_list_t temp = complex.validMoves(2);
94
if (!temp.empty())
95
moves.insert(moves.begin(), temp.begin(), temp.end());
96
97
if (moves.empty())
98
moves = complex.validMoves(3);
99
}
100
heating--;
101
}
102
else
103
{
104
moves = complex.validMoves(4);
105
if (moves.empty())
106
{
107
moves = complex.validMoves(3);
108
if (moves.empty())
109
{
110
moves = complex.validMoves(2);
111
bistellar_move_list_t temp = complex.validMoves(1);
112
if (!temp.empty())
113
moves.insert(moves.begin(), temp.begin(), temp.end());
114
115
if (relaxation == 10)
116
{
117
heating = 20;
118
relaxation = 0;
119
}
120
relaxation++;
121
}
122
}
123
}
124
}
125
else if (complex.dimension() == 5)
126
{
127
if (heating > 0)
128
{
129
if (heating % 40 == 0)
130
{
131
moves = complex.validMoves(0);
132
}
133
else
134
{
135
moves = complex.validMoves(1);
136
bistellar_move_list_t temp = complex.validMoves(2);
137
if (!temp.empty())
138
moves.insert(moves.begin(), temp.begin(), temp.end());
139
temp = complex.validMoves(3);
140
if (!temp.empty())
141
moves.insert(moves.begin(), temp.begin(), temp.end());
142
143
if (moves.empty())
144
moves = complex.validMoves(4);
145
}
146
heating--;
147
}
148
else
149
{
150
moves = complex.validMoves(5);
151
if (moves.empty())
152
{
153
moves = complex.validMoves(4);
154
if (moves.empty())
155
{
156
moves = complex.validMoves(3);
157
if (moves.empty())
158
{
159
moves = complex.validMoves(2);
160
bistellar_move_list_t temp = complex.validMoves(1);
161
if (!temp.empty())
162
moves.insert(moves.begin(), temp.begin(), temp.end());
163
164
if (relaxation == 20)
165
{
166
heating = 40;
167
relaxation = 0;
168
}
169
relaxation++;
170
}
171
}
172
}
173
}
174
175
}
176
else
177
{
178
if (heating > 0)
179
{
180
//if (heating % ((complex.dimension()+2)*baseHeating) == 0)
181
//{
182
// moves = complex.validMoves(0);
183
//}
184
//else
185
//{
186
for (unsigned int i = 1; i < complex.dimension()/2 + 1; i++)
187
{
188
bistellar_move_list_t temp = complex.validMoves(i);
189
if (!temp.empty())
190
moves.insert(moves.begin(), temp.begin(), temp.end());
191
}
192
//}
193
if (moves.empty())
194
{
195
for (unsigned int i = 1; i < complex.dimension()+2; i++)
196
{
197
bistellar_move_list_t temp = complex.validMoves(complex.dimension() + 1 - i);
198
if (!temp.empty())
199
{
200
moves.insert(moves.begin(), temp.begin(), temp.end());
201
if (i > (complex.dimension()-1)/2)
202
break;
203
}
204
}
205
}
206
heating--;
207
}
208
else
209
{
210
if (complex.dimension() % 2 == 1)
211
{
212
for (unsigned int i = 1; i < (complex.dimension()+1)/2 + 1; i++)
213
{
214
bistellar_move_list_t temp = complex.validMoves(complex.dimension() + 1 - i);
215
if (!temp.empty())
216
{
217
moves = temp;
218
break;
219
}
220
}
221
}
222
else
223
{
224
for (unsigned int i = 1; i < std::min((complex.dimension()+1)/2 + 1, complex.dimension())+1; i++)
225
{
226
bistellar_move_list_t temp = complex.validMoves(complex.dimension() + 1 - i);
227
if (!temp.empty())
228
{
229
moves = temp;
230
break;
231
}
232
}
233
}
234
if (moves.empty())
235
{
236
for (unsigned int i = 1; i < std::min((complex.dimension()+1)/2 + 1, complex.dimension())+1; i++)
237
{
238
bistellar_move_list_t temp = complex.validMoves(i);
239
if (!temp.empty())
240
{
241
moves = temp;
242
break;
243
}
244
}
245
}
246
if (relaxation == (complex.dimension()+2)*baseRelaxation)
247
{
248
//heating = (complex.dimension()+2)*baseHeating;
249
heating = 1;
250
relaxation = 0;
251
}
252
relaxation++;
253
}
254
}
255
256
// perform move
257
if (moves.size() == 0)
258
break;
259
260
BistellarMove move = moves.at(rand() % moves.size());
261
complex.moveComplex(move);
262
263
if (complex.f(0) < minimalComplex.f(0))
264
{
265
minimalComplex = complex;
266
std::cout << "found complex with " << minimalComplex.f(0) << " vertices in round " << currentRound << std::endl;
267
268
}
269
}
270
complex = minimalComplex;
271
}
272
273