Newer
Older
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
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ctype.h>
#ifndef __USE_POSIX
#define __USE_POSIX
#endif
#include <signal.h>
#include <time.h>
#include "decompose.h"
#include "graph.h"
#include "lire.h"
#include "lists.h"
#include "main.h"
#include "separator.h"
#include "utils.h"
volatile sig_atomic_t stopSearch = 0;
char file_name[555], *last_name;
FILE *fileSolution = NULL;
#ifdef PACE_2020
int pace_2020 = 1;
#else
int pace_2020 = 0;
#endif
int nb_runs = 100000;
int algo = SEPARE_AND_EXPLORE ; //SEPARE_AND_EXPLORE; GREEDY_ALGORITHM
int noSwapsInFirstRuns = 0; // Do not improve for the first explorations
int timeWithNoSwaps = 50; // proportion of the total time with no improvement
int sizeSwitchToGreedy = 0; // switch to greedy algorithm when nb vertices is les than this.
int preliminaryGreedyDecomposition = 0; // perform a preliminary greedy search,
int maxSizePrelimGreedy = 350000; //350000; for instance heur_187
int maxDepthGreedy = 777; //25000;
int depthThreshold = 1; // threshold above which the current run is abandoned, compared with the best first height
int perForceChoiceNotInC = NONE; // Initialized before each separation if modeEvalAtRandom is true
int perChooseInCAtRandom = 1; // Choice in C at random
int nbRunsSeparation = 30; // 1 or 5
int nbFlushes = 101; // default is 100,
int ratioMin = 5; // min=5 max=55
int ratioMax = 55; // too small ratioMax stops the flush (>50)
int modeEvalSeparator = EVAL_CARD; // EVAL_SQRT_CARD EVAL_TREE_HEIGHT_COMPLETE_GRAPH EVAL_MINIMIZE_C EVAL_CARD EVAL_MIN_A_B
double coeffHeightNbEdges = 2.0; // coefficient used to estimate the height for a given number of edges. Ponderates the evaluation against the cardinal of C.
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
int searchSwapsInCriticalBranch = 1; // improve version april 2020
int pullUpIndependentSubtrees = 1; // before swaps, pull up independent critical subtrees
int maxMakeSwapsRestarts = 10; // the number of restarts of the improve process Without height decrease
int printStats = 0;
int compressTree = 0; // not used
int trace = 0;
clock_t startTime;
int printSolution = 0;
int printResult = 1;
int time_limit = 30;
void term(int signum) {
stopSearch = 1;
}
/***********************************************
* Main *
**********************************************/
int main (int nargs, char ** args)
{
Graph g;
FILE *f = stdin;
if (1) {
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler = term;
sigaction(SIGTERM, &action, NULL);
// signal(SIGTERM, sig_handler);
// signal(SIGINT, sig_handler);
}
srand(time(NULL));
if (pace_2020) {
nb_runs = 1000000; //100000;
noSwapsInFirstRuns = 0;
printSolution = 1;
printResult = 0;
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
preliminaryGreedyDecomposition = 1;
goto START_SOLVE;
}
for (int i = 1; i < nargs; i ++) {
if (strcmp(args[i], "-file") == 0) {
i ++;
if (i == nargs)
goto USAGE;
strcpy(file_name, args[i]);
f = fopen(file_name, "r");
if (f == NULL) {
printf("unable to open file %s\n", file_name);
goto USAGE;
}
}
else if (strcmp(args[i], "-save_solution") == 0) {
i ++;
if (i == nargs)
goto USAGE;
fileSolution = fopen(args[i], "w");
if (fileSolution == NULL) {
printf("Output abandoned :: unable to open file %s\n", args[i]);
goto USAGE;
}
printSolution = 1;
}
else if (strcmp(args[i], "-auto") == 0) {
noSwapsInFirstRuns = 1;
nb_runs = 10000;
}
else if (strcmp(args[i], "-runs") == 0) {
i ++;
if (i == nargs)
goto USAGE;
nb_runs = atoi(args[i]);
}
else if (strcmp(args[i], "-s") == 0) {
i ++;
if (i == nargs)
goto USAGE;
srand(atoi(args[i]));
}
else if (strcmp(args[i], "-time") == 0) {
i ++;
if (i == nargs)
goto USAGE;
time_limit = atoi(args[i]);
}
else if (strcmp(args[i], "-trace") == 0) {
trace = 1;
}
else if (strcmp(args[i], "-no_solution") == 0) {
printSolution = 0;
}
else if (strcmp(args[i], "-no_improve") == 0) {
searchSwapsInCriticalBranch = 0;
pullUpIndependentSubtrees = 0;
}
else if (strcmp(args[i], "-no_pullup") == 0) {
pullUpIndependentSubtrees = 0;
}
else if (strcmp(args[i], "-no_swaps") == 0) {
searchSwapsInCriticalBranch = 0;
}
else if (strcmp(args[i], "-sep_runs") == 0) {
i ++;
if (i == nargs)
goto USAGE;
nbRunsSeparation = atoi(args[i]);
}
else if (strcmp(args[i], "-max_time_sep") == 0) {
i ++;
if (i == nargs)
goto USAGE;
maxTimeSeparation = atoi(args[i]);
}
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
else if (strcmp(args[i], "-per_choice_AB") == 0) {
i ++;
if (i == nargs)
goto USAGE;
perForceChoiceNotInC = atoi(args[i]);
}
else if (strcmp(args[i], "-per_chrand_C") == 0) {
i ++;
if (i == nargs)
goto USAGE;
perChooseInCAtRandom = atoi(args[i]);
}
else if (strcmp(args[i], "-flushes") == 0) {
i ++;
if (i == nargs)
goto USAGE;
nbFlushes = atoi(args[i]);
}
else if (strcmp(args[i], "-ratios") == 0) {
i ++;
if (i == nargs)
goto USAGE;
ratioMin = atoi(args[i]);
i ++;
if (i == nargs)
goto USAGE;
ratioMax = atoi(args[i]);
}
else if (strcmp(args[i], "-threshold") == 0) {
i ++;
if (i == nargs)
goto USAGE;
depthThreshold = atoi(args[i]);
}
else if (strcmp(args[i], "-eval") == 0) {
i ++;
if (i == nargs)
goto USAGE;
modeEvalSeparator = atoi(args[i]);
modeEvalAtRandom = 0;
}
else if (strcmp(args[i], "-tree_height_eval") == 0) {
i ++;
if (i == nargs)
goto USAGE;
modeEvalSeparator = EVAL_TREE_HEIGHT_COMPLETE_GRAPH;
modeEvalAtRandom = 0;
coeffHeightNbEdges = (double) (atoi(args[i])) / 100;
}
else if (strcmp(args[i], "-greedy") == 0) {
algo = GREEDY_ALGORITHM;
}
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
algo = SEPARE_AND_EXPLORE;
}
else
goto USAGE;
}
if (f != stdin) {
char *s = file_name;
last_name = s;
while (*s != '\0') {
if (*s == '/')
last_name = s+1;
s ++;
}
}
START_SOLVE:
startTime = clock();
g = lireGraphe(f);
if (trace) printf("n=%d m=%d\n", g->n, g->m);
testDecompose(g, nb_runs, algo);
return 0;
USAGE:
printf("Usage :: ./treedepth [-file <file name>] [-greedy] [-separe] [-runs <nb runs>] [-s <number>] [-trace] \\"
"[-save_solution <file name>] [-no_solution] [-no_improve] [-no_pullup] [-no_swaps]\\"
"[-sep_runs <nb runs>] [-max_time_sep <duration>] [-flushes <nb flushes>] \\"
"[-per_choice_AB <per>] [-per_chrand_C <per>] \\"
"[-ratios <min> <max>] [-threshold <per>] [-eval <mode>] \\"
"[-greedy] [-separe]\n");