94b2b13d
Pedro Roque
PHACT source
|
1
2
3
4
|
/*
* actions.c
*
|
4d26a735
Pedro Roque
Increased recogni...
|
5
|
* Created on: 15/12/2017
|
94b2b13d
Pedro Roque
PHACT source
|
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
* Author: pedro
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// for elapsed time calculation under windows
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include <time.h>
#include <Winsock2.h>
#include <stdint.h>
#else
#include <sys/time.h>
#endif
|
4d26a735
Pedro Roque
Increased recogni...
|
23
|
|
94b2b13d
Pedro Roque
PHACT source
|
24
25
|
#include "../../constraints/all_different.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
26
27
28
29
30
31
|
#include "../../constraints/at_least.h"
#include "../../constraints/at_most_one.h"
#include "../../constraints/at_most.h"
#include "../../constraints/bool2int.h"
#include "../../constraints/bool_and.h"
#include "../../constraints/bool_clause.h"
|
94b2b13d
Pedro Roque
PHACT source
|
32
|
#include "../../constraints/bool_or.h"
|
94b2b13d
Pedro Roque
PHACT source
|
33
|
#include "../../constraints/element_int_var.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
34
|
#include "../../constraints/element_var.h"
|
94b2b13d
Pedro Roque
PHACT source
|
35
36
|
#include "../../constraints/element.h"
#include "../../constraints/eq.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
37
38
39
40
41
42
|
#include "../../constraints/eq_var.h"
#include "../../constraints/exactly_var.h"
#include "../../constraints/exactly.h"
#include "../../constraints/fake_all_different.h"
#include "../../constraints/ge.h"
#include "../../constraints/gt.h"
|
94b2b13d
Pedro Roque
PHACT source
|
43
|
#include "../../constraints/le.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
44
45
|
#include "../../constraints/linear_lt.h"
#include "../../constraints/linear_ne.h"
|
94b2b13d
Pedro Roque
PHACT source
|
46
|
#include "../../constraints/linear_var.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
47
|
#include "../../constraints/linear.h"
|
94b2b13d
Pedro Roque
PHACT source
|
48
|
#include "../../constraints/lt.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
49
|
#include "../../constraints/max.h"
|
94b2b13d
Pedro Roque
PHACT source
|
50
51
52
|
#include "../../constraints/maximize.h"
#include "../../constraints/min.h"
#include "../../constraints/minimize.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "../../constraints/minus_eq.h"
#include "../../constraints/minus_ne.h"
#include "../../constraints/ne.h"
#include "../../constraints/sum_prod.h"
#include "../../constraints/sum_var.h"
#include "../../constraints/sum.h"
#include "../../constraints/var_eq_minus.h"
#include "../../constraints/var_eq_minus_abs.h"
#include "../../constraints/var_eq_plus.h"
#include "../../constraints/var_eq_times.h"
#include "../../constraints.h"
#include "../benchmark.h"
#include "../../config.h"
#include "../../split.h"
|
94b2b13d
Pedro Roque
PHACT source
|
67
|
#include "../../variables.h"
|
94b2b13d
Pedro Roque
PHACT source
|
68
69
70
|
#include "../../bitmaps.h"
|
4d26a735
Pedro Roque
Increased recogni...
|
71
|
#include "actions.h"
|
94b2b13d
Pedro Roque
PHACT source
|
72
73
|
int FZN_OPTIMIZE = 0; // if the the optimization is for minimize or maximize
|
94b2b13d
Pedro Roque
PHACT source
|
74
75
|
int optimize_var_idx; // Index of the variable to optimize on the array fzn_vars
|
94b2b13d
Pedro Roque
PHACT source
|
76
77
78
79
80
81
82
|
int search_annot_ctr = 0; // Number of search annotations already received
int fzn_n_vars = FZN_MAX_ELEMENTS; // initial maximum number of variables (is extended if needed)
int fzn_n_constrs = FZN_MAX_ELEMENTS; // initial maximum number of constraints (is extended if needed)
int fzn_n_output_arrays = FZN_MAX_ARRAYS; // initial maximum number of arrays of variables to print
int fzn_n_arrays = FZN_MAX_ARRAYS; // initial maximum number of arrays of variables or constants (is extended if needed)
int fzn_n_constr_vals = FZN_MAX_ELEMENTS; // initial maximum number of values for a constraint (is extended if needed)
|
4d26a735
Pedro Roque
Increased recogni...
|
83
|
int fzn_n_search_annot = FZN_MAX_ELEMENTS; // initial maximum number of search annotations (is extended if needed)
|
94b2b13d
Pedro Roque
PHACT source
|
84
85
86
87
88
89
|
fzn_object fzn_obj; // FlatZinc object used until identification as an array, constraint or variable
fzn_var* fzn_vars; // Flatzinc representation of CSP variables
fzn_var* fzn_vars_aux; // To extend fzn_vars when needed
int fzn_next_var_posit = 0; // Index of fzn_vars where to place a new variable
|
4d26a735
Pedro Roque
Increased recogni...
|
90
|
|
94b2b13d
Pedro Roque
PHACT source
|
91
92
|
fzn_constr* fzn_constrs; // Flatzinc representation of a CSP constraint
fzn_constr* fzn_constrs_aux; // To extend fzn_constrs when needed
|
4d26a735
Pedro Roque
Increased recogni...
|
93
|
int fzn_next_constr_posit = 0; // Index of fzn_constrs where to place a new flatzinc constraint
|
94b2b13d
Pedro Roque
PHACT source
|
94
95
96
97
98
|
fzn_array* fzn_arrays; // Arrays for storing values that may be the ID of variables or constant values
fzn_array* fzn_arrays_aux; // To extend fzn_arrays when needed
int fzn_next_array_posit = 0; // Index of fzn_arrays where to place a new array
|
4d26a735
Pedro Roque
Increased recogni...
|
99
100
|
fzn_output_array* fzn_output_arrays; // Arrays for storing the ID of the variables that should be printed
fzn_output_array* fzn_output_arrays_aux; // To extend fzn_output_arrays when needed
|
94b2b13d
Pedro Roque
PHACT source
|
101
102
|
int fzn_next_output_array_posit = 0; // Index of fzn_output_arrays where to place a new array
|
4d26a735
Pedro Roque
Increased recogni...
|
103
104
|
fzn_search_annotat* fzn_search_annot; // For storing the search annotations
fzn_search_annotat* fzn_search_annot_aux; // To extend fzn_search_annot when needed
|
94b2b13d
Pedro Roque
PHACT source
|
105
106
|
int fzn_next_search_annot_posit = 0; // Index of fzn_search_annot where to place a new one
|
4d26a735
Pedro Roque
Increased recogni...
|
107
108
|
struct timeval start, end;
char start_time[40]; // for elapse time calculation
|
94b2b13d
Pedro Roque
PHACT source
|
109
110
|
char end_time[40]; // for elapse time calculation
char elapsed_time[40]; // for elapse time calculation
|
4d26a735
Pedro Roque
Increased recogni...
|
111
112
113
|
/*
* Translate the flatzinc file to a PHACT representation of a CSP
|
94b2b13d
Pedro Roque
PHACT source
|
114
|
*/
|
4d26a735
Pedro Roque
Increased recogni...
|
115
116
117
|
void parse(char* fzn_file_name) {
int i;
|
94b2b13d
Pedro Roque
PHACT source
|
118
|
gettimeofday(&start, NULL);
|
4d26a735
Pedro Roque
Increased recogni...
|
119
|
|
94b2b13d
Pedro Roque
PHACT source
|
120
|
if (!(yyin = fopen(fzn_file_name, "r"))) {
|
4d26a735
Pedro Roque
Increased recogni...
|
121
122
123
124
125
|
fprintf(stderr, "The file %s doesn't exist.\n", fzn_file_name);
exit(-1);
}
// create the structures needed for parsing
|
94b2b13d
Pedro Roque
PHACT source
|
126
127
128
|
fzn_obj.annots = malloc(FZN_MAX_ANNOTATIONS * (sizeof(char*)));
fzn_obj.elements = malloc(FZN_MAX_ELEMENTS * (sizeof(int)));
fzn_obj.element_is_var = malloc(FZN_MAX_ELEMENTS * (sizeof(bool)));
|
4d26a735
Pedro Roque
Increased recogni...
|
129
|
fzn_vars = malloc(fzn_n_vars * sizeof(fzn_var));
|
94b2b13d
Pedro Roque
PHACT source
|
130
|
fzn_constrs = malloc(fzn_n_constrs * sizeof(fzn_constr));
|
4d26a735
Pedro Roque
Increased recogni...
|
131
|
fzn_arrays = malloc(fzn_n_arrays * sizeof(fzn_array));
|
94b2b13d
Pedro Roque
PHACT source
|
132
133
134
135
136
|
fzn_output_arrays = malloc(fzn_n_output_arrays * sizeof(fzn_output_array));
fzn_search_annot = malloc(fzn_n_search_annot * sizeof(fzn_search_annotat));
for (i = 0; i < FZN_MAX_ANNOTATIONS; i++) {
fzn_obj.annots[i] = NULL;
|
4d26a735
Pedro Roque
Increased recogni...
|
137
138
139
140
141
142
143
144
|
}
fzn_obj.element_is_var_aux = NULL;
fzn_obj.elements_aux = NULL;
fzn_obj.annots_aux = NULL;
fzn_obj.next_annot = 0;
fzn_obj.max_annots = FZN_MAX_ANNOTATIONS;
fzn_obj.max_elements = FZN_MAX_ELEMENTS;
|
94b2b13d
Pedro Roque
PHACT source
|
145
146
147
148
149
150
|
fzn_obj.next_element = 0;
fzn_obj.is_array = false;
fzn_obj.is_constraint = false;
fzn_obj.pos_init_2_array = -1;
if (FZN_VERBOSE) {
|
4d26a735
Pedro Roque
Increased recogni...
|
151
152
153
154
155
|
printf("Parsing %s file.\n", fzn_file_name);
}
yyparse();
|
94b2b13d
Pedro Roque
PHACT source
|
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
|
if (FZN_VERBOSE)
printf("Finished parsing\n");
free(fzn_obj.annots);
free(fzn_obj.elements);
free(fzn_obj.element_is_var);
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].name != NULL) {
free(fzn_vars[i].name);
}
if (fzn_vars[i].values != NULL) {
free(fzn_vars[i].values);
}
}
free(fzn_vars);
for (i = 0; i < fzn_next_constr_posit; i++) {
if (fzn_constrs[i].next_var_to_add > 0) {
free(fzn_constrs[i].vars_id);
}
if (fzn_constrs[i].next_const_to_add > 0) {
free(fzn_constrs[i].consts);
}
if (fzn_constrs[i].name != NULL) {
free(fzn_constrs[i].name);
}
}
for (i = 0; i < fzn_next_array_posit; i++) {
free(fzn_arrays[i].values);
if (fzn_arrays[i].name != NULL) {
free(fzn_arrays[i].name);
}
}
free(fzn_arrays);
for (i = 0; i < fzn_next_output_array_posit; i++) {
free(fzn_output_arrays[i].vars_id);
if (fzn_output_arrays[i].name != NULL) {
free(fzn_output_arrays[i].name);
}
}
free(fzn_output_arrays);
for (i = 0; i < fzn_next_search_annot_posit; i++) {
free(fzn_search_annot[i].assign_heur);
free(fzn_search_annot[i].label_array_name);
free(fzn_search_annot[i].label_heur);
free(fzn_search_annot[i].search_strategy);
free(fzn_search_annot[i].search_type);
}
fclose(yyin);
}
/*
* Explores the CSP to find and print one solution, to count all the solutions or to find and print the best solution
*/
void fzn_solve() {
unsigned long result = 0;
bool output_vars;
int i, j, k;
N_VS_ORIGINAL = fzn_next_var_posit;
N_CS_ORIGINAL = fzn_next_constr_posit;
#if FZN_PRINT_CSP
fzn_print_csp();
#endif
#if FZN_STATS
fzn_print_stats();
#endif
|
4d26a735
Pedro Roque
Increased recogni...
|
233
234
235
236
237
|
// add all the variables marked to be printed to the array of variables to print
fzn_new_output_array();
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].output_var == true) {
fzn_add_var_id_to_output_array(i);
|
94b2b13d
Pedro Roque
PHACT source
|
238
239
240
241
242
243
244
245
246
247
248
|
}
}
// add all the variables of the arrays marked to be printed to the array of variables to print
for (i = 0; i < fzn_next_array_posit; i++) {
if (fzn_arrays[i].output_array) {
if (fzn_output_arrays[fzn_next_output_array_posit - 1].next_position != 0) {
fzn_new_output_array();
}
if (fzn_arrays[i].name != NULL) {
|
4d26a735
Pedro Roque
Increased recogni...
|
249
250
|
if (fzn_output_arrays[fzn_next_output_array_posit - 1].name != NULL) {
free(fzn_output_arrays[fzn_next_output_array_posit - 1].name);
|
94b2b13d
Pedro Roque
PHACT source
|
251
252
|
}
fzn_output_arrays[fzn_next_output_array_posit - 1].name = malloc((strlen(fzn_arrays[i].name) + 1) * sizeof(char));
|
4d26a735
Pedro Roque
Increased recogni...
|
253
|
strcpy(fzn_output_arrays[fzn_next_output_array_posit - 1].name, fzn_arrays[i].name);
|
94b2b13d
Pedro Roque
PHACT source
|
254
255
256
|
}
for (j = 0; j < fzn_arrays[i].next_position; j++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
257
|
fzn_add_var_id_to_output_array(fzn_arrays[i].values[j]);
|
94b2b13d
Pedro Roque
PHACT source
|
258
259
260
261
262
263
|
}
}
}
// select the variables to label if there is no search annotation in the model and the ones marked for output
// check if there are any variables set for labeling
|
4d26a735
Pedro Roque
Increased recogni...
|
264
|
// if none, add all the ones marked for output
|
94b2b13d
Pedro Roque
PHACT source
|
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
// if none, just add all
if (fzn_next_search_annot_posit > 0) {
fzn_init_search_annots();
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].range == true) {
fzn_vars[i].to_label = false;
#if FZN_LABEL_DEFINED_VARS
} else if (fzn_vars[i].is_defined_var) {
defined_var = true;
fzn_vars[i].to_label = true;
}
# else
}
#endif
}
|
4d26a735
Pedro Roque
Increased recogni...
|
284
|
|
94b2b13d
Pedro Roque
PHACT source
|
285
286
287
288
|
#if FZN_LABEL_DEFINED_VARS
if (defined_var) {
printf("Some variables marked as \"is_defined_var\" were also set for labeling.\n\n");
}
|
4d26a735
Pedro Roque
Increased recogni...
|
289
290
291
292
|
#endif
} else {
// set output variables for labeling
|
94b2b13d
Pedro Roque
PHACT source
|
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
output_vars = false;
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].output_var) {
if (fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].range == true) {
fzn_vars[i].to_label = false;
} else {
fzn_vars[i].to_label = true;
output_vars = true;
}
}
}
for (i = 0; i < fzn_next_array_posit; i++) {
if (fzn_arrays[i].output_array) {
for (j = 0; j < fzn_arrays[i].next_position; j++) {
if (fzn_vars[fzn_arrays[i].values[j]].min == fzn_vars[fzn_arrays[i].values[j]].max && fzn_vars[fzn_arrays[i].values[j]].range == true) {
fzn_vars[fzn_arrays[i].values[j]].to_label = false;
} else {
fzn_vars[fzn_arrays[i].values[j]].to_label = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
317
318
|
output_vars = true;
}
|
94b2b13d
Pedro Roque
PHACT source
|
319
320
|
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
321
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
322
323
|
if (!output_vars) {
|
4d26a735
Pedro Roque
Increased recogni...
|
324
325
326
327
328
329
330
331
|
printf("No search annotations and no output variables, so all variables will be set for labeling, which may greatly decrease PHACT performance.\n");
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].range == true) {
fzn_vars[i].to_label = false;
} else {
|
94b2b13d
Pedro Roque
PHACT source
|
332
|
fzn_vars[i].to_label = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
333
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
334
335
336
337
|
}
} else {
printf("No search annotations, so all the variables marked for output will be set for labeling.\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
338
339
340
341
342
343
344
345
346
347
348
349
|
}
}
#if FZN_LABEL_ALL_VARS
fprintf(stderr, "\nSetting all variables for labeling\n");
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].next_position == 1) {
fzn_vars[i].to_label = false;
} else {
fzn_vars[i].to_label = true;
|
94b2b13d
Pedro Roque
PHACT source
|
350
351
352
|
}
}
#endif
|
94b2b13d
Pedro Roque
PHACT source
|
353
|
|
4d26a735
Pedro Roque
Increased recogni...
|
354
355
356
|
if (FZN_VERBOSE)
printf("Creating CSP model for PHACT.\n");
|
94b2b13d
Pedro Roque
PHACT source
|
357
|
if (WORK == DEFAULT_W) {
|
4d26a735
Pedro Roque
Increased recogni...
|
358
359
360
361
362
363
|
if (FZN_OPTIMIZE == FZN_MINIMIZE || FZN_OPTIMIZE == FZN_MAXIMIZE) {
WORK = OPT;
OPTIMIZING = true;
VS_LOCK = malloc(N_VS * sizeof(var));
VS_LOCK_BEST = malloc(N_VS * sizeof(var));
} else {
|
94b2b13d
Pedro Roque
PHACT source
|
364
|
COUNTING_SOLUTIONS = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
365
366
367
368
369
370
371
|
WORK = CNT;
}
}
// Use command line heuristics for labeling and assignment, if existent
if (LABEL_MODE_COM != DEFAULT_L) {
LABEL_MODE = LABEL_MODE_COM;
|
94b2b13d
Pedro Roque
PHACT source
|
372
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
373
374
375
376
377
378
379
380
381
382
|
if (ASSIGN_MODE_COM != DEFAULT_A) {
ASSIGN_MODE = ASSIGN_MODE_COM;
}
#if FZN_NE2ALL_DIFF
int count = 0;
int first_ne_idx;
int last_ne_idx;
bool all_diff = true;
int l;
|
94b2b13d
Pedro Roque
PHACT source
|
383
384
385
|
for (i = 0; i < fzn_next_constr_posit; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
386
387
|
if (strcmp(fzn_constrs[i].name, "int_lin_ne") == 0
&& fzn_constrs[i].next_const_to_add == 3
|
94b2b13d
Pedro Roque
PHACT source
|
388
389
|
&& fzn_constrs[i].consts[0] == 1
&& fzn_constrs[i].consts[1] == -1
|
4d26a735
Pedro Roque
Increased recogni...
|
390
391
392
393
394
|
&& fzn_constrs[i].consts[2] == 0 ) {
count = 0;
for (j = i;
strcmp(fzn_constrs[j].name, "int_lin_ne") == 0
|
94b2b13d
Pedro Roque
PHACT source
|
395
396
397
|
&& fzn_constrs[j].next_const_to_add == 3
&& fzn_constrs[j].consts[0] == 1
&& fzn_constrs[j].consts[1] == -1
|
4d26a735
Pedro Roque
Increased recogni...
|
398
|
&& fzn_constrs[j].consts[2] == 0
|
94b2b13d
Pedro Roque
PHACT source
|
399
400
401
402
|
&& fzn_constrs[i].vars_id[0] == fzn_constrs[j].vars_id[0]
; j++) {
count++;
|
4d26a735
Pedro Roque
Increased recogni...
|
403
404
405
406
407
408
409
410
411
412
413
414
|
}
// its probably an all different constraint with count + 1 elements
if (count > 1) {
count++;
first_ne_idx = i;
k = first_ne_idx;
unsigned int* all_diff_idxs = malloc((count) * sizeof(unsigned int));
all_diff_idxs[0] = fzn_constrs[k].vars_id[0];
|
94b2b13d
Pedro Roque
PHACT source
|
415
416
417
418
|
for (j = 1; j < count; j++) {
all_diff_idxs[j] = fzn_constrs[k++].vars_id[1];
}
|
4d26a735
Pedro Roque
Increased recogni...
|
419
420
421
422
|
l = first_ne_idx;
for (j = 0; j < count && all_diff; j++) {
for (k = j + 1; k < count && all_diff; k++) {
|
94b2b13d
Pedro Roque
PHACT source
|
423
424
425
426
|
if (strcmp(fzn_constrs[l].name, "int_lin_ne") != 0 || all_diff_idxs[j] != fzn_constrs[l].vars_id[0] || all_diff_idxs[k] != fzn_constrs[l].vars_id[1]) {
all_diff = false;
}
l++;
|
4d26a735
Pedro Roque
Increased recogni...
|
427
428
429
430
|
}
}
last_ne_idx = l;
|
94b2b13d
Pedro Roque
PHACT source
|
431
432
433
434
435
436
437
438
439
440
441
442
|
if (all_diff) {
if (FZN_VERBOSE)
printf("Converting multiple int_lin_ne into an all_different.\n");
for (j = first_ne_idx; j < last_ne_idx; j++) {
fzn_constrs[j].ignore = true;
}
if (FZN_VERBOSE)
printf("Creating new all_different (number %d).\n", fzn_next_constr_posit);
|
4d26a735
Pedro Roque
Increased recogni...
|
443
|
// if the array of constraints is already full, doubles its size
|
94b2b13d
Pedro Roque
PHACT source
|
444
445
446
447
448
449
450
451
|
if (fzn_next_constr_posit == fzn_n_constrs) {
if (FZN_VERBOSE)
printf("Extending fzn constraints array.\n");
fzn_constrs_aux = malloc(fzn_n_constrs * 2 * (sizeof(fzn_constr)));
fzn_constrs_copy(fzn_constrs_aux, fzn_constrs, fzn_n_constrs);
|
4d26a735
Pedro Roque
Increased recogni...
|
452
453
|
free(fzn_constrs);
|
94b2b13d
Pedro Roque
PHACT source
|
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
fzn_constrs = fzn_constrs_aux;
fzn_n_constrs *= 2;
}
if (FZN_VERBOSE)
printf("Adding name all_different to constraint.\n");
// to maintain constraints input order
free(fzn_constrs[first_ne_idx].vars_id);
free(fzn_constrs[first_ne_idx].consts);
free(fzn_constrs[first_ne_idx].name);
fzn_constrs[first_ne_idx].name = malloc((strlen("all_different") + 1) * sizeof(char));
strcpy(fzn_constrs[first_ne_idx].name, "all_different");
fzn_constrs[first_ne_idx].defines_var_idx = -1;
fzn_constrs[first_ne_idx].boundsR = false;
fzn_constrs[first_ne_idx].boundsD = false;
|
4d26a735
Pedro Roque
Increased recogni...
|
474
475
|
fzn_constrs[first_ne_idx].boundsZ = false;
fzn_constrs[first_ne_idx].domain = false;
|
94b2b13d
Pedro Roque
PHACT source
|
476
477
478
|
fzn_constrs[first_ne_idx].priority = false;
fzn_constrs[first_ne_idx].consts = NULL;
fzn_constrs[first_ne_idx].vars_id = malloc(count * sizeof(unsigned int));
|
4d26a735
Pedro Roque
Increased recogni...
|
479
480
481
|
fzn_constrs[first_ne_idx].ignore = false;
fzn_constrs[first_ne_idx].max_consts = 0;
fzn_constrs[first_ne_idx].max_vars = count;
|
94b2b13d
Pedro Roque
PHACT source
|
482
483
484
485
486
487
488
489
490
491
492
|
fzn_constrs[first_ne_idx].next_const_to_add = 0;
fzn_constrs[first_ne_idx].next_var_to_add = count;
fzn_constrs[first_ne_idx].pos_init_2_array = -1;
for (j = 0; j < count; j++) {
if (FZN_VERBOSE)
printf("Adding variable %s to the all_different constraint.\n", fzn_vars[j].name);
fzn_constrs[first_ne_idx].vars_id[j] = all_diff_idxs[j];
}
|
4d26a735
Pedro Roque
Increased recogni...
|
493
|
|
94b2b13d
Pedro Roque
PHACT source
|
494
495
496
497
498
499
500
501
502
503
|
i = l - 1;
}
}
}
}
#endif
// to keep seq_search labeling order
if (fzn_next_search_annot_posit > 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
504
505
|
for (i = 0; i < fzn_next_search_annot_posit; i++) {
|
94b2b13d
Pedro Roque
PHACT source
|
506
507
508
509
510
511
512
513
514
515
|
for (j = 0; j < fzn_next_array_posit; j++) {
if (fzn_arrays[j].name != NULL && strcmp(fzn_arrays[j].name, fzn_search_annot[i].label_array_name) == 0) {
for (k = 0; k < fzn_arrays[j].next_position; k++) {
if (!fzn_vars[fzn_arrays[j].values[k]].ignore && fzn_vars[fzn_arrays[j].values[k]].to_label) {
fzn_new_csp_var(fzn_arrays[j].values[k]);
} else if (fzn_vars[fzn_arrays[j].values[k]].ignore) {
fzn_new_csp_var(fzn_vars[fzn_arrays[j].values[k]].replace_by_v_id);
|
4d26a735
Pedro Roque
Increased recogni...
|
516
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
517
518
519
520
521
522
|
}
}
}
for (j = 0; j < fzn_next_var_posit; j++) {
if (fzn_vars[j].name != NULL && strcmp(fzn_vars[j].name, fzn_search_annot[i].label_array_name) == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
523
|
|
94b2b13d
Pedro Roque
PHACT source
|
524
525
526
527
528
|
if (!fzn_vars[j].ignore && fzn_vars[j].to_label) {
fzn_new_csp_var(j);
} else if (fzn_vars[j].ignore) {
|
4d26a735
Pedro Roque
Increased recogni...
|
529
|
fzn_new_csp_var(fzn_vars[j].replace_by_v_id);
|
94b2b13d
Pedro Roque
PHACT source
|
530
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
531
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
532
533
534
535
536
537
538
539
540
541
542
543
|
}
}
for (i = 0; i < fzn_next_array_posit; i++) {
if (fzn_arrays[i].output_array) {
for (j = 0; j < fzn_arrays[i].next_position; j++) {
if (!fzn_vars[fzn_arrays[i].values[j]].ignore && fzn_vars[fzn_arrays[i].values[j]].to_label) {
fzn_new_csp_var(fzn_arrays[i].values[j]);
} else if (fzn_vars[fzn_arrays[i].values[j]].ignore) {
|
94b2b13d
Pedro Roque
PHACT source
|
544
545
546
547
548
549
550
551
|
fzn_new_csp_var(fzn_vars[fzn_arrays[i].values[j]].replace_by_v_id);
}
}
}
}
// create the non labeled CSP variables
for (i = 0; i < fzn_next_var_posit; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
552
|
fzn_new_csp_var(i);
|
94b2b13d
Pedro Roque
PHACT source
|
553
554
555
556
557
558
|
}
} else {
for (i = 0; i < fzn_next_array_posit; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
559
|
if (fzn_arrays[i].output_array) {
|
94b2b13d
Pedro Roque
PHACT source
|
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
|
for (j = 0; j < fzn_arrays[i].next_position; j++) {
if (!fzn_vars[fzn_arrays[i].values[j]].ignore && fzn_vars[fzn_arrays[i].values[j]].to_label) {
fzn_new_csp_var(fzn_arrays[i].values[j]);
} else if (fzn_vars[fzn_arrays[i].values[j]].ignore) {
fzn_new_csp_var(fzn_vars[fzn_arrays[i].values[j]].replace_by_v_id);
}
}
}
}
// create the CSP variables
for (i = 0; i < fzn_next_var_posit; i++) {
fzn_new_csp_var(i);
}
}
// some duplicated variables are removed, so their links must be updated
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].replace_by_v_id != -1) {
fzn_vars[i].id = fzn_vars[fzn_vars[i].replace_by_v_id].id;
}
}
// set optimization
if (FZN_OPTIMIZE == FZN_MINIMIZE) {
c_minimize(fzn_vars[optimize_var_idx].id);
} else if (FZN_OPTIMIZE == FZN_MAXIMIZE) {
c_maximize(fzn_vars[optimize_var_idx].id);
}
#if FZN_SORT_CONSTR_VARS
// sort the variables of some constraints for input order
fzn_sort_constr_vars();
#endif
// create the CSP constraints
for (i = 0; i < fzn_next_constr_posit; i++) {
fzn_new_csp_constr(i);
}
if (FZN_VERBOSE) {
gettimeofday(&end, NULL);
format_elapsed_time_s_ms(elapsed_time, start.tv_sec, start.tv_usec, end.tv_sec, end.tv_usec);
format_time_s_ms(start_time, start.tv_sec, start.tv_usec);
format_time_s_ms(end_time, end.tv_sec, end.tv_usec);
printf("%s...%s = %s (s.ms) -> CSP model loaded from FlatZinc\n", start_time, end_time, elapsed_time);
}
if (FINDING_ONE_SOLUTION) {
printf("\nFinding one solution for %s.\n", FZN_FILE_NAME);
} else if (COUNTING_SOLUTIONS) {
printf("\nCounting all the solutions for %s.\n", FZN_FILE_NAME);
} else if (OPTIMIZING) {
printf("\nOptimizing %s.\n", FZN_FILE_NAME);
}
#if FZN_MAP_FZN2PHACT == 1
fzn_map_fzn2phact();
#endif
result = solve_CSP();
if (FINDING_ONE_SOLUTION && result == 1) {
printf("Solution:\n");
for (i = 0; i < fzn_next_output_array_posit; i++) {
if (fzn_output_arrays[i].name != NULL) {
printf("%s = {", fzn_output_arrays[i].name);
for (j = 0; j < fzn_output_arrays[i].next_position - 1; j++) {
// due to possible variables sorting
for (k = 0; k < (int)N_VS; k++) {
if (VS[k].v_id_print == fzn_vars[fzn_output_arrays[i].vars_id[j]].id) {
v_print_single_val(k, 0);
break;
}
}
printf(", ");
}
// due to possible variables sorting
for (k = 0; k < (int)N_VS; k++) {
if (VS[k].v_id_print == fzn_vars[fzn_output_arrays[i].vars_id[j]].id) {
v_print_single_val(k, 0);
break;
}
}
printf("}\n");
} else {
for (j = 0; j < fzn_output_arrays[i].next_position; j++) {
// due to possible variables sorting
for (k = 0; k < (int)N_VS; k++) {
if (VS[k].v_id_print == fzn_vars[fzn_output_arrays[i].vars_id[j]].id) {
if (fzn_vars[fzn_output_arrays[i].vars_id[j]].name != NULL) {
printf("%s = ", fzn_vars[fzn_output_arrays[i].vars_id[j]].name);
}
v_print_single_val(k, 0);
break;
}
}
printf(";\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
668
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
669
670
|
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
671
|
|
94b2b13d
Pedro Roque
PHACT source
|
672
673
674
675
676
677
678
679
680
681
682
683
|
} else if (COUNTING_SOLUTIONS) {
printf("%lu solution(s) found\n", result);
} else if (OPTIMIZING && result == 1) {
printf("Best solution:\n");
for (i = 0; i < fzn_next_output_array_posit; i++) {
if (fzn_output_arrays[i].name != NULL) {
printf("%s = {", fzn_output_arrays[i].name);
for (j = 0; j < fzn_output_arrays[i].next_position - 1; j++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
684
|
// due to possible variables sorting
|
94b2b13d
Pedro Roque
PHACT source
|
685
686
687
688
|
for (k = 0; k < (int)N_VS; k++) {
if (VS[k].v_id_print == fzn_vars[fzn_output_arrays[i].vars_id[j]].id) {
v_print_single_val(k, 0);
break;
|
4d26a735
Pedro Roque
Increased recogni...
|
689
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
}
printf(", ");
}
for (k = 0; k < (int)N_VS; k++) {
if (VS[k].v_id_print == fzn_vars[fzn_output_arrays[i].vars_id[j]].id) {
v_print_single_val(k, 0);
break;
}
}
printf("}\n");
} else {
for (j = 0; j < fzn_output_arrays[i].next_position; j++) {
// due to possible variables sorting
|
4d26a735
Pedro Roque
Increased recogni...
|
704
|
for (k = 0; k < (int)N_VS; k++) {
|
94b2b13d
Pedro Roque
PHACT source
|
705
706
|
if (VS[k].v_id_print == fzn_vars[fzn_output_arrays[i].vars_id[j]].id) {
|
4d26a735
Pedro Roque
Increased recogni...
|
707
|
|
94b2b13d
Pedro Roque
PHACT source
|
708
709
710
711
712
713
714
715
|
if (fzn_vars[fzn_output_arrays[i].vars_id[j]].name != NULL) {
printf("%s = ", fzn_vars[fzn_output_arrays[i].vars_id[j]].name);
}
v_print_single_val(k, 0);
break;
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
716
|
printf(";\n");
|
94b2b13d
Pedro Roque
PHACT source
|
717
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
718
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
719
720
721
722
723
724
|
}
printf("\n");
v_print_cost(0);
} else {
printf("No solution found.\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
725
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
726
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
727
|
|
94b2b13d
Pedro Roque
PHACT source
|
728
729
730
731
732
733
734
735
736
|
/*
* Add a new value to the current flatzinc object
* val - value to add
*/
void fzn_add_val_to_object(int val) {
if (FZN_VERBOSE)
printf("Adding value %d to element number %d of fzn_obj.\n", val, fzn_obj.next_element);
|
4d26a735
Pedro Roque
Increased recogni...
|
737
|
fzn_extend_object_elements();
|
94b2b13d
Pedro Roque
PHACT source
|
738
739
740
741
742
743
744
|
fzn_obj.elements[fzn_obj.next_element] = val;
fzn_obj.element_is_var[fzn_obj.next_element] = false;
fzn_obj.next_element++;
}
|
4d26a735
Pedro Roque
Increased recogni...
|
745
|
/*
|
94b2b13d
Pedro Roque
PHACT source
|
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
|
* Add a new variable to the current flatzinc object
* name - Name of the variable to add to the object
*/
void fzn_add_var_or_array_to_object(char* name) {
int i, j;
fzn_extend_object_elements();
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].name != NULL && strcmp(fzn_vars[i].name, name) == 0) {
if (FZN_VERBOSE)
printf("Adding variable %s to element number %d fzn_obj.\n", name, fzn_obj.next_element);
fzn_obj.element_is_var[fzn_obj.next_element] = true;
fzn_obj.elements[fzn_obj.next_element] = i;
fzn_obj.next_element++;
break;
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
767
|
|
94b2b13d
Pedro Roque
PHACT source
|
768
|
if (i == fzn_next_var_posit) {
|
4d26a735
Pedro Roque
Increased recogni...
|
769
|
for (i = 0; i < fzn_next_array_posit; i++) {
|
94b2b13d
Pedro Roque
PHACT source
|
770
771
772
773
774
|
if (fzn_arrays[i].name != NULL && strcmp(fzn_arrays[i].name, name) == 0) {
if (FZN_VERBOSE)
printf("Adding array %s to fzn_obj.\n", name);
|
4d26a735
Pedro Roque
Increased recogni...
|
775
|
|
94b2b13d
Pedro Roque
PHACT source
|
776
|
if (fzn_arrays[i].var_array) {
|
4d26a735
Pedro Roque
Increased recogni...
|
777
|
for (j = 0; j < fzn_arrays[i].next_position; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
778
779
780
781
782
783
784
785
|
fzn_extend_object_elements();
if (FZN_VERBOSE)
printf("Adding variable ID %d from array %s to element number %d of fzn_obj.\n", fzn_arrays[i].values[j], name,
fzn_obj.next_element);
fzn_obj.element_is_var[fzn_obj.next_element] = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
786
|
fzn_obj.elements[fzn_obj.next_element] = fzn_arrays[i].values[j];
|
94b2b13d
Pedro Roque
PHACT source
|
787
788
789
790
791
792
793
|
fzn_obj.next_element++;
}
} else {
for (j = 0; j < fzn_arrays[i].next_position; j++) {
fzn_extend_object_elements();
|
4d26a735
Pedro Roque
Increased recogni...
|
794
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
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
|
printf("Adding value %d from array %s to element number %d of fzn_obj.\n", fzn_arrays[i].values[j], name,
fzn_obj.next_element);
fzn_obj.element_is_var[fzn_obj.next_element] = false;
fzn_obj.elements[fzn_obj.next_element] = fzn_arrays[i].values[j];
fzn_obj.next_element++;
}
}
break;
}
}
if (i == fzn_next_array_posit) {
fprintf(stderr, "\n Error: variable or array name not found when adding it to a fzn_obj.\n");
exit(-1);
}
}
}
/*
* Define fzn_obj range as true or false
*/
void fzn_set_fzn_obj_range(bool range) {
if (FZN_VERBOSE)
printf("Setting current fzn_obj range as %d.\n", range);
fzn_obj.range = range;
}
/*
* Add an annotation to the current flatzinc object
*/
void fzn_add_annot_to_object(char* annot) {
int i;
|
4d26a735
Pedro Roque
Increased recogni...
|
831
|
if (fzn_obj.next_annot == fzn_obj.max_annots) {
|
94b2b13d
Pedro Roque
PHACT source
|
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
|
if (FZN_VERBOSE)
printf("Extending annotations array of fzn_obj.\n");
fzn_obj.annots_aux = malloc(fzn_obj.max_annots * 2 * (sizeof(char*)));
for (i = 0; i < fzn_obj.next_annot; i++) {
fzn_obj.annots_aux[i] = fzn_obj.annots[i];
}
free(fzn_obj.annots);
fzn_obj.annots = fzn_obj.annots_aux;
fzn_obj.max_annots *= 2;
}
if (FZN_VERBOSE)
printf("Adding annotation %s, as the annotation number %d to fzn_obj.\n", annot, fzn_obj.next_annot);
if (strcmp(annot, "bool") == 0) {
if (FZN_VERBOSE)
printf("Setting fzn_obj as bool.\n");
fzn_obj.is_bool = true;
} else if (strcmp(annot, "int_search") == 0 || strcmp(annot, "bool_search") == 0) {
fzn_obj.annots[fzn_obj.next_annot] = malloc((strlen(annot) + 1) * sizeof(char));
strcpy(fzn_obj.annots[fzn_obj.next_annot], annot);
fzn_obj.next_annot++;
fzn_add_fzn_obj_search_annot();
} else if (strcmp(annot, "float_search") == 0 || strcmp(annot, "set_search") == 0) {
fprintf(stderr, "PHACT can only work with \"int_search\" or \"bool_search\" annotations (not %s).\n", annot);
exit(-1);
} else {
fzn_obj.annots[fzn_obj.next_annot] = malloc((strlen(annot) + 1) * sizeof(char));
strcpy(fzn_obj.annots[fzn_obj.next_annot], annot);
fzn_obj.next_annot++;
}
|
4d26a735
Pedro Roque
Increased recogni...
|
877
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
878
879
880
881
882
883
884
885
886
887
888
|
/*
* identifies the element on the elements array where the second array of the constraint begins
*/
void fzn_set_2array_init_pos() {
if (fzn_obj.pos_init_2_array == -1) {
if (FZN_VERBOSE)
printf("Begin of second array of elements at element number %d.\n", fzn_obj.next_element);
fzn_obj.pos_init_2_array = fzn_obj.next_element;
|
4d26a735
Pedro Roque
Increased recogni...
|
889
890
891
892
893
894
895
896
|
}
}
/*
* If the array of object elements is already full, doubles its size
*/
void fzn_extend_object_elements() {
int i;
|
94b2b13d
Pedro Roque
PHACT source
|
897
898
899
900
901
902
|
if (fzn_obj.next_element == fzn_obj.max_elements) {
if (FZN_VERBOSE)
printf("Extending array of elements of fzn_obj.\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
903
|
fzn_obj.elements_aux = malloc(fzn_obj.max_elements * 2 * (sizeof(int)));
|
94b2b13d
Pedro Roque
PHACT source
|
904
905
906
907
908
909
910
911
912
913
914
|
fzn_obj.element_is_var_aux = malloc(fzn_obj.max_elements * 2 * (sizeof(bool)));
for (i = 0; i < fzn_obj.next_element; i++) {
fzn_obj.elements_aux[i] = fzn_obj.elements[i];
fzn_obj.element_is_var_aux[i] = fzn_obj.element_is_var[i];
}
free(fzn_obj.elements);
free(fzn_obj.element_is_var);
fzn_obj.elements = fzn_obj.elements_aux;
|
4d26a735
Pedro Roque
Increased recogni...
|
915
|
fzn_obj.element_is_var = fzn_obj.element_is_var_aux;
|
94b2b13d
Pedro Roque
PHACT source
|
916
|
|
4d26a735
Pedro Roque
Increased recogni...
|
917
|
fzn_obj.max_elements *= 2;
|
94b2b13d
Pedro Roque
PHACT source
|
918
919
920
921
922
923
924
|
}
}
/*
* Reset the flatzinc object
*/
void fzn_reset_object_elements() {
|
4d26a735
Pedro Roque
Increased recogni...
|
925
|
int i = 0;
|
94b2b13d
Pedro Roque
PHACT source
|
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
|
if (FZN_VERBOSE)
printf("Reseting fzn_obj.\n");
for (i = 0; i < fzn_obj.next_annot; i++) {
free(fzn_obj.annots[i]);
fzn_obj.annots[i] = NULL;
}
fzn_obj.annots_aux = NULL;
fzn_obj.element_is_var_aux = NULL;
fzn_obj.next_annot = 0;
fzn_obj.next_element = 0;
fzn_obj.is_array = false;
fzn_obj.is_constraint = false;
fzn_obj.is_bool = false;
fzn_obj.range = true;
fzn_obj.pos_init_2_array = -1;
}
/*
* Create a new empty array that will contain constant values or variables IDs
*/
void fzn_new_fzn_obj_array() {
int i;
fzn_obj.is_array = true;
if (FZN_VERBOSE)
printf("Adding new FZN array (number %d).\n", fzn_next_array_posit);
|
4d26a735
Pedro Roque
Increased recogni...
|
957
958
959
960
961
962
963
964
|
// if the array of arrays is full, doubles its size
if (fzn_next_array_posit == fzn_n_arrays) {
fzn_arrays_aux = malloc(fzn_n_arrays * 2 * (sizeof(fzn_array)));
fzn_array_copy(fzn_arrays_aux, fzn_arrays, fzn_n_arrays);
free(fzn_arrays);
fzn_arrays = fzn_arrays_aux;
|
94b2b13d
Pedro Roque
PHACT source
|
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
|
fzn_n_arrays *= 2;
}
fzn_arrays[fzn_next_array_posit].output_var = false;
fzn_arrays[fzn_next_array_posit].is_defined_var = false;
fzn_arrays[fzn_next_array_posit].var_is_introduced = false;
fzn_arrays[fzn_next_array_posit].output_array = false;
fzn_arrays[fzn_next_array_posit].to_label = true;
fzn_arrays[fzn_next_array_posit].next_position = 0;
fzn_arrays[fzn_next_array_posit].values = NULL;
fzn_arrays[fzn_next_array_posit].max_values = FZN_MAX_ELEMENTS;
fzn_arrays[fzn_next_array_posit].values_aux = NULL;
fzn_arrays[fzn_next_array_posit].var_array = true;
fzn_arrays[fzn_next_array_posit].name = NULL;
for (i = 0; i < fzn_obj.next_annot; i++) {
if (fzn_obj.annots[i] == NULL) {
fprintf(stderr, "Trying to add an annotation number %d that is empty to array number %d.\n", i, fzn_next_array_posit);
exit(-1);
}
if (strcmp(fzn_obj.annots[i], "output_var") == 0) {
if (FZN_VERBOSE)
printf("Adding annotation output_var to array.\n");
fzn_arrays[fzn_next_array_posit].output_var = true;
} else if (strcmp(fzn_obj.annots[i], "is_defined_var") == 0) {
if (FZN_VERBOSE)
printf("Adding annotation is_defined_var to array.\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
998
999
|
fzn_arrays[fzn_next_array_posit].is_defined_var = true;
|
94b2b13d
Pedro Roque
PHACT source
|
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
|
} else if (strcmp(fzn_obj.annots[i], "var_is_introduced") == 0) {
if (FZN_VERBOSE)
printf("Adding annotation var_is_introduced to array.\n");
fzn_arrays[fzn_next_array_posit].var_is_introduced = true;
} else if (strcmp(fzn_obj.annots[i], "output_array") == 0) {
if (FZN_VERBOSE)
printf("Adding annotation output_array to array.\n");
fzn_arrays[fzn_next_array_posit].output_array = true;
} else {
if (fzn_arrays[fzn_next_array_posit].name == NULL) {
if (FZN_VERBOSE)
printf("Adding name %s to array.\n", fzn_obj.annots[i]);
fzn_arrays[fzn_next_array_posit].name = malloc((strlen(fzn_obj.annots[i]) + 1) * sizeof(char));
strcpy(fzn_arrays[fzn_next_array_posit].name, fzn_obj.annots[i]);
} else {
fprintf(stderr, "Trying to name array with %s when its name is already %s.\n", fzn_arrays[fzn_next_array_posit].name, fzn_obj.annots[i]);
exit(-1);
}
}
}
// reset all the array values
fzn_arrays[fzn_next_array_posit].next_position = fzn_obj.next_element;
fzn_arrays[fzn_next_array_posit].to_label = false;
fzn_arrays[fzn_next_array_posit].values = malloc(fzn_obj.next_element * sizeof(int));
fzn_arrays[fzn_next_array_posit].max_values = fzn_obj.next_element;
fzn_arrays[fzn_next_array_posit].values_aux = NULL;
fzn_arrays[fzn_next_array_posit].var_array = false;
for (i = 0; i < fzn_obj.next_element; i++) {
if (fzn_obj.element_is_var[i]) {
fzn_arrays[fzn_next_array_posit].var_array = true;
break;
}
}
if (fzn_arrays[fzn_next_array_posit].var_array) {
for (i = 0; i < fzn_obj.next_element; i++) {
if (fzn_obj.element_is_var[i]) {
fzn_arrays[fzn_next_array_posit].values[i] = fzn_obj.elements[i];
} else {
fzn_arrays[fzn_next_array_posit].values[i] = fzn_new_fzn_obj_var_value(fzn_obj.elements[i]);
|
4d26a735
Pedro Roque
Increased recogni...
|
1054
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
|
}
} else {
for (i = 0; i < fzn_obj.next_element; i++) {
fzn_arrays[fzn_next_array_posit].values[i] = fzn_obj.elements[i];
}
}
fzn_reset_object_elements();
fzn_next_array_posit++;
}
/*
* Adds a variable ID to the last created array
* name - name of the variable whose ID is to add to the array
*/
void fzn_add_var_to_array(char* var_name) {
int i, j;
if (FZN_VERBOSE)
printf("Adding variable %s to FZN array number %d.\n", var_name, fzn_next_array_posit - 1);
if (var_name == NULL) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1078
1079
1080
1081
1082
1083
1084
1085
|
fprintf(stderr, "Attempting to add a variable with no name to an array.\n");
exit(-1);
}
// finds the variable with that name to retrieve its ID and adds the ID to the array
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].name != NULL && strcmp(var_name, fzn_vars[i].name) == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
|
// if the array of integers is already full, doubles its size
if (fzn_arrays[fzn_next_array_posit - 1].next_position == fzn_arrays[fzn_next_array_posit - 1].max_values) {
fzn_arrays[fzn_next_array_posit - 1].values_aux = malloc(fzn_arrays[fzn_next_array_posit - 1].max_values * 2 * (sizeof(int)));
for (j = 0; j < fzn_arrays[fzn_next_array_posit - 1].max_values; j++) {
fzn_arrays[fzn_next_array_posit - 1].values_aux[j] = fzn_arrays[fzn_next_array_posit - 1].values[i];
}
free(fzn_arrays[fzn_next_array_posit - 1].values);
fzn_arrays[fzn_next_array_posit - 1].values = fzn_arrays[fzn_next_array_posit - 1].values_aux;
fzn_arrays[fzn_next_array_posit - 1].max_values *= 2;
}
fzn_arrays[fzn_next_array_posit - 1].values[fzn_arrays[fzn_next_array_posit - 1].next_position] = i;
fzn_arrays[fzn_next_array_posit - 1].next_position++;
fzn_arrays[fzn_next_array_posit - 1].var_array = true;
return;
}
}
if (i == fzn_next_var_posit) {
fprintf(stderr, "Variable name %s not found when adding it to an array.\n", var_name);
exit(-1);
}
if (!fzn_arrays[fzn_next_array_posit - 1].var_array) {
int val;
for (i = 0; i < fzn_arrays[fzn_next_array_posit - 1].next_position; i++) {
val = fzn_arrays[fzn_next_array_posit - 1].values[i];
fzn_arrays[fzn_next_array_posit - 1].values[i] = fzn_new_fzn_var_range(val, val);
}
fzn_arrays[fzn_next_array_posit - 1].var_array = true;
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1126
1127
1128
1129
1130
1131
1132
1133
1134
|
/*
* Adds an integer value to the last created array
* value - value to add to the array
*/
void fzn_add_val_to_array(int value) {
int i;
if (FZN_VERBOSE)
printf("Adding value/variable %d to FZN array number %d.\n", value, fzn_next_array_posit - 1);
|
94b2b13d
Pedro Roque
PHACT source
|
1135
1136
1137
1138
1139
1140
1141
|
// if the array of integers is already full, doubles its size
if (fzn_arrays[fzn_next_array_posit - 1].next_position == fzn_arrays[fzn_next_array_posit - 1].max_values) {
fzn_arrays[fzn_next_array_posit - 1].values_aux = malloc(fzn_arrays[fzn_next_array_posit - 1].max_values * 2 * (sizeof(int)));
for (i = 0; i < fzn_arrays[fzn_next_array_posit - 1].max_values; i++) {
fzn_arrays[fzn_next_array_posit - 1].values_aux[i] = fzn_arrays[fzn_next_array_posit - 1].values[i];
|
4d26a735
Pedro Roque
Increased recogni...
|
1142
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
|
free(fzn_arrays[fzn_next_array_posit - 1].values);
fzn_arrays[fzn_next_array_posit - 1].values = fzn_arrays[fzn_next_array_posit - 1].values_aux;
fzn_arrays[fzn_next_array_posit - 1].max_values *= 2;
}
if (fzn_arrays[fzn_next_array_posit - 1].var_array) {
fzn_arrays[fzn_next_array_posit - 1].values[fzn_arrays[fzn_next_array_posit - 1].next_position] = fzn_new_fzn_var_range(value, value);
} else {
// adds the new value to the array
fzn_arrays[fzn_next_array_posit - 1].values[fzn_arrays[fzn_next_array_posit - 1].next_position] = value;
}
fzn_arrays[fzn_next_array_posit - 1].next_position++;
}
/*
* Copy a Flatzinc array
* dest - the array from where to copy the fzn_array to
* src - the array from where to copy the fzn_array from
* n_arrays - number of fzn_arrays to copy
*/
void fzn_array_copy(fzn_array* dest, fzn_array* src, int n_arrays) {
int i;
if (FZN_VERBOSE)
printf("Copying FZN array.\n");
for (i = 0; i < n_arrays; i++) {
dest[i].is_defined_var = src[i].is_defined_var;
dest[i].max_values = src[i].max_values;
dest[i].name = src[i].name;
dest[i].next_position = src[i].next_position;
dest[i].output_array = src[i].output_array;
|
4d26a735
Pedro Roque
Increased recogni...
|
1179
|
dest[i].output_var = src[i].output_var;
|
94b2b13d
Pedro Roque
PHACT source
|
1180
1181
1182
1183
1184
1185
|
dest[i].to_label = src[i].to_label;
dest[i].values = src[i].values;
dest[i].values_aux = src[i].values_aux;
dest[i].var_array = src[i].var_array;
dest[i].var_is_introduced = src[i].var_is_introduced;
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1186
1187
1188
1189
1190
1191
1192
1193
|
}
/*
* Create a new Flatzinc variable with the minimum and the maximum value of its domain
* and return the index of the variable in fzn_vars array
* min - minimum value of the variable domain
* max - maximum value of the variable domain
*/
|
94b2b13d
Pedro Roque
PHACT source
|
1194
1195
1196
1197
1198
1199
1200
1201
|
int fzn_new_fzn_var_range(int min, int max) {
int i;
if (FZN_VERBOSE)
printf("Creating new FZN variable with range [%d, %d].\n", min, max);
if (min == max) {
for (i = 0; i < fzn_next_var_posit; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1202
|
if (fzn_vars[i].min == min && fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].range == true && fzn_vars[i].name == NULL) {
|
94b2b13d
Pedro Roque
PHACT source
|
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
|
return i;
}
}
}
// if the array of variables is already full, doubles its size
fzn_vars_extend();
fzn_vars[fzn_next_var_posit].values = NULL;
fzn_vars[fzn_next_var_posit].values_aux = NULL;
fzn_vars[fzn_next_var_posit].next_position = 0;
fzn_vars[fzn_next_var_posit].max_values = 0;
fzn_vars[fzn_next_var_posit].range = true;
fzn_vars[fzn_next_var_posit].defined_by_constr_idx = -1;
fzn_vars[fzn_next_var_posit].id = -1;
fzn_vars[fzn_next_var_posit].ignore = false;
fzn_vars[fzn_next_var_posit].is_defined_var = false;
fzn_vars[fzn_next_var_posit].max = max;
fzn_vars[fzn_next_var_posit].min = min;
fzn_vars[fzn_next_var_posit].name = NULL;
fzn_vars[fzn_next_var_posit].output_var = false;
|
4d26a735
Pedro Roque
Increased recogni...
|
1224
1225
1226
1227
1228
1229
1230
1231
|
fzn_vars[fzn_next_var_posit].to_label = false;
fzn_vars[fzn_next_var_posit].replace_by_v_id = -1;
fzn_vars[fzn_next_var_posit].created = false;
fzn_next_var_posit++;
return fzn_next_var_posit - 1;
}
|
94b2b13d
Pedro Roque
PHACT source
|
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
|
/*
* Create a new Flatzinc variable with a single value on its domain
* and return the index of the variable in fzn_vars array
* val - value of the variable domain
*/
int fzn_new_fzn_obj_var_value(int val) {
int i;
if (fzn_obj.is_bool && fzn_obj.is_array != true) {
fzn_add_val_to_object(0);
fzn_add_val_to_object(1);
}
if (fzn_obj.is_array == true || fzn_obj.is_constraint || fzn_obj.annots[0] == NULL) {
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].min == val && fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].range == true && fzn_vars[i].name == NULL) {
if (FZN_VERBOSE)
printf("New FZN variable with value %d not created, as one already exists.\n", val);
return i;
|
4d26a735
Pedro Roque
Increased recogni...
|
1254
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
1255
1256
1257
|
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1258
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
|
printf("Creating new FZN variable with value %d.\n", val);
// if the array of variables is already full, doubles its size
fzn_vars_extend();
fzn_vars[fzn_next_var_posit].values = NULL;
fzn_vars[fzn_next_var_posit].values_aux = NULL;
fzn_vars[fzn_next_var_posit].next_position = 0;
fzn_vars[fzn_next_var_posit].max_values = 0;
fzn_vars[fzn_next_var_posit].name = NULL;
fzn_vars[fzn_next_var_posit].range = true;
fzn_vars[fzn_next_var_posit].defined_by_constr_idx = -1;
fzn_vars[fzn_next_var_posit].id = -1;
fzn_vars[fzn_next_var_posit].ignore = false;
fzn_vars[fzn_next_var_posit].is_defined_var = false;
fzn_vars[fzn_next_var_posit].max = val;
fzn_vars[fzn_next_var_posit].min = val;
fzn_vars[fzn_next_var_posit].output_var = false;
fzn_vars[fzn_next_var_posit].to_label = false;
fzn_vars[fzn_next_var_posit].replace_by_v_id = -1;
fzn_vars[fzn_next_var_posit].var_is_introduced = false;
fzn_vars[fzn_next_var_posit].created = false;
fzn_next_var_posit++;
return fzn_next_var_posit - 1;
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1286
|
|
94b2b13d
Pedro Roque
PHACT source
|
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
|
/*
* Create a new Flatzinc variable with the fzn_obj data
*/
int fzn_new_fzn_obj_var() {
if (fzn_obj.is_bool && fzn_obj.is_array != true) {
fzn_add_val_to_object(0);
fzn_add_val_to_object(1);
}
int min = fzn_obj.elements[0];
int max = fzn_obj.elements[1];
int i;
if (min == max && (fzn_obj.annots[0] == NULL || fzn_obj.is_array == true || fzn_obj.is_constraint)) {
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].min == min && fzn_vars[i].min == fzn_vars[i].max && fzn_vars[i].range == true && fzn_vars[i].name == NULL) {
if (FZN_VERBOSE)
printf("New FZN variable with with range [%d, %d] not created, as one already exists.\n", min, max);
return i;
}
}
}
// if the array of variables is already full, doubles its size
fzn_vars_extend();
fzn_vars[fzn_next_var_posit].values = NULL;
|
4d26a735
Pedro Roque
Increased recogni...
|
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
|
fzn_vars[fzn_next_var_posit].values_aux = NULL;
fzn_vars[fzn_next_var_posit].next_position = 0;
fzn_vars[fzn_next_var_posit].max_values = 0;
fzn_vars[fzn_next_var_posit].name = NULL;
fzn_vars[fzn_next_var_posit].range = true;
fzn_vars[fzn_next_var_posit].defined_by_constr_idx = -1;
fzn_vars[fzn_next_var_posit].id = -1;
fzn_vars[fzn_next_var_posit].ignore = false;
fzn_vars[fzn_next_var_posit].is_defined_var = false;
fzn_vars[fzn_next_var_posit].max = -1;
fzn_vars[fzn_next_var_posit].min = -1;
fzn_vars[fzn_next_var_posit].output_var = false;
fzn_vars[fzn_next_var_posit].to_label = false;
fzn_vars[fzn_next_var_posit].replace_by_v_id = -1;
fzn_vars[fzn_next_var_posit].var_is_introduced = false;
fzn_vars[fzn_next_var_posit].created = false;
|
94b2b13d
Pedro Roque
PHACT source
|
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
|
for (i = 0; i < fzn_obj.next_annot; i++) {
if (strcmp(fzn_obj.annots[i], "output_var") == 0) {
if (FZN_VERBOSE)
printf("Adding annotation output_var to variable.\n");
fzn_vars[fzn_next_var_posit].output_var = true;
} else if (strcmp(fzn_obj.annots[i], "is_defined_var") == 0) {
if (FZN_VERBOSE)
printf("Adding annotation is_defined_var to variable.\n");
fzn_vars[fzn_next_var_posit].is_defined_var = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
1349
|
|
94b2b13d
Pedro Roque
PHACT source
|
1350
|
} else if (strcmp(fzn_obj.annots[i], "var_is_introduced") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
|
if (FZN_VERBOSE)
printf("Adding annotation var_is_introduced to variable.\n");
fzn_vars[fzn_next_var_posit].var_is_introduced = true;
} else {
if (fzn_vars[fzn_next_var_posit].name == NULL) {
if (FZN_VERBOSE)
printf("Adding name %s to variable.\n", fzn_obj.annots[i]);
fzn_vars[fzn_next_var_posit].name = malloc((strlen(fzn_obj.annots[i]) + 1) * sizeof(char));
strcpy(fzn_vars[fzn_next_var_posit].name, fzn_obj.annots[i]);
} else {
fprintf(stderr, "Trying to name variable with %s when its name is already %s.\n", fzn_vars[fzn_next_var_posit].name, fzn_obj.annots[i]);
exit(-1);
|
94b2b13d
Pedro Roque
PHACT source
|
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
|
}
}
}
fzn_vars[fzn_next_var_posit].range = fzn_obj.range;
if (fzn_obj.range) {
if (FZN_VERBOSE)
printf("Creating new FZN variable (number %d) with range [%d, %d].\n", fzn_next_var_posit, min, max);
|
4d26a735
Pedro Roque
Increased recogni...
|
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
|
fzn_vars[fzn_next_var_posit].max = max;
fzn_vars[fzn_next_var_posit].min = min;
} else {
if (FZN_VERBOSE)
printf("Creating new FZN variable (number %d) with values %d...%d.\n", fzn_next_var_posit, fzn_obj.elements[0],
fzn_obj.elements[fzn_obj.next_element - 1]);
fzn_vars[fzn_next_var_posit].values = malloc(fzn_obj.next_element * sizeof(int));
fzn_vars[fzn_next_var_posit].values_aux = NULL;
fzn_vars[fzn_next_var_posit].next_position = fzn_obj.next_element;
fzn_vars[fzn_next_var_posit].max_values = fzn_obj.next_element;
|
94b2b13d
Pedro Roque
PHACT source
|
1392
1393
1394
1395
1396
1397
1398
1399
|
for (i = 0; i < fzn_obj.next_element; i++) {
fzn_vars[fzn_next_var_posit].values[i] = fzn_obj.elements[i];
}
// may not be, if value not ordered, but PHACT does it correctly
fzn_vars[fzn_next_var_posit].max = fzn_obj.elements[fzn_obj.next_element - 1];
fzn_vars[fzn_next_var_posit].min = fzn_obj.elements[0];
|
4d26a735
Pedro Roque
Increased recogni...
|
1400
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
|
fzn_vars[fzn_next_var_posit].defined_by_constr_idx = -1;
fzn_vars[fzn_next_var_posit].id = -1;
fzn_vars[fzn_next_var_posit].to_label = false;
fzn_vars[fzn_next_var_posit].created = false;
if (fzn_obj.element_is_var[fzn_obj.next_element - 1]) {
fzn_vars[fzn_next_var_posit].ignore = true;
fzn_vars[fzn_next_var_posit].replace_by_v_id = fzn_obj.elements[fzn_obj.next_element - 1];
} else {
fzn_vars[fzn_next_var_posit].ignore = false;
fzn_vars[fzn_next_var_posit].replace_by_v_id = -1;
}
fzn_next_var_posit++;
fzn_reset_object_elements();
|
4d26a735
Pedro Roque
Increased recogni...
|
1421
|
return fzn_next_var_posit - 1;
|
94b2b13d
Pedro Roque
PHACT source
|
1422
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
|
/*
* Copy a Flatzinc variable
* dest - the array from where to copy the variable to
* src - the array from where to copy the variable from
* n_vs - number of variables to copy
*/
void fzn_vars_copy(fzn_var* dest, fzn_var* src, int n_vs) {
int i;
if (FZN_VERBOSE)
printf("Copying FZN variable.\n");
for (i = 0; i < n_vs; i++) {
dest[i].values = src[i].values;
dest[i].values_aux = src[i].values_aux;
dest[i].next_position = src[i].next_position;
dest[i].max_values = src[i].max_values;
dest[i].range = src[i].range;
|
94b2b13d
Pedro Roque
PHACT source
|
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
|
dest[i].defined_by_constr_idx = src[i].defined_by_constr_idx;
dest[i].id = src[i].id;
dest[i].ignore = src[i].ignore;
dest[i].is_defined_var = src[i].is_defined_var;
dest[i].max = src[i].max;
dest[i].min = src[i].min;
dest[i].name = src[i].name;
dest[i].output_var = src[i].output_var;
dest[i].to_label = src[i].to_label;
dest[i].var_is_introduced = src[i].var_is_introduced;
dest[i].replace_by_v_id = src[i].replace_by_v_id;
dest[i].created = src[i].created;
|
4d26a735
Pedro Roque
Increased recogni...
|
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
|
}
}
/*
* If the array of variables is already full, doubles its size
*/
void fzn_vars_extend() {
if (fzn_next_var_posit == fzn_n_vars) {
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
1465
1466
1467
1468
1469
1470
|
printf("Extending FZN variables array.\n");
fzn_vars_aux = malloc(fzn_n_vars * 2 * (sizeof(fzn_var)));
fzn_vars_copy(fzn_vars_aux, fzn_vars, fzn_n_vars);
|
4d26a735
Pedro Roque
Increased recogni...
|
1471
|
free(fzn_vars);
|
94b2b13d
Pedro Roque
PHACT source
|
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
|
fzn_vars = fzn_vars_aux;
fzn_n_vars *= 2;
}
}
/*
* Save the index of the variable to optimize
*/
void fzn_set_var_to_optimize(char* var_name) {
int i;
if (FZN_VERBOSE)
printf("Preparing optimization.\n");
// get the ID of the variable with that name
|
4d26a735
Pedro Roque
Increased recogni...
|
1489
|
for (i = 0; i < fzn_next_var_posit; i++) {
|
94b2b13d
Pedro Roque
PHACT source
|
1490
|
if (fzn_vars[i].name != NULL && strcmp(var_name, fzn_vars[i].name) == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
|
optimize_var_idx = i;
break;
}
}
}
/*
* Create a new empty output array that will contain the IDs of the variable to print
*/
void fzn_new_output_array() {
if (FZN_VERBOSE)
printf("Adding new FZN output array (%d).\n", fzn_next_output_array_posit);
// if the array of output arrays is full, doubles its size
|
94b2b13d
Pedro Roque
PHACT source
|
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
|
if (fzn_next_output_array_posit == fzn_n_output_arrays) {
fzn_output_arrays_aux = malloc(fzn_n_output_arrays * 2 * (sizeof(fzn_output_array)));
fzn_output_array_copy(fzn_output_arrays_aux, fzn_output_arrays, fzn_n_output_arrays);
free(fzn_output_arrays);
fzn_output_arrays = fzn_output_arrays_aux;
fzn_n_output_arrays *= 2;
}
// reset all the array values
fzn_output_arrays[fzn_next_output_array_posit].max_vars = FZN_MAX_ELEMENTS;
fzn_output_arrays[fzn_next_output_array_posit].next_position = 0;
fzn_output_arrays[fzn_next_output_array_posit].vars_id = malloc(FZN_MAX_ELEMENTS * sizeof(unsigned int));
fzn_output_arrays[fzn_next_output_array_posit].vars_id_aux = NULL;
fzn_output_arrays[fzn_next_output_array_posit].name = NULL;
fzn_next_output_array_posit++;
}
/*
* Copy an output array
* dest - the array from where to copy the output_array to
* src - the array from where to copy the output_array from
|
4d26a735
Pedro Roque
Increased recogni...
|
1530
|
* n_arrays - number of output_arrays to copy
|
94b2b13d
Pedro Roque
PHACT source
|
1531
1532
1533
1534
1535
1536
1537
1538
1539
|
*/
void fzn_output_array_copy(fzn_output_array* dest, fzn_output_array* src, int n_arrays) {
int i;
if (FZN_VERBOSE)
printf("Copying FZN output array.\n");
for (i = 0; i < n_arrays; i++) {
dest[i].max_vars = src[i].max_vars;
|
4d26a735
Pedro Roque
Increased recogni...
|
1540
1541
1542
1543
1544
1545
1546
1547
1548
|
dest[i].next_position = src[i].next_position;
dest[i].vars_id = src[i].vars_id;
dest[i].vars_id_aux = src[i].vars_id_aux;
dest[i].name = src[i].name;
}
}
/*
* Adds a variable ID to the last created output_array
|
94b2b13d
Pedro Roque
PHACT source
|
1549
1550
1551
1552
|
* v_id - ID of the variable to add to the array
*/
void fzn_add_var_id_to_output_array(unsigned int v_id) {
int i;
|
4d26a735
Pedro Roque
Increased recogni...
|
1553
|
|
94b2b13d
Pedro Roque
PHACT source
|
1554
1555
|
if (FZN_VERBOSE) {
if (fzn_vars[v_id].name != NULL) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1556
|
printf("Adding variable ID %d with name %s to FZN output array number %d.\n", v_id, fzn_vars[v_id].name, fzn_next_output_array_posit - 1);
|
94b2b13d
Pedro Roque
PHACT source
|
1557
|
|
4d26a735
Pedro Roque
Increased recogni...
|
1558
|
} else {
|
94b2b13d
Pedro Roque
PHACT source
|
1559
|
printf("Adding variable ID %d to FZN output array number %d.\n", v_id, fzn_next_output_array_posit - 1);
|
4d26a735
Pedro Roque
Increased recogni...
|
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
|
}
}
// if the array of integers is already full, doubles its size
if (fzn_output_arrays[fzn_next_output_array_posit - 1].next_position == fzn_output_arrays[fzn_next_output_array_posit - 1].max_vars) {
fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id_aux = malloc(fzn_output_arrays[fzn_next_output_array_posit - 1].max_vars * 2 * (sizeof(unsigned int)));
for (i = 0; i < fzn_output_arrays[fzn_next_output_array_posit - 1].max_vars; i++) {
fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id_aux[i] = fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id[i];
}
free(fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id);
fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id = fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id_aux;
fzn_output_arrays[fzn_next_output_array_posit - 1].max_vars *= 2;
|
94b2b13d
Pedro Roque
PHACT source
|
1575
1576
1577
|
}
// adds the new value to the array
|
4d26a735
Pedro Roque
Increased recogni...
|
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
|
fzn_output_arrays[fzn_next_output_array_posit - 1].vars_id[fzn_output_arrays[fzn_next_output_array_posit - 1].next_position] = v_id;
fzn_output_arrays[fzn_next_output_array_posit - 1].next_position++;
}
/*
* Create a new flatzinc constraint structure
*/
void fzn_new_fzn_obj_constr() {
int i, j;
if (FZN_VERBOSE)
printf("Creating new FZN constraint (number %d).\n", fzn_next_constr_posit);
fzn_obj.is_constraint = true;
|
94b2b13d
Pedro Roque
PHACT source
|
1592
1593
1594
1595
|
// if the array of constraints is already full, doubles its size
if (fzn_next_constr_posit == fzn_n_constrs) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1596
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
1597
1598
1599
1600
1601
|
printf("Extending fzn constraints array.\n");
fzn_constrs_aux = malloc(fzn_n_constrs * 2 * (sizeof(fzn_constr)));
fzn_constrs_copy(fzn_constrs_aux, fzn_constrs, fzn_n_constrs);
|
4d26a735
Pedro Roque
Increased recogni...
|
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
|
free(fzn_constrs);
fzn_constrs = fzn_constrs_aux;
fzn_n_constrs *= 2;
}
fzn_constrs[fzn_next_constr_posit].name = NULL;
fzn_constrs[fzn_next_constr_posit].defines_var_idx = -1;
fzn_constrs[fzn_next_constr_posit].consts = NULL;
fzn_constrs[fzn_next_constr_posit].consts_aux = NULL;
fzn_constrs[fzn_next_constr_posit].vars_id = NULL;
fzn_constrs[fzn_next_constr_posit].vars_id_aux = NULL;
fzn_constrs[fzn_next_constr_posit].ignore = false;
|
94b2b13d
Pedro Roque
PHACT source
|
1616
1617
|
fzn_constrs[fzn_next_constr_posit].max_consts = 0;
fzn_constrs[fzn_next_constr_posit].max_vars = 0;
|
4d26a735
Pedro Roque
Increased recogni...
|
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
|
fzn_constrs[fzn_next_constr_posit].next_const_to_add = 0;
fzn_constrs[fzn_next_constr_posit].next_var_to_add = 0;
fzn_constrs[fzn_next_constr_posit].boundsR = false;
fzn_constrs[fzn_next_constr_posit].boundsD = false;
fzn_constrs[fzn_next_constr_posit].boundsZ = false;
fzn_constrs[fzn_next_constr_posit].domain = false;
fzn_constrs[fzn_next_constr_posit].priority = false;
fzn_constrs[fzn_next_constr_posit].id = -1;
fzn_constrs[fzn_next_constr_posit].pos_init_2_array = fzn_obj.pos_init_2_array;
for (i = 0; i < fzn_obj.next_annot; i++) {
if (FZN_VERBOSE)
printf("Adding annotation %s to constraint.\n", fzn_obj.annots[i]);
if (strcmp(fzn_obj.annots[i], "defines_var") == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
1634
1635
1636
|
for (j = 0; j < fzn_next_var_posit; j++) {
if (fzn_vars[j].name != NULL && strcmp(fzn_vars[j].name, fzn_constrs[fzn_next_constr_posit].name) == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1637
1638
1639
|
if (FZN_VERBOSE)
printf("Setting this constraint as defining variable %s.\n", fzn_vars[j].name);
|
94b2b13d
Pedro Roque
PHACT source
|
1640
1641
|
fzn_constrs[fzn_next_constr_posit].defines_var_idx = j;
|
4d26a735
Pedro Roque
Increased recogni...
|
1642
1643
1644
|
fzn_vars[j].defined_by_constr_idx = fzn_next_constr_posit;
fzn_vars[j].is_defined_var = true; // some FlatZinc models do not mark the variable
|
94b2b13d
Pedro Roque
PHACT source
|
1645
1646
|
if (FZN_VERBOSE)
printf("Setting variable %s as defined by current constraint.\n", fzn_vars[j].name);
|
4d26a735
Pedro Roque
Increased recogni...
|
1647
1648
1649
|
free(fzn_constrs[fzn_next_constr_posit].name);
fzn_constrs[fzn_next_constr_posit].name = NULL;
|
94b2b13d
Pedro Roque
PHACT source
|
1650
1651
|
break;
|
4d26a735
Pedro Roque
Increased recogni...
|
1652
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
1653
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1654
|
|
94b2b13d
Pedro Roque
PHACT source
|
1655
|
} else if (strcmp(fzn_obj.annots[i], "boundsZ") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1656
|
fzn_constrs[fzn_next_constr_posit].boundsZ = true;
|
94b2b13d
Pedro Roque
PHACT source
|
1657
1658
1659
1660
1661
1662
1663
1664
|
} else if (strcmp(fzn_obj.annots[i], "boundsR") == 0) {
fzn_constrs[fzn_next_constr_posit].boundsR = true;
} else if (strcmp(fzn_obj.annots[i], "boundsD") == 0) {
fzn_constrs[fzn_next_constr_posit].boundsD = true;
} else if (strcmp(fzn_obj.annots[i], "domain") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1665
|
fzn_constrs[fzn_next_constr_posit].domain = true;
|
94b2b13d
Pedro Roque
PHACT source
|
1666
1667
1668
|
} else if (strcmp(fzn_obj.annots[i], "priority") == 0) {
fzn_constrs[fzn_next_constr_posit].priority = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
1669
|
|
94b2b13d
Pedro Roque
PHACT source
|
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
|
} else {
if (fzn_constrs[fzn_next_constr_posit].name == NULL) {
if (FZN_VERBOSE)
printf("Adding name %s to constraint.\n", fzn_obj.annots[i]);
fzn_constrs[fzn_next_constr_posit].name = malloc((strlen(fzn_obj.annots[i]) + 1) * sizeof(char));
strcpy(fzn_constrs[fzn_next_constr_posit].name, fzn_obj.annots[i]);
} else {
fprintf(stderr, "Trying to name constraint with %s when its name is already %s.\n", fzn_constrs[fzn_next_constr_posit].name, fzn_obj.annots[i]);
exit(-1);
}
}
}
if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lt") == 0
|
4d26a735
Pedro Roque
Increased recogni...
|
1688
|
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_le") == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
1689
|
|
4d26a735
Pedro Roque
Increased recogni...
|
1690
1691
1692
1693
|
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(2 * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_vars = 2;
fzn_add_fzn_obj_elem_var_to_constr(0);
|
94b2b13d
Pedro Roque
PHACT source
|
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
|
fzn_add_fzn_obj_elem_var_to_constr(1);
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "bool2int") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "bool_eq") == 0) {
if (fzn_obj.element_is_var[0] && fzn_obj.element_is_var[1]) {
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(2 * sizeof(unsigned int));
#if FZN_REPLACE_BOOL2INT
fzn_vars[fzn_obj.elements[1]].replace_by_v_id = fzn_obj.elements[0];
fzn_vars[fzn_obj.elements[1]].ignore = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
1707
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
|
printf("Replacing variable %s by variable %s due to FZN constraint %s.\n", fzn_vars[fzn_obj.elements[1]].name,
fzn_vars[fzn_obj.elements[0]].name, fzn_constrs[fzn_next_constr_posit].name);
fzn_constrs[fzn_next_constr_posit].ignore = true;
#endif
fzn_constrs[fzn_next_constr_posit].max_vars = 2;
fzn_add_fzn_obj_elem_var_to_constr(0);
fzn_add_fzn_obj_elem_var_to_constr(1);
} else {
fprintf(stderr, "fzn_obj has values instead of variables when ignoring constraint %s (%d).\n", fzn_obj.annots[0], fzn_next_constr_posit);
|
4d26a735
Pedro Roque
Increased recogni...
|
1721
|
exit(-1);
|
94b2b13d
Pedro Roque
PHACT source
|
1722
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1723
|
|
94b2b13d
Pedro Roque
PHACT source
|
1724
1725
1726
|
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "bool_clause") == 0) {
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(fzn_obj.next_element * sizeof(unsigned int));
|
4d26a735
Pedro Roque
Increased recogni...
|
1727
|
fzn_constrs[fzn_next_constr_posit].max_vars = fzn_obj.next_element;
|
94b2b13d
Pedro Roque
PHACT source
|
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
|
for (i = 0; i < fzn_obj.next_element; i++) {
fzn_add_fzn_obj_elem_var_to_constr(i);
}
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_ne") == 0 && !fzn_obj.element_is_var[1]) {
fzn_constrs[fzn_next_constr_posit].consts = malloc(sizeof(int));
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_consts = 1;
fzn_constrs[fzn_next_constr_posit].max_vars = 1;
fzn_add_fzn_obj_elem_var_to_constr(0);
fzn_add_fzn_obj_elem_val_to_constr(1);
} else if ((strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_eq_reif") == 0 && !fzn_obj.element_is_var[1])
|
4d26a735
Pedro Roque
Increased recogni...
|
1744
|
|| (strcmp(fzn_constrs[fzn_next_constr_posit].name, "bool_eq_reif") == 0 && !fzn_obj.element_is_var[1])) {
|
94b2b13d
Pedro Roque
PHACT source
|
1745
1746
1747
|
fzn_constrs[fzn_next_constr_posit].consts = malloc(1 * sizeof(int));
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(2 * sizeof(unsigned int));
|
4d26a735
Pedro Roque
Increased recogni...
|
1748
|
fzn_constrs[fzn_next_constr_posit].max_consts = 1;
|
94b2b13d
Pedro Roque
PHACT source
|
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
|
fzn_constrs[fzn_next_constr_posit].max_vars = 2;
fzn_add_fzn_obj_elem_var_to_constr(0);
fzn_add_fzn_obj_elem_val_to_constr(1);
fzn_add_fzn_obj_elem_var_to_constr(2);
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_times") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_eq_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lt_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_le_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_ne_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "bool_eq_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_max") == 0) {
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(3 * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_vars = 3;
fzn_add_fzn_obj_elem_var_to_constr(0);
fzn_add_fzn_obj_elem_var_to_constr(1);
fzn_add_fzn_obj_elem_var_to_constr(2);
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lin_ne") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lin_le") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lin_eq") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1773
|
|
94b2b13d
Pedro Roque
PHACT source
|
1774
1775
1776
|
int n_consts = (fzn_obj.next_element - 1) / 2 + 1;
int n_vars = fzn_obj.next_element - n_consts;
|
4d26a735
Pedro Roque
Increased recogni...
|
1777
|
fzn_constrs[fzn_next_constr_posit].consts = malloc(n_consts * sizeof(int));
|
94b2b13d
Pedro Roque
PHACT source
|
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
|
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(n_vars * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_consts = n_consts;
fzn_constrs[fzn_next_constr_posit].max_vars = n_vars;
for (i = 0; i < n_consts - 1; i++) {
fzn_add_fzn_obj_elem_val_to_constr(i);
}
for (; i < n_vars + n_consts - 1; i++) {
fzn_add_fzn_obj_elem_var_to_constr(i);
}
fzn_add_fzn_obj_elem_val_to_constr(i);
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lin_ne_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lin_le_reif") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "int_lin_eq_reif") == 0) {
int n_consts = (fzn_obj.next_element - 2) / 2 + 1;
int n_vars = fzn_obj.next_element - n_consts;
fzn_constrs[fzn_next_constr_posit].consts = malloc(n_consts * sizeof(int));
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(n_vars * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_consts = n_consts;
fzn_constrs[fzn_next_constr_posit].max_vars = n_vars;
for (i = 0; i < (fzn_obj.next_element - 2) / 2; i++) {
fzn_add_fzn_obj_elem_val_to_constr(i);
}
for (; i < fzn_obj.next_element - 2; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
1806
1807
|
fzn_add_fzn_obj_elem_var_to_constr(i);
}
|
94b2b13d
Pedro Roque
PHACT source
|
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
|
fzn_add_fzn_obj_elem_val_to_constr(i);
fzn_add_fzn_obj_elem_var_to_constr(i + 1);
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "array_bool_or") == 0
|| strcmp(fzn_constrs[fzn_next_constr_posit].name, "array_bool_and") == 0) {
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(fzn_obj.next_element * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_vars = fzn_obj.next_element;
for (i = 0; i < fzn_obj.next_element; i++) {
fzn_add_fzn_obj_elem_var_to_constr(i);
}
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "array_var_int_element") == 0) {
if (fzn_obj.element_is_var[fzn_obj.next_element - 1]) {
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(fzn_obj.next_element * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_vars = fzn_obj.next_element;
} else {
fzn_constrs[fzn_next_constr_posit].consts = malloc(1 * sizeof(int));
fzn_constrs[fzn_next_constr_posit].vars_id = malloc((fzn_obj.next_element - 1) * sizeof(unsigned int));
|
4d26a735
Pedro Roque
Increased recogni...
|
1831
|
fzn_constrs[fzn_next_constr_posit].max_consts = 1;
|
94b2b13d
Pedro Roque
PHACT source
|
1832
1833
1834
1835
1836
1837
1838
1839
1840
|
fzn_constrs[fzn_next_constr_posit].max_vars = fzn_obj.next_element - 1;
}
for (i = 0; i < fzn_obj.next_element - 1; i++) {
fzn_add_fzn_obj_elem_var_to_constr(i);
}
if (fzn_obj.element_is_var[fzn_obj.next_element - 1]) {
fzn_add_fzn_obj_elem_var_to_constr(i);
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
1841
|
fzn_add_fzn_obj_elem_val_to_constr(i);
|
94b2b13d
Pedro Roque
PHACT source
|
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
|
}
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "array_int_element") == 0) {
fzn_constrs[fzn_next_constr_posit].consts = malloc((fzn_obj.next_element - 2) * sizeof(int));
fzn_constrs[fzn_next_constr_posit].vars_id = malloc(2 * sizeof(unsigned int));
fzn_constrs[fzn_next_constr_posit].max_consts = fzn_obj.next_element - 2;
fzn_constrs[fzn_next_constr_posit].max_vars = 2;
fzn_add_fzn_obj_elem_var_to_constr(0);
|
4d26a735
Pedro Roque
Increased recogni...
|
1852
|
for (i = 1; i < fzn_obj.next_element - 1; i++) {
|
94b2b13d
Pedro Roque
PHACT source
|
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
|
fzn_add_fzn_obj_elem_val_to_constr(i);
}
fzn_add_fzn_obj_elem_var_to_constr(i);
} else if (strcmp(fzn_constrs[fzn_next_constr_posit].name, "all_different") == 0) {
// already done
} else {
fprintf(stderr, "Constraint \"%s\" (%d) not recognized when creating FZN constraint.\n", fzn_constrs[fzn_next_constr_posit].name, fzn_next_constr_posit);
exit(-1);
}
fzn_reset_object_elements();
fzn_next_constr_posit++;
}
/*
* Add an element IDX to the last created constraint
* e_idx - element idx in fzn_obj
*/
void fzn_add_fzn_obj_elem_var_to_constr(int e_idx) {
int v_idx;
int i;
if (fzn_constrs[fzn_next_constr_posit].max_vars == 0) {
fprintf(stderr, "\n Error: max_vars = 0 when constructing fzn constraint %s.\n", fzn_constrs[fzn_next_constr_posit].name);
exit(-1);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1883
|
// if the array of variables that are constrained by this constraint is already full, doubles it
|
94b2b13d
Pedro Roque
PHACT source
|
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
|
if (fzn_constrs[fzn_next_constr_posit].next_var_to_add == fzn_constrs[fzn_next_constr_posit].max_vars) {
if (FZN_VERBOSE)
printf("Extending variables array for constraint %s.\n", fzn_constrs[fzn_next_constr_posit].name);
fzn_constrs[fzn_next_constr_posit].vars_id_aux = malloc(fzn_constrs[fzn_next_constr_posit].max_vars * 2 * (sizeof(unsigned int)));
for (i = 0; i < fzn_constrs[fzn_next_constr_posit].max_vars; i++) {
fzn_constrs[fzn_next_constr_posit].vars_id_aux[i] = fzn_constrs[fzn_next_constr_posit].vars_id[i];
}
free(fzn_constrs[fzn_next_constr_posit].vars_id);
fzn_constrs[fzn_next_constr_posit].vars_id = fzn_constrs[fzn_next_constr_posit].vars_id_aux;
|
4d26a735
Pedro Roque
Increased recogni...
|
1897
|
|
94b2b13d
Pedro Roque
PHACT source
|
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
|
fzn_constrs[fzn_next_constr_posit].max_vars *= 2;
}
if (fzn_obj.element_is_var[e_idx]) {
v_idx = fzn_obj.elements[e_idx];
} else {
v_idx = fzn_new_fzn_obj_var_value(fzn_obj.elements[e_idx]);
}
if (FZN_VERBOSE)
printf("Adding variable %d to constraint %s.\n", v_idx, fzn_constrs[fzn_next_constr_posit].name);
fzn_constrs[fzn_next_constr_posit].vars_id[fzn_constrs[fzn_next_constr_posit].next_var_to_add] = v_idx;
fzn_constrs[fzn_next_constr_posit].next_var_to_add++;
}
/*
* Adds a value to the array of constants of the flatzinc constraint
* e_idx - element idx in fzn_obj
*/
void fzn_add_fzn_obj_elem_val_to_constr(int e_idx) {
int i;
if (FZN_VERBOSE)
printf("Adding value %d to constraint %s.\n", fzn_obj.elements[e_idx], fzn_constrs[fzn_next_constr_posit].name);
|
4d26a735
Pedro Roque
Increased recogni...
|
1923
1924
1925
1926
1927
1928
1929
1930
1931
|
if (fzn_constrs[fzn_next_constr_posit].max_consts == 0) {
fprintf(stderr, "\n Error: max_consts = 0 when constructing fzn constraint %s.\n", fzn_constrs[fzn_next_constr_posit].name);
exit(-1);
}
// If the array of constants is already full, doubles its size
if (fzn_constrs[fzn_next_constr_posit].next_const_to_add == fzn_constrs[fzn_next_constr_posit].max_consts) {
|
94b2b13d
Pedro Roque
PHACT source
|
1932
1933
1934
1935
|
if (FZN_VERBOSE)
printf("Extending values array for constraint %s.\n", fzn_constrs[fzn_next_constr_posit].name);
fzn_constrs[fzn_next_constr_posit].consts_aux = malloc(fzn_constrs[fzn_next_constr_posit].max_consts * 2 * (sizeof(int)));
|
4d26a735
Pedro Roque
Increased recogni...
|
1936
1937
1938
|
for (i = 0; i < fzn_constrs[fzn_next_constr_posit].max_consts; i++) {
fzn_constrs[fzn_next_constr_posit].consts_aux[i] = fzn_constrs[fzn_next_constr_posit].consts[i];
|
94b2b13d
Pedro Roque
PHACT source
|
1939
1940
1941
1942
1943
1944
1945
|
}
free(fzn_constrs[fzn_next_constr_posit].consts);
fzn_constrs[fzn_next_constr_posit].consts = fzn_constrs[fzn_next_constr_posit].consts_aux;
fzn_constrs[fzn_next_constr_posit].max_consts *= 2;
}
|
4d26a735
Pedro Roque
Increased recogni...
|
1946
1947
|
if (fzn_obj.element_is_var[e_idx]) {
|
94b2b13d
Pedro Roque
PHACT source
|
1948
1949
1950
1951
1952
|
fprintf(stderr, "\n Error: value marked as variable when constructing fzn constraint %s.\n", fzn_constrs[fzn_next_constr_posit].name);
exit(-1);
}
// Adds the value
|
4d26a735
Pedro Roque
Increased recogni...
|
1953
1954
1955
1956
|
fzn_constrs[fzn_next_constr_posit].consts[fzn_constrs[fzn_next_constr_posit].next_const_to_add] = fzn_obj.elements[e_idx];
fzn_constrs[fzn_next_constr_posit].next_const_to_add++;
}
|
94b2b13d
Pedro Roque
PHACT source
|
1957
1958
1959
1960
|
/*
* Copy a Flatzinc constraint
* dest - the array from where to copy the constraint to
* src - the array from where to copy the constraint from
|
4d26a735
Pedro Roque
Increased recogni...
|
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
|
* n_constrs - number of constraints to copy
*/
void fzn_constrs_copy(fzn_constr* dest, fzn_constr* src, int n_constrs) {
int i;
if (FZN_VERBOSE)
printf("Copying FZN constraint.\n");
for (i = 0; i < n_constrs; i++) {
dest[i].consts = src[i].consts;
dest[i].consts_aux = src[i].consts_aux;
dest[i].defines_var_idx = src[i].defines_var_idx;
dest[i].ignore = src[i].ignore;
dest[i].boundsZ = src[i].boundsZ;
dest[i].boundsR = src[i].boundsR;
dest[i].boundsD = src[i].boundsD;
dest[i].domain = src[i].domain;
dest[i].priority = src[i].priority;
dest[i].priority_v_id = src[i].priority_v_id;
|
94b2b13d
Pedro Roque
PHACT source
|
1980
1981
|
dest[i].max_consts = src[i].max_consts;
dest[i].max_vars = src[i].max_vars;
|
4d26a735
Pedro Roque
Increased recogni...
|
1982
1983
1984
1985
1986
1987
1988
1989
1990
|
dest[i].name = src[i].name;
dest[i].next_const_to_add = src[i].next_const_to_add;
dest[i].next_var_to_add = src[i].next_var_to_add;
dest[i].vars_id = src[i].vars_id;
dest[i].vars_id_aux = src[i].vars_id_aux;
dest[i].pos_init_2_array = src[i].pos_init_2_array;
}
}
|
94b2b13d
Pedro Roque
PHACT source
|
1991
1992
|
/*
* Create a new search annotation with the last fzn_obj data
|
4d26a735
Pedro Roque
Increased recogni...
|
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
|
*/
void fzn_add_fzn_obj_search_annot() {
int i;
// if the array of search annotations is already full, doubles its size
if (fzn_next_search_annot_posit == fzn_n_search_annot) {
fzn_search_annot_aux = malloc(fzn_n_search_annot * 2 * (sizeof(fzn_search_annotat)));
fzn_search_annots_copy(fzn_search_annot_aux, fzn_search_annot, fzn_n_search_annot);
free(fzn_search_annot);
fzn_search_annot = fzn_search_annot_aux;
fzn_n_search_annot *= 2;
}
fzn_search_annot[fzn_next_search_annot_posit].label_array_name = NULL;
if (fzn_obj.next_annot > 5) {
i = 0;
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2015
|
printf("Adding new array with name array_to_label (number %d).\n", fzn_next_array_posit);
|
4d26a735
Pedro Roque
Increased recogni...
|
2016
|
|
94b2b13d
Pedro Roque
PHACT source
|
2017
2018
2019
2020
|
// if the array of arrays is full, doubles its size
if (fzn_next_array_posit == fzn_n_arrays) {
fzn_arrays_aux = malloc(fzn_n_arrays * 2 * (sizeof(fzn_array)));
|
4d26a735
Pedro Roque
Increased recogni...
|
2021
2022
|
fzn_array_copy(fzn_arrays_aux, fzn_arrays, fzn_n_arrays);
|
94b2b13d
Pedro Roque
PHACT source
|
2023
|
free(fzn_arrays);
|
4d26a735
Pedro Roque
Increased recogni...
|
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
|
fzn_arrays = fzn_arrays_aux;
fzn_n_arrays *= 2;
}
fzn_arrays[fzn_next_array_posit].name = malloc((strlen("array_to_label") + 1) * sizeof(char));
strcpy(fzn_arrays[fzn_next_array_posit].name, "array_to_label");
fzn_arrays[fzn_next_array_posit].output_var = false;
fzn_arrays[fzn_next_array_posit].is_defined_var = false;
fzn_arrays[fzn_next_array_posit].var_is_introduced = false;
fzn_arrays[fzn_next_array_posit].output_array = false;
fzn_arrays[fzn_next_array_posit].to_label = true;
fzn_arrays[fzn_next_array_posit].next_position = 0;
fzn_arrays[fzn_next_array_posit].values = malloc(FZN_MAX_ELEMENTS * sizeof(int));
fzn_arrays[fzn_next_array_posit].max_values = FZN_MAX_ELEMENTS;
fzn_arrays[fzn_next_array_posit].values_aux = NULL;
fzn_arrays[fzn_next_array_posit].var_array = true;
fzn_search_annot[fzn_next_search_annot_posit].label_array_name = malloc((strlen("array_to_label") + 1) * sizeof(char));
strcpy(fzn_search_annot[fzn_next_search_annot_posit].label_array_name, "array_to_label");
|
94b2b13d
Pedro Roque
PHACT source
|
2045
2046
2047
2048
|
fzn_next_array_posit++;
for (i = 0; i < fzn_obj.next_annot - 4; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2049
|
fzn_add_var_to_array(fzn_obj.annots[i]);
|
94b2b13d
Pedro Roque
PHACT source
|
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
|
}
} else {
fzn_search_annot[fzn_next_search_annot_posit].label_array_name = malloc((strlen(fzn_obj.annots[0]) + 1) * sizeof(char));
strcpy(fzn_search_annot[fzn_next_search_annot_posit].label_array_name, fzn_obj.annots[0]);
i = 1;
}
if (FZN_VERBOSE)
printf("Creating new search annotation %s, %s, %s, %s, %s.\n", fzn_obj.annots[i + 3]
, fzn_search_annot[fzn_next_search_annot_posit].label_array_name
, fzn_obj.annots[i], fzn_obj.annots[i + 1], fzn_obj.annots[i + 2]);
fzn_search_annot[fzn_next_search_annot_posit].label_heur = malloc((strlen(fzn_obj.annots[i]) + 1) * sizeof(char));
strcpy(fzn_search_annot[fzn_next_search_annot_posit].label_heur, fzn_obj.annots[i]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2066
2067
2068
2069
2070
2071
2072
2073
|
fzn_search_annot[fzn_next_search_annot_posit].assign_heur = malloc((strlen(fzn_obj.annots[i + 1]) + 1) * sizeof(char));
strcpy(fzn_search_annot[fzn_next_search_annot_posit].assign_heur, fzn_obj.annots[i + 1]);
fzn_search_annot[fzn_next_search_annot_posit].search_strategy = malloc((strlen(fzn_obj.annots[i + 2]) + 1) * sizeof(char));
strcpy(fzn_search_annot[fzn_next_search_annot_posit].search_strategy, fzn_obj.annots[i + 2]);
fzn_search_annot[fzn_next_search_annot_posit].search_type = malloc((strlen(fzn_obj.annots[i + 3]) + 1) * sizeof(char));
strcpy(fzn_search_annot[fzn_next_search_annot_posit].search_type, fzn_obj.annots[i + 3]);
|
94b2b13d
Pedro Roque
PHACT source
|
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
|
fzn_next_search_annot_posit++;
// int_search or bool_search
fzn_reset_object_elements();
}
/*
* Copy a Flatzinc search annotation
* dest - the array from where to copy the search annotation to
* src - the array from where to copy the search annotation from
* n_search_annots - number of search annotation to copy
|
4d26a735
Pedro Roque
Increased recogni...
|
2086
2087
2088
2089
2090
2091
2092
2093
2094
|
*/
void fzn_search_annots_copy(fzn_search_annotat* dest, fzn_search_annotat* src, int n_search_annots) {
int i;
if (FZN_VERBOSE)
printf("Copying FZN constraint.\n");
for (i = 0; i < n_search_annots; i++) {
dest[i].assign_heur = src[i].assign_heur;
|
94b2b13d
Pedro Roque
PHACT source
|
2095
2096
2097
2098
2099
2100
2101
2102
|
dest[i].label_array_name = src[i].label_array_name;
dest[i].label_heur = src[i].label_heur;
dest[i].search_strategy = src[i].search_strategy;
dest[i].search_type = src[i].search_type;
}
}
/*
|
4d26a735
Pedro Roque
Increased recogni...
|
2103
|
* Set an array of variables or a variable to label
|
94b2b13d
Pedro Roque
PHACT source
|
2104
|
*/
|
4d26a735
Pedro Roque
Increased recogni...
|
2105
|
void fzn_set_var_or_array_to_label(char* name) {
|
94b2b13d
Pedro Roque
PHACT source
|
2106
|
int i, j;
|
4d26a735
Pedro Roque
Increased recogni...
|
2107
2108
2109
2110
|
for (i = 0; i < fzn_next_array_posit; i++) {
if (fzn_arrays[i].name != NULL && strcmp(fzn_arrays[i].name, name) == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
2111
|
|
4d26a735
Pedro Roque
Increased recogni...
|
2112
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2113
|
printf("Setting array %s to label.\n", name);
|
4d26a735
Pedro Roque
Increased recogni...
|
2114
|
|
94b2b13d
Pedro Roque
PHACT source
|
2115
|
fzn_arrays[i].to_label = true;
|
4d26a735
Pedro Roque
Increased recogni...
|
2116
2117
|
for (j = 0; j < fzn_arrays[i].next_position; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
2118
|
|
4d26a735
Pedro Roque
Increased recogni...
|
2119
2120
2121
2122
|
if (fzn_vars[fzn_arrays[i].values[j]].ignore) {
if (FZN_VERBOSE)
printf("Setting variable %s to label because variable %s is ignored.\n",
|
94b2b13d
Pedro Roque
PHACT source
|
2123
|
fzn_vars[fzn_vars[fzn_arrays[i].values[j]].replace_by_v_id].name, fzn_vars[fzn_arrays[i].values[j]].name);
|
4d26a735
Pedro Roque
Increased recogni...
|
2124
2125
2126
2127
2128
2129
|
fzn_vars[fzn_vars[fzn_arrays[i].values[j]].replace_by_v_id].to_label = true;
} else {
if (FZN_VERBOSE)
printf("Setting variable %s to label.\n", fzn_vars[fzn_arrays[i].values[j]].name);
|
94b2b13d
Pedro Roque
PHACT source
|
2130
2131
|
fzn_vars[fzn_arrays[i].values[j]].to_label = true;
|
94b2b13d
Pedro Roque
PHACT source
|
2132
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
2133
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
2134
|
return;
|
4d26a735
Pedro Roque
Increased recogni...
|
2135
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
2136
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
2137
2138
2139
2140
|
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].name != NULL && strcmp(fzn_vars[i].name, name) == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
2141
|
if (fzn_vars[i].ignore) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2142
|
|
94b2b13d
Pedro Roque
PHACT source
|
2143
|
if (FZN_VERBOSE)
|
4d26a735
Pedro Roque
Increased recogni...
|
2144
|
printf("Setting variable %s to label because variable %s is ignored.\n", fzn_vars[fzn_vars[i].replace_by_v_id].name, name);
|
94b2b13d
Pedro Roque
PHACT source
|
2145
|
|
4d26a735
Pedro Roque
Increased recogni...
|
2146
2147
|
fzn_vars[fzn_vars[i].replace_by_v_id].to_label = true;
|
94b2b13d
Pedro Roque
PHACT source
|
2148
|
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
|
if (FZN_VERBOSE)
printf("Setting variable %s to label.\n", name);
fzn_vars[i].to_label = true;
}
return;
}
}
fprintf(stderr, "\n Error: variable or array name (\"%s\") not found when setting it to label.\n", name);
exit(-1);
}
/*
* Sort the variables of some constraints for input order for possible detection and removal of duplicated constraints
*/
void fzn_sort_constr_vars() {
unsigned int* vars;
int* consts;
int temp_int;
unsigned int temp_uint;
int i, j, k, n_vars;
if (FZN_VERBOSE)
printf("Sorting the variables of some constraints in input order.\n");
for (i = 0; i < fzn_next_constr_posit; i++) {
if (strcmp(fzn_constrs[i].name, "int_lin_le") == 0) {
n_vars = fzn_constrs[i].next_var_to_add;
vars = fzn_constrs[i].vars_id;
consts = fzn_constrs[i].consts;
for (j = 0; j < n_vars - 1; j++) {
for (k = 0; k < n_vars - j - 1; k++) {
if (vars[k] > vars[k + 1]) {
// swap variables
temp_uint = vars[k];
vars[k] = vars[k + 1];
vars[k + 1] = temp_uint;
// swap constants
temp_int = consts[k];
consts[k] = consts[k + 1];
consts[k + 1] = temp_int;
}
}
}
}
}
}
/*
* Create a new CSP variable correspondent to the Flatzinc variable in index var_idx of fzn_vars array
* var_idx - index of fzn_vars array where the variable is
*/
void fzn_new_csp_var(int var_idx) {
unsigned int v_id;
int i;
if (FZN_VERBOSE) {
if (!fzn_vars[var_idx].ignore && !fzn_vars[var_idx].created) {
printf("Creating new CSP variable");
if (fzn_vars[var_idx].name != NULL) {
printf(" from %s", fzn_vars[var_idx].name);
}
if (fzn_vars[var_idx].range == true) {
printf(" with range %d,%d", fzn_vars[var_idx].min, fzn_vars[var_idx].max);
} else {
printf(" with values {");
for (i = 0; i < fzn_vars[var_idx].next_position - 1; i++) {
printf("%d,", fzn_vars[var_idx].values[i]);
}
printf("%d}", fzn_vars[var_idx].values[i]);
}
} else {
printf("Variable");
if (fzn_vars[var_idx].name != NULL) {
printf(" from %s", fzn_vars[var_idx].name);
}
if (fzn_vars[var_idx].range == true) {
printf(" with range %d,%d ", fzn_vars[var_idx].min, fzn_vars[var_idx].max);
} else {
printf(" with values {");
for (i = 0; i < fzn_vars[var_idx].next_position - 1; i++) {
printf("%d,", fzn_vars[var_idx].values[i]);
}
printf("%d} ", fzn_vars[var_idx].values[i]);
}
printf("is ignored (or already created), so it won't be created.\n");
}
}
if (!fzn_vars[var_idx].ignore && !fzn_vars[var_idx].created) {
// ranged values
if (fzn_vars[var_idx].range == true) {
if (fzn_vars[var_idx].min < 0 || fzn_vars[var_idx].max < 0) {
fprintf(stderr, "\n PHACT can only work with variables whose domains contain only values equal or greater than zero.\n"
" Please apply an offset for the variables domains on your CSP model.\n");
exit(-1);
}
v_id = v_new_range(fzn_vars[var_idx].min, fzn_vars[var_idx].max, fzn_vars[var_idx].to_label);
// alternated values
} else {
for (i = 0; i < fzn_vars[var_idx].next_position; i++) {
if (fzn_vars[var_idx].values[i] < 0) {
fprintf(stderr, "\n PHACT can only work with variables whose domains contain only values equal or greater than zero.\n"
" Please apply an offset to the domains of the variables of your CSP model.\n");
exit(-1);
}
}
v_id = v_new_vals((unsigned int*)fzn_vars[var_idx].values, fzn_vars[var_idx].next_position, fzn_vars[var_idx].to_label);
}
fzn_vars[var_idx].id = v_id;
if (FZN_VERBOSE) {
printf(" with ID %d and label %d\n", v_id, fzn_vars[var_idx].to_label);
}
fzn_vars[var_idx].created = true;
}
}
/*
* Creates a new CSP constraint correspondent to the Flatzinc constraint on index constr_idx from fzn_constrs array
* constr_idx - index in the fzn_constrs array of the Flatzinc constraint to create
*/
void fzn_new_csp_constr(int constr_idx) {
int i;
if (!fzn_constrs[constr_idx].ignore) {
#if FZN_REMOVE_ACHIEVED_CONSTRS
int k;
if (strcmp(fzn_constrs[constr_idx].name, "int_lin_le") == 0
&& fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1] >= 0) {
for (k = 0; k < fzn_constrs[constr_idx].next_const_to_add - 1; k++) {
if (fzn_constrs[constr_idx].consts[k] > 0) {
break;
}
}
if (k == fzn_constrs[constr_idx].next_const_to_add - 1) {
fzn_constrs[constr_idx].ignore = true;
return;
}
}
#endif
// update the variables id from Flatzinc to PHACT
for (i = 0; i < fzn_constrs[constr_idx].next_var_to_add; i++) {
if (fzn_vars[fzn_constrs[constr_idx].vars_id[i]].replace_by_v_id == -1) {
fzn_constrs[constr_idx].vars_id[i] = fzn_vars[fzn_constrs[constr_idx].vars_id[i]].id;
} else {
if (fzn_vars[fzn_vars[fzn_constrs[constr_idx].vars_id[i]].replace_by_v_id].ignore) {
fprintf(stderr, "The %d variable of the constraint \"%s\" (%d) is a replacement variable marked as ignored.\n", i,
fzn_constrs[constr_idx].name, constr_idx);
exit(-1);
}
fzn_constrs[constr_idx].vars_id[i] = fzn_vars[fzn_vars[fzn_constrs[constr_idx].vars_id[i]].replace_by_v_id].id;
}
if (fzn_vars[fzn_constrs[constr_idx].vars_id[i]].ignore && fzn_vars[fzn_constrs[constr_idx].vars_id[i]].replace_by_v_id == -1) {
fprintf(stderr, "The %d variable of the constraint \"%s\" (%d) is marked as ignored and has no replacement.\n", i,
fzn_constrs[constr_idx].name, constr_idx);
exit(-1);
}
}
#if FZN_REMOVE_DUPLICATE_CONSTRS
int j;
if (FZN_VERBOSE)
printf("Checking and removing possible duplicated constraints\n");
for (i = constr_idx + 1; i < fzn_next_constr_posit; i++) {
if (fzn_constrs[constr_idx].next_const_to_add == fzn_constrs[i].next_const_to_add
&& fzn_constrs[constr_idx].next_var_to_add == fzn_constrs[i].next_var_to_add
&& fzn_constrs[i].ignore == false
&& strcmp(fzn_constrs[constr_idx].name, fzn_constrs[i].name) == 0) {
fzn_constrs[i].ignore = true;
for (j = 0; j < fzn_constrs[constr_idx].next_var_to_add; j++) {
if (fzn_constrs[constr_idx].vars_id[j] != fzn_constrs[i].vars_id[j]) {
fzn_constrs[i].ignore = false;
break;
}
}
if (fzn_constrs[i].ignore == true) {
fzn_constrs[i].ignore = false;
if (strcmp(fzn_constrs[constr_idx].name, "int_lin_le") == 0) {
for (j = 0; j < fzn_constrs[constr_idx].next_const_to_add - 1; j++) {
if (fzn_constrs[constr_idx].consts[j] != fzn_constrs[i].consts[j]) {
fzn_constrs[i].ignore = false;
break;
}
}
if (fzn_constrs[i].ignore) {
if (fzn_constrs[constr_idx].consts[j] < fzn_constrs[i].consts[j]) {
fzn_constrs[constr_idx].ignore = false;
fzn_constrs[i].ignore = true;
} else {
fzn_constrs[constr_idx].ignore = true;
fzn_constrs[i].ignore = false;
}
}
|
94b2b13d
Pedro Roque
PHACT source
|
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
|
} else {
for (j = 0; j < fzn_constrs[constr_idx].next_const_to_add; j++) {
if (fzn_constrs[constr_idx].consts[j] != fzn_constrs[i].consts[j]) {
fzn_constrs[i].ignore = false;
break;
}
}
}
}
}
}
#endif
|
4d26a735
Pedro Roque
Increased recogni...
|
2395
|
|
94b2b13d
Pedro Roque
PHACT source
|
2396
2397
2398
2399
2400
2401
2402
|
if (!fzn_constrs[constr_idx].ignore) {
if (strcmp(fzn_constrs[constr_idx].name, "int_lt") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lt (c_lt) with variables %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
|
fzn_constrs[constr_idx].id = c_lt(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_ne") == 0 && fzn_constrs[constr_idx].next_const_to_add == 1) {
if (FZN_VERBOSE)
printf("Deleting value %d from variable %d from int_ne\n", fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[0]);
|
94b2b13d
Pedro Roque
PHACT source
|
2414
2415
2416
2417
2418
2419
2420
|
fzn_constrs[constr_idx].ignore = true;
v_del_val(&VS[fzn_constrs[constr_idx].vars_id[0]], fzn_constrs[constr_idx].consts[0]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_le") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2421
2422
2423
2424
2425
2426
2427
2428
2429
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_le (c_le) with variables %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_le(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
94b2b13d
Pedro Roque
PHACT source
|
2430
2431
|
} else if (strcmp(fzn_constrs[constr_idx].name, "int_le_reif") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2432
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
|
printf("Adding new CSP (%d) int_le_reif (c_le_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_le_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lt_reif") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lt_reif (c_lt_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2446
2447
2448
2449
2450
2451
2452
2453
|
fzn_constrs[constr_idx].id = c_lt_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_ne_reif") == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
2454
2455
2456
2457
2458
2459
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_ne_reif (c_ne_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_ne_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2460
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2461
|
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
4d26a735
Pedro Roque
Increased recogni...
|
2462
|
|
94b2b13d
Pedro Roque
PHACT source
|
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
|
} else if (strcmp(fzn_constrs[constr_idx].name, "int_max") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) constraint int_max (c_max) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_max(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lin_ne") == 0) {
// remove value
if (fzn_constrs[constr_idx].next_var_to_add == 1) {
if (fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] >= 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2481
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2482
|
printf("Deleting value %d from variable %d from int_lin_ne\n", fzn_constrs[constr_idx].consts[1], fzn_constrs[constr_idx].vars_id[0]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2483
|
|
94b2b13d
Pedro Roque
PHACT source
|
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
|
fzn_constrs[constr_idx].ignore = true;
v_del_val(&VS[fzn_constrs[constr_idx].vars_id[0]], fzn_constrs[constr_idx].consts[1]);
} else if (fzn_constrs[constr_idx].next_var_to_add == 1 && fzn_constrs[constr_idx].consts[0] == -1 && fzn_constrs[constr_idx].consts[1] <= 0) {
if (FZN_VERBOSE)
printf("Deleting value %d from variable %d from int_lin_ne\n", abs(fzn_constrs[constr_idx].consts[1]), fzn_constrs[constr_idx].vars_id[0]);
fzn_constrs[constr_idx].ignore = true;
v_del_val(&VS[fzn_constrs[constr_idx].vars_id[0]], abs(fzn_constrs[constr_idx].consts[1]));
|
4d26a735
Pedro Roque
Increased recogni...
|
2495
|
} else {
|
94b2b13d
Pedro Roque
PHACT source
|
2496
2497
|
if (FZN_VERBOSE)
|
4d26a735
Pedro Roque
Increased recogni...
|
2498
2499
2500
2501
2502
2503
2504
2505
|
printf("Adding new CSP (%d) int_lin_ne (c_linear_ne) with constants %d..., variables %d... and result %d", constr_idx,
fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
fzn_constrs[constr_idx].id = c_linear_ne(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2506
2507
2508
2509
2510
2511
|
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
// ne, minus_ne or linear_ne
} else if (fzn_constrs[constr_idx].next_var_to_add == 2) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2512
|
if (fzn_constrs[constr_idx].consts[2] == 0 && ((fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1)
|
94b2b13d
Pedro Roque
PHACT source
|
2513
|
|| (fzn_constrs[constr_idx].consts[0] == -1 && fzn_constrs[constr_idx].consts[1] == 1))) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2514
|
|
94b2b13d
Pedro Roque
PHACT source
|
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_ne (c_ne) with variables %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_ne(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].consts[0] == 1) {
if (fzn_constrs[constr_idx].consts[1] == -1) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2527
2528
2529
2530
2531
2532
2533
2534
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_ne (c_minus_ne) with variables %d and %d and a constant %d", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[2]);
fzn_constrs[constr_idx].id = c_minus_ne(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[2]);
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
|
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].consts[1] == 1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_ne (c_minus_ne) with variables %d and %d and a constant %d ", constr_idx,
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[2]);
fzn_constrs[constr_idx].id = c_minus_ne(fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
2548
|
} else {
|
94b2b13d
Pedro Roque
PHACT source
|
2549
2550
2551
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_ne (c_linear_ne) with constants %d..., variables %d... and result %d", constr_idx,
|
4d26a735
Pedro Roque
Increased recogni...
|
2552
|
fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[0],
|
94b2b13d
Pedro Roque
PHACT source
|
2553
2554
2555
2556
|
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
fzn_constrs[constr_idx].id = c_linear_ne(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2557
|
|
94b2b13d
Pedro Roque
PHACT source
|
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
// linear_ne
} else {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_ne (c_linear_ne) with constants %d..., variables %d... and result %d", constr_idx,
fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
fzn_constrs[constr_idx].id = c_linear_ne(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lin_le") == 0) {
if (fzn_constrs[constr_idx].next_var_to_add == 2 && fzn_constrs[constr_idx].next_const_to_add == 3
&& fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1 && fzn_constrs[constr_idx].consts[2] == -1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_le (c_lt) with variables %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2584
|
fzn_constrs[constr_idx].id = c_lt(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
|
94b2b13d
Pedro Roque
PHACT source
|
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_var_to_add == 2 && fzn_constrs[constr_idx].next_const_to_add == 3
&& fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1 && fzn_constrs[constr_idx].consts[2] == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_le (c_le) with variables %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_le(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else {
if (FZN_VERBOSE)
|
4d26a735
Pedro Roque
Increased recogni...
|
2604
|
printf("Adding new CSP (%d) int_lin_le (c_linear_lt) with constants %d..., variables %d... and result %d", constr_idx,
|
94b2b13d
Pedro Roque
PHACT source
|
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
|
fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
fzn_constrs[constr_idx].id = c_linear_lt(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add] + 1);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lin_le_reif") == 0) {
if (fzn_constrs[constr_idx].next_var_to_add == 3 && fzn_constrs[constr_idx].next_const_to_add == 3
&& fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1 && fzn_constrs[constr_idx].consts[2] == -1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_le_reif (c_lt_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_lt_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_le_reif (c_linear_lt_reif) with constants %d..., variables %d..., result %d and reification variable %d",
constr_idx, fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add],
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
fzn_constrs[constr_idx].id = c_linear_lt_reif(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add - 1,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add - 1] + 1,
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
2644
2645
|
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lin_eq") == 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
|
// check if it is a sum_var constraint
int j = 0;
int minus_idx = 0;
int plus_idx = 0;
int minus_consts = 0;
int plus_consts = 0;
unsigned int* vars_idx = malloc(fzn_constrs[constr_idx].next_const_to_add * sizeof(unsigned int));
for (i = 0; i < fzn_constrs[constr_idx].next_const_to_add; i++) {
if (fzn_constrs[constr_idx].consts[i] == -1) {
minus_idx = i;
minus_consts++;
} else if (fzn_constrs[constr_idx].consts[i] == 1) {
plus_idx = i;
plus_consts++;
}
}
if ((plus_consts + 1 == fzn_constrs[constr_idx].next_const_to_add && fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1] != 1)
|| (plus_consts == fzn_constrs[constr_idx].next_const_to_add)) {
j = 0;
for (i = 0; i < fzn_constrs[constr_idx].next_const_to_add - 1; i++) {
vars_idx[j++] = fzn_constrs[constr_idx].vars_id[i];
}
|
4d26a735
Pedro Roque
Increased recogni...
|
2671
|
|
94b2b13d
Pedro Roque
PHACT source
|
2672
2673
2674
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_sum) with variables %d... and result %d", constr_idx, vars_idx[0],
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1]);
|
4d26a735
Pedro Roque
Increased recogni...
|
2675
|
|
94b2b13d
Pedro Roque
PHACT source
|
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
|
fzn_constrs[constr_idx].id = c_sum(vars_idx, fzn_constrs[constr_idx].next_var_to_add,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (minus_consts + plus_consts + 1 == fzn_constrs[constr_idx].next_const_to_add
&& fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1] == 0 && (minus_consts == 1 || plus_consts == 1)) {
if (minus_consts == 1) {
j = 0;
|
4d26a735
Pedro Roque
Increased recogni...
|
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
|
for (i = 0; i < fzn_constrs[constr_idx].next_const_to_add; i++) {
if (fzn_constrs[constr_idx].consts[i] == 1) {
vars_idx[j++] = fzn_constrs[constr_idx].vars_id[i];
}
}
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_sum_var) with variables %d... and result in variable %d", constr_idx, vars_idx[0],
fzn_constrs[constr_idx].vars_id[minus_idx]);
fzn_constrs[constr_idx].id = c_sum_var(vars_idx, fzn_constrs[constr_idx].next_var_to_add - 1, fzn_constrs[constr_idx].vars_id[minus_idx]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (plus_consts == 1) {
j = 0;
for (i = 0; i < fzn_constrs[constr_idx].next_const_to_add; i++) {
if (fzn_constrs[constr_idx].consts[i] == -1) {
vars_idx[j++] = fzn_constrs[constr_idx].vars_id[i];
}
}
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_sum_var) with variables %d... and result in variable %d", constr_idx, vars_idx[0],
fzn_constrs[constr_idx].vars_id[plus_idx]);
fzn_constrs[constr_idx].id = c_sum_var(vars_idx, fzn_constrs[constr_idx].next_var_to_add - 1, fzn_constrs[constr_idx].vars_id[plus_idx]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
} else if (fzn_constrs[constr_idx].next_var_to_add == 3 && fzn_constrs[constr_idx].next_const_to_add == 4 && fzn_constrs[constr_idx].consts[0] == 1 &&
fzn_constrs[constr_idx].consts[1] == -1 && fzn_constrs[constr_idx].consts[2] == 1 && fzn_constrs[constr_idx].consts[3] == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_var_eq_minus) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_var_eq_minus(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_var_to_add == 3 && fzn_constrs[constr_idx].next_const_to_add == 4 && fzn_constrs[constr_idx].consts[0] == 1
&& fzn_constrs[constr_idx].consts[1] == -1 && fzn_constrs[constr_idx].consts[2] == -1 && fzn_constrs[constr_idx].consts[3] == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_var_eq_minus) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[2],
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_var_eq_minus(fzn_constrs[constr_idx].vars_id[2], fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_var_to_add == 2 && fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_var_eq_minus) with variables %d and %d, and constants %d, %d and %d", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[0],
fzn_constrs[constr_idx].consts[1], fzn_constrs[constr_idx].consts[2]);
fzn_constrs[constr_idx].id = c_minus_eq(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_var_to_add >= 3
|| (fzn_constrs[constr_idx].next_var_to_add == 2 && fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == 1
&& fzn_constrs[constr_idx].consts[2] == 1)) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_linear) with constants %d..., variables %d... and result %d", constr_idx, fzn_constrs[constr_idx].consts[0],
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
fzn_constrs[constr_idx].id = c_linear(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_var_to_add]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_var_to_add == 2 && fzn_constrs[constr_idx].consts[0] > 1 && fzn_constrs[constr_idx].consts[1] == -1
&& fzn_constrs[constr_idx].consts[2] == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq (c_linear) with constant %d, variable %d and variable result %d", constr_idx, fzn_constrs[constr_idx].consts[0],
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_linear_var(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, 1, fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else {
fprintf(stderr, "Type of constraint \"%s\" (%d) not recognized.\n", fzn_constrs[constr_idx].name, constr_idx);
exit(-1);
}
free(vars_idx);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_eq_reif") == 0 && fzn_constrs[constr_idx].next_const_to_add == 1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_eq_reif (c_eq_reif) with variable %d, constant %d and variable %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_eq_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "int_eq_reif") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_eq_reif (c_eq_var_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_eq_var_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "bool_eq_reif") == 0 && fzn_constrs[constr_idx].next_const_to_add == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) bool_eq_reif (c_eq_var_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_eq_var_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
|
94b2b13d
Pedro Roque
PHACT source
|
2818
|
|
4d26a735
Pedro Roque
Increased recogni...
|
2819
|
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2820
|
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
4d26a735
Pedro Roque
Increased recogni...
|
2821
|
|
94b2b13d
Pedro Roque
PHACT source
|
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
|
} else if (strcmp(fzn_constrs[constr_idx].name, "bool_eq_reif") == 0 && fzn_constrs[constr_idx].next_const_to_add == 1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) bool_eq_reif (c_eq_reif) with variable %d, value %d and reification variable %d", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_eq_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "bool2int") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) bool2int (c_bool2int) with variables %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_bool2int(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
4d26a735
Pedro Roque
Increased recogni...
|
2843
2844
2845
2846
2847
2848
2849
2850
2851
|
} else if (strcmp(fzn_constrs[constr_idx].name, "bool_clause") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) bool_clause (c_bool_clause) with variables %d...", constr_idx, fzn_constrs[constr_idx].vars_id[0]);
fzn_constrs[constr_idx].id = c_bool_clause(fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].pos_init_2_array,
&fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].pos_init_2_array],
fzn_constrs[constr_idx].next_var_to_add - fzn_constrs[constr_idx].pos_init_2_array);
|
94b2b13d
Pedro Roque
PHACT source
|
2852
2853
2854
2855
2856
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "array_var_int_element") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2857
2858
2859
2860
2861
2862
2863
2864
2865
|
if (fzn_constrs[constr_idx].next_const_to_add == 1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) array_var_int_element (c_element) with variables %d... and %d and constant %d", constr_idx,
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[0]);
fzn_constrs[constr_idx].id = c_element(&fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].next_var_to_add - 1, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].consts[0]);
|
94b2b13d
Pedro Roque
PHACT source
|
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) array_var_int_element (c_element_var) with variables %d..., %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[1],
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
fzn_constrs[constr_idx].id = c_element_var(&fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].next_var_to_add - 2, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
2882
2883
2884
2885
2886
2887
2888
2889
2890
|
} else if (strcmp(fzn_constrs[constr_idx].name, "array_int_element") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) array_int_element (c_element_int_var) with variables %d and %d and constants %d...", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[0]);
fzn_constrs[constr_idx].id = c_element_int_var(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].next_const_to_add, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1]);
|
94b2b13d
Pedro Roque
PHACT source
|
2891
2892
2893
2894
2895
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "array_bool_or") == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
2896
2897
2898
2899
2900
2901
2902
2903
2904
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) array_bool_or (c_bool_or) with variables %d... and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
fzn_constrs[constr_idx].id = c_bool_or(fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add - 1,
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
2905
2906
2907
2908
2909
2910
|
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (strcmp(fzn_constrs[constr_idx].name, "array_bool_and") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) array_bool_and (c_bool_and) with variables %d... and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
|
4d26a735
Pedro Roque
Increased recogni...
|
2911
2912
2913
2914
2915
2916
2917
2918
|
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
fzn_constrs[constr_idx].id = c_bool_and(fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add - 1,
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
94b2b13d
Pedro Roque
PHACT source
|
2919
2920
2921
2922
2923
2924
|
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lin_ne_reif") == 0) {
// check if its a "ne" reified constraint
if (fzn_constrs[constr_idx].next_var_to_add == 3 && fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1
&& fzn_constrs[constr_idx].consts[2] == 0) {
if (FZN_VERBOSE)
|
4d26a735
Pedro Roque
Increased recogni...
|
2925
2926
|
printf("Adding new CSP (%d) int_lin_ne_reif (c_ne_reif) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
|
94b2b13d
Pedro Roque
PHACT source
|
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
|
fzn_constrs[constr_idx].id = c_ne_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_var_to_add > 3) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_ne_reif (c_linear_ne) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_linear_ne_reif(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id,
fzn_constrs[constr_idx].next_var_to_add - 1, fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1],
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else {
fprintf(stderr, "Constraint \"%s\" (%d) not recognized.\n", fzn_constrs[constr_idx].name, constr_idx);
exit(-1);
}
} else if (strcmp(fzn_constrs[constr_idx].name, "int_lin_eq_reif") == 0) {
// check if it is a sum_var constraint
int j = 0;
int plus_consts = 0;
unsigned int* vars_idx = malloc(fzn_constrs[constr_idx].next_const_to_add * sizeof(unsigned int));
for (i = 0; i < fzn_constrs[constr_idx].next_const_to_add; i++) {
if (fzn_constrs[constr_idx].consts[i] == 1) {
plus_consts++;
}
}
if ((plus_consts + 1 == fzn_constrs[constr_idx].next_const_to_add && fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1] != 1)
|| (plus_consts == fzn_constrs[constr_idx].next_const_to_add)) {
j = 0;
for (i = 0; i < fzn_constrs[constr_idx].next_const_to_add - 1; i++) {
vars_idx[j++] = fzn_constrs[constr_idx].vars_id[i];
}
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq_reif (c_sum_reif) with variables %d..., reification variable %d and result %d", constr_idx, vars_idx[0],
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1],
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1]);
fzn_constrs[constr_idx].id = c_sum_reif(vars_idx, fzn_constrs[constr_idx].next_var_to_add - 1,
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1],
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_const_to_add == 2 && fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] >= 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq_reif (c_eq_reif) with variable %d, constant %d and reification variable %d", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[1], fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_eq_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[1], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_const_to_add == 2 && fzn_constrs[constr_idx].consts[0] == -1 && fzn_constrs[constr_idx].consts[1] <= 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq_reif (c_eq_reif) with variable %d, constant %d and reification variable %d", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[1] * (-1), fzn_constrs[constr_idx].vars_id[1]);
fzn_constrs[constr_idx].id = c_eq_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[1] * (-1), fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else if (fzn_constrs[constr_idx].next_const_to_add == 3 && fzn_constrs[constr_idx].next_var_to_add == 3
&& fzn_constrs[constr_idx].consts[0] == 1 && fzn_constrs[constr_idx].consts[1] == -1) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq_reif (c_minus_eq_reif) with variable %d and %d, constant %d and reification variable %d", constr_idx,
|
4d26a735
Pedro Roque
Increased recogni...
|
3011
|
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[2], fzn_constrs[constr_idx].vars_id[2]);
|
94b2b13d
Pedro Roque
PHACT source
|
3012
|
|
4d26a735
Pedro Roque
Increased recogni...
|
3013
3014
|
fzn_constrs[constr_idx].id = c_minus_eq_reif(fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].consts[2],
fzn_constrs[constr_idx].vars_id[2]);
|
94b2b13d
Pedro Roque
PHACT source
|
3015
|
|
4d26a735
Pedro Roque
Increased recogni...
|
3016
3017
3018
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
94b2b13d
Pedro Roque
PHACT source
|
3019
|
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
3020
3021
3022
3023
|
if (FZN_VERBOSE)
printf("Adding new CSP (%d) int_lin_eq_reif (c_linear_reif) with variables %d..., constants %d..., result %d and reification variable %d", constr_idx,
fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].consts[0],
|
94b2b13d
Pedro Roque
PHACT source
|
3024
|
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1],
|
4d26a735
Pedro Roque
Increased recogni...
|
3025
3026
|
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
|
94b2b13d
Pedro Roque
PHACT source
|
3027
|
fzn_constrs[constr_idx].id = c_linear_reif(fzn_constrs[constr_idx].consts, fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add - 1,
|
4d26a735
Pedro Roque
Increased recogni...
|
3028
|
fzn_constrs[constr_idx].consts[fzn_constrs[constr_idx].next_const_to_add - 1],
|
94b2b13d
Pedro Roque
PHACT source
|
3029
|
fzn_constrs[constr_idx].vars_id[fzn_constrs[constr_idx].next_var_to_add - 1]);
|
4d26a735
Pedro Roque
Increased recogni...
|
3030
3031
3032
3033
3034
3035
3036
3037
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
}
} else if (strcmp(fzn_constrs[constr_idx].name, "int_times") == 0) {
if (FZN_VERBOSE)
|
94b2b13d
Pedro Roque
PHACT source
|
3038
|
printf("Adding new CSP (%d) int_times (c_var_eq_times) with variables %d, %d and %d", constr_idx, fzn_constrs[constr_idx].vars_id[0],
|
4d26a735
Pedro Roque
Increased recogni...
|
3039
3040
3041
3042
3043
3044
|
fzn_constrs[constr_idx].vars_id[1], fzn_constrs[constr_idx].vars_id[2]);
fzn_constrs[constr_idx].id = c_var_eq_times(fzn_constrs[constr_idx].vars_id[2], fzn_constrs[constr_idx].vars_id[0], fzn_constrs[constr_idx].vars_id[1]);
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
|
94b2b13d
Pedro Roque
PHACT source
|
3045
|
|
4d26a735
Pedro Roque
Increased recogni...
|
3046
3047
3048
3049
3050
3051
|
} else if (strcmp(fzn_constrs[constr_idx].name, "all_different") == 0) {
if (FZN_VERBOSE)
printf("Adding new CSP (%d) all_different (c_all_different) with variables %d...", constr_idx, fzn_constrs[constr_idx].vars_id[0]);
fzn_constrs[constr_idx].id = c_all_different(fzn_constrs[constr_idx].vars_id, fzn_constrs[constr_idx].next_var_to_add);
|
94b2b13d
Pedro Roque
PHACT source
|
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
|
if (FZN_VERBOSE)
printf(" as constraint number %d\n",fzn_constrs[constr_idx].id);
} else {
fprintf(stderr, "Constraint \"%s\" (%d) not recognized when creating CSP constraint.\n", fzn_constrs[constr_idx].name, constr_idx);
exit(-1);
}
}
}
}
/*
* Print the model from the FlatZinc file as interpreted by the interpreter
*/
void fzn_print_csp() {
int i, j;
printf("\n\n--------------------------------\n");
printf("CSP as loaded by the Flatzinc interpreter:\n");
for (i = 0; i < fzn_next_array_posit; i++) {
if (!fzn_arrays[i].output_array && !fzn_arrays[i].output_var && !fzn_arrays[i].is_defined_var && !fzn_arrays[i].var_array) {
printf(" - Array %s, values={", fzn_arrays[i].name);
for (j = 0; j < fzn_arrays[i].next_position - 1; j++) {
printf("%d,", fzn_arrays[i].values[j]);
}
printf("%d}\n", fzn_arrays[i].values[j]);
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3085
|
|
94b2b13d
Pedro Roque
PHACT source
|
3086
3087
3088
3089
|
for (i = 0; i < fzn_next_var_posit; i++) {
printf(" - Variable");
if (fzn_vars[i].name != NULL) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3090
|
printf(" %s", fzn_vars[i].name);
|
94b2b13d
Pedro Roque
PHACT source
|
3091
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3092
3093
3094
3095
3096
3097
3098
|
printf(", domain={");
if (fzn_vars[i].range == true) {
printf("%d..%d}", fzn_vars[i].min, fzn_vars[i].max);
} else {
for (j = 0; j < fzn_vars[i].next_position - 1; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
3099
3100
|
printf("%d,", fzn_vars[i].values[j]);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3101
|
printf("%d}", fzn_vars[i].values[j]);
|
94b2b13d
Pedro Roque
PHACT source
|
3102
3103
3104
|
}
if (fzn_vars[i].output_var) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3105
|
printf(", output_var");
|
94b2b13d
Pedro Roque
PHACT source
|
3106
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3107
3108
3109
3110
3111
3112
3113
|
if (fzn_vars[i].var_is_introduced) {
printf(", var_is_introduced");
}
if (fzn_vars[i].is_defined_var) {
printf(", is_defined_var");
}
printf("\n");
|
94b2b13d
Pedro Roque
PHACT source
|
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
|
}
for (i = 0; i < fzn_next_array_posit; i++) {
if (fzn_arrays[i].output_array) {
printf(" - Array %s, output_array", fzn_arrays[i].name);
if (fzn_arrays[i].var_array) {
printf(", variables={");
for (j = 0; j < fzn_arrays[i].next_position - 1; j++) {
if (fzn_vars[fzn_arrays[i].values[j]].name != NULL) {
printf("%s,", fzn_vars[fzn_arrays[i].values[j]].name);
} else {
printf("%d,", fzn_vars[fzn_arrays[i].values[j]].min);
}
}
if (fzn_vars[fzn_arrays[i].values[j]].name != NULL) {
printf("%s}\n", fzn_vars[fzn_arrays[i].values[j]].name);
} else {
printf("%d}\n", fzn_vars[fzn_arrays[i].values[j]].min);
}
} else {
printf(", values={");
for (j = 0; j < fzn_arrays[i].next_position - 1; j++) {
printf("%d,", fzn_arrays[i].values[j]);
}
printf("%d}\n", fzn_arrays[i].values[j]);
}
}
}
for (i = 0; i < fzn_next_array_posit; i++) {
if (!fzn_arrays[i].output_array && !fzn_arrays[i].output_var && !fzn_arrays[i].is_defined_var && fzn_arrays[i].var_array) {
printf(" - Array %s, variables={", fzn_arrays[i].name);
for (j = 0; j < fzn_arrays[i].next_position - 1; j++) {
if (fzn_vars[fzn_arrays[i].values[j]].name != NULL) {
printf("%s,", fzn_vars[fzn_arrays[i].values[j]].name);
} else {
printf("%d,", fzn_vars[fzn_arrays[i].values[j]].min);
}
}
if (fzn_vars[fzn_arrays[i].values[j]].name != NULL) {
printf("%s}\n", fzn_vars[fzn_arrays[i].values[j]].name);
} else {
printf("%d}\n", fzn_vars[fzn_arrays[i].values[j]].min);
}
}
}
for (i = 0; i < fzn_next_constr_posit; i++) {
printf(" - Constraint %s", fzn_constrs[i].name);
if (fzn_constrs[i].next_const_to_add > 0) {
printf(", values={");
for (j = 0; j < fzn_constrs[i].next_const_to_add - 1; j++) {
printf("%d,", fzn_constrs[i].consts[j]);
}
printf("%d}", fzn_constrs[i].consts[j]);
}
if (fzn_constrs[i].next_var_to_add > 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3181
|
printf(", variables={");
|
94b2b13d
Pedro Roque
PHACT source
|
3182
3183
|
for (j = 0; j < fzn_constrs[i].next_var_to_add - 1; j++) {
if (fzn_vars[fzn_constrs[i].vars_id[j]].name != NULL) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3184
|
printf("%s,", fzn_vars[fzn_constrs[i].vars_id[j]].name);
|
94b2b13d
Pedro Roque
PHACT source
|
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
|
} else {
printf("%d,", fzn_vars[fzn_constrs[i].vars_id[j]].min);
}
}
if (fzn_vars[fzn_constrs[i].vars_id[j]].name != NULL) {
printf("%s}", fzn_vars[fzn_constrs[i].vars_id[j]].name);
} else {
printf("%d}", fzn_vars[fzn_constrs[i].vars_id[j]].min);
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
|
if (fzn_constrs[i].boundsD != false) {
printf(", boundsD");
}
if (fzn_constrs[i].boundsZ != false) {
printf(", boundsZ");
}
if (fzn_constrs[i].boundsR != false) {
printf(", boundsR");
}
if (fzn_constrs[i].domain != false) {
printf(", domain");
|
94b2b13d
Pedro Roque
PHACT source
|
3207
3208
3209
3210
|
}
if (fzn_constrs[i].priority != false) {
printf(", priority(%d)", fzn_constrs[i].priority_v_id);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3211
3212
3213
3214
3215
3216
3217
|
if (fzn_constrs[i].defines_var_idx != -1) {
printf(", defines_var(%s)", fzn_vars[fzn_constrs[i].defines_var_idx].name);
}
printf("\n");
}
|
94b2b13d
Pedro Roque
PHACT source
|
3218
|
// if any search annotation
|
4d26a735
Pedro Roque
Increased recogni...
|
3219
|
if (fzn_next_search_annot_posit > 0) {
|
94b2b13d
Pedro Roque
PHACT source
|
3220
3221
|
if (fzn_next_search_annot_posit > 1) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
|
printf(" - solve seq_search:\n");
for (i = 0; i < fzn_next_search_annot_posit; i++) {
printf(" - %s(%s, %s, %s, %s)", fzn_search_annot[i].search_type, fzn_search_annot[i].label_array_name, fzn_search_annot[i].label_heur
, fzn_search_annot[i].assign_heur, fzn_search_annot[i].search_strategy);
if (i < fzn_next_search_annot_posit) {
printf("\n");
}
}
if (FZN_OPTIMIZE == FZN_MINIMIZE) {
printf(" - minimize %s\n", fzn_vars[optimize_var_idx].name);
} else if (FZN_OPTIMIZE == FZN_MAXIMIZE) {
printf(" - maximize %s\n", fzn_vars[optimize_var_idx].name);
} else {
printf(" - satisfy");
}
} else {
printf(" - solve %s(%s, %s, %s, %s)", fzn_search_annot[0].search_type, fzn_search_annot[0].label_array_name, fzn_search_annot[0].label_heur
, fzn_search_annot[0].assign_heur, fzn_search_annot[0].search_strategy);
if (FZN_OPTIMIZE == FZN_MINIMIZE) {
printf(" minimize %s\n", fzn_vars[optimize_var_idx].name);
} else if (FZN_OPTIMIZE == FZN_MAXIMIZE) {
printf(" maximize %s\n", fzn_vars[optimize_var_idx].name);
|
94b2b13d
Pedro Roque
PHACT source
|
3251
3252
3253
3254
3255
|
} else {
printf(" satisfy");
}
}
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
3256
|
printf(" - solve satisfy");
|
94b2b13d
Pedro Roque
PHACT source
|
3257
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3258
3259
|
printf("\n");
printf("--------------------------------\n\n");
|
94b2b13d
Pedro Roque
PHACT source
|
3260
3261
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
|
/*
* Prints each variable and constraint, one by one, from FZN to PHACT representations
*/
void fzn_map_fzn2phact() {
int prev_val, new_val, cntr, phact_id;
int fzn_id = 0;
int i, j, k;
printf("\nVariables:\n");
for (i = 0; i < fzn_next_var_posit; i++) {
phact_id = fzn_vars[i].id;
if (fzn_vars[i].name != NULL) {
printf(" - %d -> %s -> ", i, fzn_vars[i].name);
} else {
printf(" - %d -> ", i);
}
if (!fzn_vars[i].ignore) {
printf("%d:\n", phact_id);
} else {
printf("ignored\n");
}
printf(" - FZN");
if (fzn_vars[i].name != NULL) {
printf(" %s", fzn_vars[i].name);
}
printf(", domain={");
if (fzn_vars[i].range == true) {
|
94b2b13d
Pedro Roque
PHACT source
|
3299
3300
3301
3302
3303
3304
3305
|
printf("%d..%d}", fzn_vars[i].min, fzn_vars[i].max);
} else {
for (j = 0; j < fzn_vars[i].next_position - 1; j++) {
printf("%d,", fzn_vars[i].values[j]);
}
printf("%d}", fzn_vars[i].values[j]);
|
4d26a735
Pedro Roque
Increased recogni...
|
3306
3307
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
3308
3309
|
if (fzn_vars[i].output_var) {
printf(", output_var");
|
4d26a735
Pedro Roque
Increased recogni...
|
3310
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
3311
3312
3313
3314
3315
3316
3317
|
if (fzn_vars[i].var_is_introduced) {
printf(", var_is_introduced");
}
if (fzn_vars[i].is_defined_var) {
printf(", is_defined_var");
}
printf("\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
3318
3319
|
if (!fzn_vars[i].ignore) {
|
94b2b13d
Pedro Roque
PHACT source
|
3320
3321
|
printf(" - PHACT ID=%u: Values={", VS[phact_id].v_id);
|
4d26a735
Pedro Roque
Increased recogni...
|
3322
|
|
94b2b13d
Pedro Roque
PHACT source
|
3323
3324
3325
3326
|
j = 1;
prev_val = b_get_nth_val(&VS[phact_id].domain_b, j++);
new_val = prev_val;
printf("%u", prev_val);
|
4d26a735
Pedro Roque
Increased recogni...
|
3327
3328
3329
3330
3331
3332
3333
3334
|
while (new_val < VS[phact_id].max) {
cntr = 0;
while ((new_val = b_get_nth_val(&VS[phact_id].domain_b, j++)) == prev_val + 1 && new_val < VS[phact_id].max) {
prev_val = new_val;
cntr++;
}
|
94b2b13d
Pedro Roque
PHACT source
|
3335
|
if (cntr == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3336
|
printf(",%u", new_val);
|
94b2b13d
Pedro Roque
PHACT source
|
3337
3338
|
} else {
if (new_val == VS[phact_id].max && new_val == prev_val + 1) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3339
3340
3341
3342
3343
3344
3345
3346
|
printf("-%u", new_val);
} else if (cntr == 1) {
printf(",%u,%u", prev_val, new_val);
} else {
printf("-%u,%u", prev_val, new_val);
}
}
prev_val = new_val;
|
94b2b13d
Pedro Roque
PHACT source
|
3347
3348
3349
3350
3351
3352
3353
3354
3355
|
}
if (VS[phact_id].to_label) {
printf("} Label=true");
} else {
printf("} Label=false");
}
if (VS[phact_id].n_cs > 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3356
3357
|
printf(" Constraints={");
for (j = 0; j < VS[phact_id].n_cs - 1; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
3358
3359
3360
3361
|
printf("%u,", VS[phact_id].cs[j]->c_id);
}
if (VS[phact_id].n_cs > 0) {
printf("%u}\n", VS[phact_id].cs[j]->c_id);
|
4d26a735
Pedro Roque
Increased recogni...
|
3362
3363
|
} else {
printf("\n");
|
94b2b13d
Pedro Roque
PHACT source
|
3364
3365
|
}
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
3366
3367
|
printf("\n");
}
|
94b2b13d
Pedro Roque
PHACT source
|
3368
3369
3370
3371
3372
3373
3374
|
} else {
printf(" - PHACT -> ignored\n");
}
}
printf("\nConstraints:\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
3375
|
|
94b2b13d
Pedro Roque
PHACT source
|
3376
3377
3378
|
for (i = 0; i < fzn_next_constr_posit; i++) {
phact_id = fzn_constrs[i].id;
|
4d26a735
Pedro Roque
Increased recogni...
|
3379
3380
|
if (fzn_constrs[i].name != NULL) {
|
94b2b13d
Pedro Roque
PHACT source
|
3381
3382
3383
|
printf(" - %d -> %s -> ", i, fzn_constrs[i].name);
} else {
printf(" - %d -> ", i);
|
4d26a735
Pedro Roque
Increased recogni...
|
3384
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
3385
3386
|
if (!fzn_constrs[i].ignore) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3387
|
printf("%d:\n", phact_id);
|
94b2b13d
Pedro Roque
PHACT source
|
3388
3389
|
} else {
printf(" ignored:\n");
|
4d26a735
Pedro Roque
Increased recogni...
|
3390
3391
3392
|
}
printf(" - FZN");
|
94b2b13d
Pedro Roque
PHACT source
|
3393
3394
3395
3396
3397
|
printf(" - Constraint %s", fzn_constrs[i].name);
if (fzn_constrs[i].next_const_to_add > 0) {
printf(", values={");
|
4d26a735
Pedro Roque
Increased recogni...
|
3398
|
for (j = 0; j < fzn_constrs[i].next_const_to_add - 1; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
3399
3400
|
printf("%d,", fzn_constrs[i].consts[j]);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3401
|
printf("%d}", fzn_constrs[i].consts[j]);
|
94b2b13d
Pedro Roque
PHACT source
|
3402
3403
3404
3405
3406
3407
3408
3409
3410
|
}
if (fzn_constrs[i].next_var_to_add > 0) {
printf(", variables={");
for (j = 0; j < fzn_constrs[i].next_var_to_add - 1; j++) {
phact_id = fzn_constrs[i].vars_id[j];
for (k = 0; k < fzn_next_var_posit; k++) {
if (fzn_vars[k].id == (unsigned int)phact_id) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3411
3412
|
phact_id = fzn_vars[k].id;
fzn_id = k;
|
94b2b13d
Pedro Roque
PHACT source
|
3413
3414
|
break;
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3415
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
3416
3417
3418
3419
3420
3421
3422
|
if (fzn_vars[fzn_id].name != NULL) {
printf("%s (%d),", fzn_vars[fzn_id].name, fzn_vars[fzn_id].id);
} else {
printf("\"\" (%d),", fzn_vars[fzn_id].id);
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3423
3424
|
phact_id = fzn_constrs[i].vars_id[j];
|
94b2b13d
Pedro Roque
PHACT source
|
3425
3426
|
for (k = 0; k < fzn_next_var_posit; k++) {
if (fzn_vars[k].id == (unsigned int)phact_id) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3427
|
phact_id = fzn_vars[k].id;
|
94b2b13d
Pedro Roque
PHACT source
|
3428
3429
3430
3431
|
fzn_id = k;
break;
}
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3432
|
|
94b2b13d
Pedro Roque
PHACT source
|
3433
3434
3435
|
if (fzn_vars[fzn_id].name != NULL) {
printf("%s (%d)}", fzn_vars[fzn_id].name, fzn_vars[fzn_id].id);
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
3436
3437
|
printf("\"\" (%d)}", fzn_vars[fzn_id].id);
}
|
94b2b13d
Pedro Roque
PHACT source
|
3438
3439
3440
|
}
if (fzn_constrs[i].boundsD != false) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3441
|
printf(", boundsD");
|
94b2b13d
Pedro Roque
PHACT source
|
3442
|
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3443
|
if (fzn_constrs[i].boundsZ != false) {
|
94b2b13d
Pedro Roque
PHACT source
|
3444
3445
3446
|
printf(", boundsZ");
}
if (fzn_constrs[i].boundsR != false) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3447
|
printf(", boundsR");
|
94b2b13d
Pedro Roque
PHACT source
|
3448
3449
3450
|
}
if (fzn_constrs[i].domain != false) {
printf(", domain");
|
4d26a735
Pedro Roque
Increased recogni...
|
3451
3452
|
}
if (fzn_constrs[i].priority != false) {
|
94b2b13d
Pedro Roque
PHACT source
|
3453
3454
|
printf(", priority(%d)", fzn_constrs[i].priority_v_id);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3455
|
|
94b2b13d
Pedro Roque
PHACT source
|
3456
3457
3458
|
if (fzn_constrs[i].defines_var_idx != -1) {
printf(", defines_var(%s)", fzn_vars[fzn_constrs[i].defines_var_idx].name);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3459
3460
|
printf("\n");
|
94b2b13d
Pedro Roque
PHACT source
|
3461
3462
3463
3464
3465
|
if (!fzn_constrs[i].ignore) {
phact_id = fzn_constrs[i].id;
printf(" - PHACT ID=%u: Type=", CS[phact_id].c_id);
cs_print_type(&CS[phact_id]);
|
4d26a735
Pedro Roque
Increased recogni...
|
3466
|
printf(" Variables={");
|
94b2b13d
Pedro Roque
PHACT source
|
3467
3468
|
for (j = 0; j < CS[phact_id].n_c_vs - 1; j++) {
printf("%u,", CS[phact_id].c_vs[j]->v_id);
|
4d26a735
Pedro Roque
Increased recogni...
|
3469
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
3470
3471
3472
3473
3474
3475
3476
3477
|
printf("%u}", CS[phact_id].c_vs[j]->v_id);
if (CS[phact_id].n_c_consts > 0) {
printf(" Constants={");
for (j = 0; j < CS[phact_id].n_c_consts - 1; j++) {
printf("%d,", CS[phact_id].c_consts[j]);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3478
|
if (CS[phact_id].kind == LINEAR || CS[phact_id].kind == LINEAR_NE || CS[phact_id].kind == LINEAR_LT) {
|
94b2b13d
Pedro Roque
PHACT source
|
3479
3480
|
printf("%d, %d}", CS[phact_id].c_consts[j], CS[phact_id].constant_val);
|
4d26a735
Pedro Roque
Increased recogni...
|
3481
|
} else {
|
94b2b13d
Pedro Roque
PHACT source
|
3482
3483
|
printf("%d}", CS[phact_id].c_consts[j]);
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3484
3485
|
} else if (CS[phact_id].kind == ELEMENT || CS[phact_id].kind == EXACTLY_VAR || CS[phact_id].kind == LINEAR || CS[phact_id].kind == LINEAR_NE
|
94b2b13d
Pedro Roque
PHACT source
|
3486
|
|| CS[phact_id].kind == MINUS_EQ || CS[phact_id].kind == MINUS_NE || CS[phact_id].kind == SUM_PROD || CS[phact_id].kind == SUM
|
4d26a735
Pedro Roque
Increased recogni...
|
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
|
|| CS[phact_id].kind == LINEAR_LT || CS[phact_id].kind == ELEMENT_INT_VAR || CS[phact_id].kind == EQ) {
printf(" Constants={%d}", CS[phact_id].constant_val);
}
if (CS[phact_id].reified) {
printf(" reif_var_ID=%u\n", CS[phact_id].reif_v_id);
} else {
printf("\n");
}
} else {
printf(" - PHACT -> ignored\n");
}
}
}
|
94b2b13d
Pedro Roque
PHACT source
|
3502
3503
|
/*
|
4d26a735
Pedro Roque
Increased recogni...
|
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
|
* Initialize the annotation for CSP solving
*/
void fzn_init_search_annots() {
int i;
bool more = false;
if (fzn_next_search_annot_posit > 1) {
printf("\nCurrent FlatZinc model uses seq_search with multiple heuristics.\n"
"PHACT can only use one heuristic for labeling and another for value assignment.\n"
"As such, it will join all the variables/arrays identified as the ones for labeling,\n"
"but only the first introduced heuristic for labeling and the first introduced heuristic\n"
|
94b2b13d
Pedro Roque
PHACT source
|
3515
3516
|
"for assignment will be used.\n\n");
}
|
4d26a735
Pedro Roque
Increased recogni...
|
3517
|
|
94b2b13d
Pedro Roque
PHACT source
|
3518
3519
|
printf("Search annotation with \"[");
|
4d26a735
Pedro Roque
Increased recogni...
|
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
|
for (i = 0; i < fzn_next_search_annot_posit; i++) {
fzn_set_var_or_array_to_label(fzn_search_annot[i].label_array_name);
if (more) {
printf(", ");
}
printf("%s", fzn_search_annot[i].label_array_name);
more = true;
}
printf("], %s, %s, %s", fzn_search_annot[0].label_heur , fzn_search_annot[0].assign_heur , fzn_search_annot[0].search_strategy);
if (WORK == DEFAULT_W) {
if (FZN_OPTIMIZE == FZN_MINIMIZE) {
printf(", minimize %s\"", fzn_vars[optimize_var_idx].name);
} else if (FZN_OPTIMIZE == FZN_MAXIMIZE) {
printf(", maximize %s\"", fzn_vars[optimize_var_idx].name);
} else {
printf("\"");
}
} else {
printf("\"");
}
printf("\n\n");
|
94b2b13d
Pedro Roque
PHACT source
|
3547
|
// label heuristic
|
4d26a735
Pedro Roque
Increased recogni...
|
3548
3549
|
if (strcmp("input_order", fzn_search_annot[0].label_heur) == 0) {
LABEL_MODE = INPUT_ORDER;
|
94b2b13d
Pedro Roque
PHACT source
|
3550
3551
3552
3553
3554
|
} else if (strcmp("occurrence", fzn_search_annot[0].label_heur) == 0) {
LABEL_MODE = OCCURRENCE;
} else if (strcmp("first_fail", fzn_search_annot[0].label_heur) == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3555
3556
|
LABEL_MODE = FIRST_FAIL;
|
94b2b13d
Pedro Roque
PHACT source
|
3557
3558
|
} /*else if (strcmp("max_regret", fzn_search_annot[0].label_heur) == 0) {
LABEL_MODE = MAX_REGRET;
|
4d26a735
Pedro Roque
Increased recogni...
|
3559
|
|
94b2b13d
Pedro Roque
PHACT source
|
3560
3561
|
} else if (strcmp("smallest", fzn_search_annot[0].label_heur) == 0) {
LABEL_MODE = SMALLEST;
|
4d26a735
Pedro Roque
Increased recogni...
|
3562
|
|
94b2b13d
Pedro Roque
PHACT source
|
3563
|
}*/ else {
|
4d26a735
Pedro Roque
Increased recogni...
|
3564
3565
3566
3567
3568
3569
|
LABEL_MODE = INPUT_ORDER;
printf("The %s heuristic for labeling is not implemented. Using default heuristic (INPUT_ORDER).\n", fzn_search_annot[0].label_heur);
}
// assignment heuristic
|
94b2b13d
Pedro Roque
PHACT source
|
3570
|
if (strcmp("indomain_min", fzn_search_annot[0].assign_heur) == 0) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
|
ASSIGN_MODE = MIN_VAL;
} else if (strcmp("indomain_max", fzn_search_annot[0].assign_heur) == 0) {
ASSIGN_MODE = MAX_VAL;
} else if (strcmp("indomain_split", fzn_search_annot[0].assign_heur) == 0) {
ASSIGN_MODE = SPLIT_VALS;
} else {
ASSIGN_MODE = MIN_VAL;
printf("The %s heuristic for value selection is not implemented. Using default heuristic (MIN_VAL).\n", fzn_search_annot[0].assign_heur);
}
if (strcmp("complete", fzn_search_annot[0].search_strategy) != 0) {
fprintf(stderr, "%s search strategy not implemented.\n", fzn_search_annot[0].search_strategy);
exit(-1);
}
}
/*
* Print the number of variables, constraints, types of constraints and maximum domain value of the FlatZinc model
*/
void fzn_print_stats() {
char constraints_name[100][30]; // values higher than the ones in FlatZinc specification
int cs_ctr = 0;
|
94b2b13d
Pedro Roque
PHACT source
|
3598
3599
|
int max_dom = 0;
int i, j;
|
4d26a735
Pedro Roque
Increased recogni...
|
3600
|
|
94b2b13d
Pedro Roque
PHACT source
|
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
|
printf("\nFlatZinc model statistics:\n");
printf(" - Number of variables: %d\n", fzn_next_var_posit);
for (i = 0; i < fzn_next_var_posit; i++) {
if (fzn_vars[i].range == true && fzn_vars[i].max > max_dom) {
max_dom = fzn_vars[i].max;
} else {
|
4d26a735
Pedro Roque
Increased recogni...
|
3611
|
for (j = 0; j < fzn_vars[i].next_position - 1; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
|
if (fzn_vars[i].values[j] > max_dom) {
max_dom = fzn_vars[i].values[j];
}
}
}
}
printf(" - Maximum domain value: %d\n", max_dom);
printf(" - Number of constraints: %d\n", fzn_next_constr_posit);
for (i = 0; i < fzn_next_constr_posit; i++) {
|
4d26a735
Pedro Roque
Increased recogni...
|
3623
3624
|
for (j = 0; j < cs_ctr; j++) {
|
94b2b13d
Pedro Roque
PHACT source
|
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
|
if (strcmp(fzn_constrs[i].name, constraints_name[j]) == 0) {
break;
}
}
if (j == cs_ctr) {
strcpy(constraints_name[cs_ctr++], fzn_constrs[i].name);
}
}
printf(" - Types of constraints: %d\n", cs_ctr);
|
4d26a735
Pedro Roque
Increased recogni...
|
3636
|
}
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|
94b2b13d
Pedro Roque
PHACT source
|
|
|
4d26a735
Pedro Roque
Increased recogni...
|
|
|