Blame view

Debug/src/constraints/bool_and.c 19 KB
0c8ce2b0   Pedro Roque   missing files
1
2
3
/*
 * bool_and.c
 *
4d26a735   Pedro Roque   Increased recogni...
4
5
 *  Created on: 11/02/2020
 *      Author: Pedro
0c8ce2b0   Pedro Roque   missing files
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 */

#ifndef __OPENCL_VERSION__

#include <stddef.h>
#include <stdio.h>

#include "bool_and.h"

#include "../bitmaps.h"
#include "../config.h"
#include "../variables.h"

#endif

#include "../kernels/cl_aux_functions.h"
#if CL_D_TYPE == CL_BITMAP
#include "../kernels/cl_bitmaps.h"
#elif CL_D_TYPE == CL_INTERVAL
#include  "../kernels/cl_intervals.h"
#endif
#include "../kernels/cl_constraints.h"
#include "../kernels/cl_variables.h"
#include "../kernels/cl_ttl.h"

#ifndef __OPENCL_VERSION__

/*
 * Creates a new constraint of the type bool_and and return the constraint ID
4d26a735   Pedro Roque   Increased recogni...
35
36
37
38
 * (x & y) ↔ z
 * x_id - boolean variable
 * y_id - boolean variable
 * z_id - boolean variable whose assignment is the result of the binary AND between x and y variables
0c8ce2b0   Pedro Roque   missing files
39
 */
4d26a735   Pedro Roque   Increased recogni...
40
unsigned int c_bool_and(unsigned int x_id, unsigned int y_id, unsigned int z_id) {
0c8ce2b0   Pedro Roque   missing files
41

4d26a735   Pedro Roque   Increased recogni...
42
43
	if (VS[x_id].max > 1) {
		v_del_gt(&VS[x_id], 1);
0c8ce2b0   Pedro Roque   missing files
44

4d26a735   Pedro Roque   Increased recogni...
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
		if (VS[x_id].n_vals == 0) {
			printf("\nConstraint BOOL_AND makes model inconsistent at creation. No solution found.\n");

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif

			exit(0);
		}
	}
	if (VS[y_id].max > 1) {
		v_del_gt(&VS[y_id], 1);

		if (VS[y_id].n_vals == 0) {
			printf("\nConstraint BOOL_AND makes model inconsistent at creation. No solution found.\n");

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif

			exit(0);
		}
	}
	if (VS[z_id].max > 1) {
		v_del_gt(&VS[z_id], 1);

		if (VS[z_id].n_vals == 0) {
			printf("\nConstraint BOOL_AND makes model inconsistent at creation. No solution found.\n");

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif

			exit(0);
0c8ce2b0   Pedro Roque   missing files
82
83
84
85
86
87
88
89
		}
	}

	// set to include in kernel compilation
	USE_CS[BOOL_AND] = 1;
	USE_NON_CS_REIFI[BOOL_AND] = 1;
	REV = 1;

4d26a735   Pedro Roque   Increased recogni...
90
91
92
93
	unsigned int c_vs[3];
	c_vs[0] = x_id;
	c_vs[1] = y_id;
	c_vs[2] = z_id;
0c8ce2b0   Pedro Roque   missing files
94
95

	// creates a new generic constraint
4d26a735   Pedro Roque   Increased recogni...
96
	unsigned int c_id = c_new(c_vs, 3, NULL, 0, -1);
0c8ce2b0   Pedro Roque   missing files
97
98
99
100
101
102

	// pointers to this type of constraint functions
	CS[c_id].kind = BOOL_AND;
	CS[c_id].check_sol_f = &bool_and_check;
	CS[c_id].constant_val = 0;

0c8ce2b0   Pedro Roque   missing files
103
104
105
106
107
	return c_id;
}

/*
 * Creates a new reified constraint of the bool_and type
4d26a735   Pedro Roque   Increased recogni...
108
109
110
111
 * (x & y) ↔ z
 * x_id - boolean variable
 * y_id - boolean variable
 * z_id - boolean variable whose assignment is the result of the binary AND between x and y variables
0c8ce2b0   Pedro Roque   missing files
112
113
 * reif_v_id - ID of the reification variable
 */
4d26a735   Pedro Roque   Increased recogni...
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
unsigned int c_bool_and_reif(unsigned int x_id, unsigned int y_id, unsigned int z_id, int reif_v_id) {

	if (VS[x_id].max > 1) {
		v_del_gt(&VS[x_id], 1);

		if (VS[x_id].n_vals == 0) {
			printf("\nConstraint BOOL_AND_REIF makes model inconsistent at creation. No solution found.\n");

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif

			exit(0);
		}
	}
	if (VS[y_id].max > 1) {
		v_del_gt(&VS[y_id], 1);

		if (VS[y_id].n_vals == 0) {
			printf("\nConstraint BOOL_AND_REIF makes model inconsistent at creation. No solution found.\n");

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif

			exit(0);
		}
	}
	if (VS[z_id].max > 1) {
		v_del_gt(&VS[z_id], 1);

		if (VS[z_id].n_vals == 0) {
			printf("\nConstraint BOOL_AND_REIF makes model inconsistent at creation. No solution found.\n");

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif

			exit(0);
		}
	}
0c8ce2b0   Pedro Roque   missing files
158
159
160
161
162

	if (VS[reif_v_id].max > 1) {
		v_del_gt(&VS[reif_v_id], 1);

		if (VS[reif_v_id].n_vals == 0) {
4d26a735   Pedro Roque   Increased recogni...
163
			printf("\nConstraint BOOL_AND_REIF makes model inconsistent at creation. No solution found.\n");
0c8ce2b0   Pedro Roque   missing files
164

4d26a735   Pedro Roque   Increased recogni...
165
166
167
168
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
			printf("\nPress any key to exit\n");
			int a = getchar();
#endif
0c8ce2b0   Pedro Roque   missing files
169

4d26a735   Pedro Roque   Increased recogni...
170
			exit(0);
0c8ce2b0   Pedro Roque   missing files
171
172
173
174
175
176
177
178
		}
	}

	// set to include in kernel compilation
	USE_CS[BOOL_AND] = 1;
	USE_CS_REIFI[BOOL_AND] = 1;
	REV = 1;

4d26a735   Pedro Roque   Increased recogni...
179
180
181
182
	unsigned int c_vs[3];
	c_vs[0] = x_id;
	c_vs[1] = y_id;
	c_vs[2] = z_id;
0c8ce2b0   Pedro Roque   missing files
183
184

	// creates a new generic constraint
4d26a735   Pedro Roque   Increased recogni...
185
	unsigned int c_id = c_new(c_vs, 3, NULL, 0, reif_v_id);
0c8ce2b0   Pedro Roque   missing files
186
187
188
189
190
191

	// pointers to this type of constraint functions
	CS[c_id].kind = BOOL_AND;
	CS[c_id].check_sol_f = &bool_and_check;
	CS[c_id].constant_val = 0;

0c8ce2b0   Pedro Roque   missing files
192
193
194
195
196
	return c_id;
}

/*
 * Return true if the bool_and constraint is respected or false if not
4d26a735   Pedro Roque   Increased recogni...
197
 * (x & y) ↔ z
0c8ce2b0   Pedro Roque   missing files
198
199
200
 * c - constraint to check if is respected
 * explored - if the CSP was already explored, which mean that all the variables must already be singletons
 * */
4d26a735   Pedro Roque   Increased recogni...
201
bool bool_and_check(constr *c, bool explored) {
0c8ce2b0   Pedro Roque   missing files
202

4d26a735   Pedro Roque   Increased recogni...
203
204
205
206
	var *x = c->c_vs[0];
	var *y = c->c_vs[1];
	var *z = c->c_vs[2];
	unsigned int i;
0c8ce2b0   Pedro Roque   missing files
207

4d26a735   Pedro Roque   Increased recogni...
208
209
210
211
	if (!explored) {
		for (i = 0; i < c->n_c_vs; i++) {
			if (c->c_vs[i]->n_vals > 1) {
				return false;
0c8ce2b0   Pedro Roque   missing files
212
			}
4d26a735   Pedro Roque   Increased recogni...
213
214
215
216
217
218
		}
	}

	if (c->reified && VS[c->reif_v_id].n_vals > 1) {
		if (explored) {
			fprintf(stderr, "\nError: Reification variable of constraint BOOL_AND_REIF (%d) has 2 values.\n", c->c_id);
0c8ce2b0   Pedro Roque   missing files
219
220
			return false;
		}
0c8ce2b0   Pedro Roque   missing files
221
222
	}

4d26a735   Pedro Roque   Increased recogni...
223
224
225
	if (((!c->reified || (c->reified && VS[c->reif_v_id].min == 1))
			&& (((x->min == 0 || y->min == 0) && z->min == 1) || (x->min == 1 && y->min == 1 && z->min == 0)))
			|| (c->reified && VS[c->reif_v_id].min == 0 && (((x->min == 0 || y->min == 0) && z->min != 1) || (x->min == 1 && y->min == 1 && z->min != 0)))) {
0c8ce2b0   Pedro Roque   missing files
226
227

		if (explored) {
4d26a735   Pedro Roque   Increased recogni...
228
229
230
231
232
233
234
235
236

			if (c->reified) {
				fprintf(stderr, "\nError: Constraint BOOL_AND_REIF (%d) not respected:\n", c->c_id);
				fprintf(stderr, "Reif ID=%u -> minimum=%u, maximum=%u, number of values=%u\n\n", c->reif_v_id, b_get_min_val(&VS[c->reif_v_id].domain_b),
						b_get_max_val(&VS[c->reif_v_id].domain_b), b_cnt_vals(&VS[c->reif_v_id].domain_b));

			} else {
				fprintf(stderr, "\nError: Constraint BOOL_AND (%d) not respected:\n", c->c_id);
			}
0c8ce2b0   Pedro Roque   missing files
237
238
239

			for (i = 0; i < c->n_c_vs; i++) {
				fprintf(stderr, "Variable ID=%u -> minimum=%u, maximum=%u, number of values=%u\n\n", c->c_vs[i]->v_id, b_get_min_val(&c->c_vs[i]->domain_b),
4d26a735   Pedro Roque   Increased recogni...
240
						b_get_max_val(&c->c_vs[i]->domain_b), b_cnt_vals(&c->c_vs[i]->domain_b));
0c8ce2b0   Pedro Roque   missing files
241
242
243
244
245
246
247
248
249
250
251
252
253
			}
		}
		return false;
	}

	return true;
}

#endif

#if CS_BOOL_AND == 1
/*
 * Propagate the domain of the variable with the ID prop_v_id through all the other variables on the same c_numb ID bool_and constraint
4d26a735   Pedro Roque   Increased recogni...
254
 * (x & y) ↔ z
0c8ce2b0   Pedro Roque   missing files
255
256
 * vs_per_c_idx - vector with all constrained variables ID per constraint, per constraint ID order
 * vs_prop_ - all CSP variables with current step values
0c8ce2b0   Pedro Roque   missing files
257
258
 * current_cs - constraint that should be propagated for the variable with prop_v_id ID
 * vs_id_to_prop_ - circular vector with the ids of the variables to propagate
4d26a735   Pedro Roque   Increased recogni...
259
 * prop_ok - will be set to 1 or 0 if the constraint is respected or not
0c8ce2b0   Pedro Roque   missing files
260
 */
4d26a735   Pedro Roque   Increased recogni...
261
262
263
264
265
266
267
268
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
CUDA_FUNC void bool_and_prop(CL_INTS_MEM int *vs_per_c_idx, CL_MEMORY VARS_PROP *vs_prop_, CL_CS_MEM cl_constr *current_cs,
		CL_MEMORY unsigned short *vs_id_to_prop_, bool *prop_ok CS_IGNORE_FUNC TTL_CTR) {

	int x_id = vs_per_c_idx[0];
	int y_id = vs_per_c_idx[1];
	int z_id = vs_per_c_idx[2];
0c8ce2b0   Pedro Roque   missing files
269
	bool changed;
0c8ce2b0   Pedro Roque   missing files
270

4d26a735   Pedro Roque   Increased recogni...
271
272
	if (V_N_VALS(vs_prop_[x_id]) == 1) {
		if (V_MIN(vs_prop_[x_id]) == 0) {
0c8ce2b0   Pedro Roque   missing files
273

4d26a735   Pedro Roque   Increased recogni...
274
275
276
277
278
279
280
281
282
			cl_v_del_val_m(&changed, &vs_prop_[z_id], 1 TTL_CTR_V);
			if (changed) {
				// if the removal of the value resulted in an empty domain return 0
				if (V_IS_EMPTY(vs_prop_[z_id])) {
					*prop_ok = 0;
					return;
				}
				v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
			}
0c8ce2b0   Pedro Roque   missing files
283

4d26a735   Pedro Roque   Increased recogni...
284
285
286
287
#if CL_CS_IGNORE
			cs_ignore[current_cs->c_id] = 1;
#endif
			return;
0c8ce2b0   Pedro Roque   missing files
288

4d26a735   Pedro Roque   Increased recogni...
289
290
291
292
293
294
295
296
297
298
299
300
301
		} else {
			if (V_N_VALS(vs_prop_[y_id]) == 1) {
				if (V_MIN(vs_prop_[y_id]) == 1) {

					cl_v_del_val_m(&changed, &vs_prop_[z_id], 0 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[z_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
					}
0c8ce2b0   Pedro Roque   missing files
302
303
304
305
306
307
308

#if CL_CS_IGNORE
					cs_ignore[current_cs->c_id] = 1;
#endif
					return;

				} else {
4d26a735   Pedro Roque   Increased recogni...
309
310
311
312
313
314
315
316
317
					cl_v_del_val_m(&changed, &vs_prop_[z_id], 1 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[z_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
					}
0c8ce2b0   Pedro Roque   missing files
318
319

#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
320
					cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
321
#endif
4d26a735   Pedro Roque   Increased recogni...
322
323
					return;
				}
0c8ce2b0   Pedro Roque   missing files
324

4d26a735   Pedro Roque   Increased recogni...
325
326
				// y has 2 values and x is 1
			} else if (V_N_VALS(vs_prop_[z_id]) == 1) {
0c8ce2b0   Pedro Roque   missing files
327

4d26a735   Pedro Roque   Increased recogni...
328
329
330
				if (V_MIN(vs_prop_[z_id]) == 1) {
					cl_v_bool_del_val_m(&vs_prop_[y_id], 0 TTL_CTR_V);
					v_add_to_prop(vs_id_to_prop_, vs_prop_, y_id);
0c8ce2b0   Pedro Roque   missing files
331

4d26a735   Pedro Roque   Increased recogni...
332
333
334
335
				} else {
					cl_v_bool_del_val_m(&vs_prop_[y_id], 1 TTL_CTR_V);
					v_add_to_prop(vs_id_to_prop_, vs_prop_, y_id);
				}
0c8ce2b0   Pedro Roque   missing files
336
337

#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
338
				cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
339
#endif
4d26a735   Pedro Roque   Increased recogni...
340
341
342
343
344
345
346
347
348
349
350
351
352
				return;
			}
		}

		// x has 2 values and maybe y too
	} else if (V_N_VALS(vs_prop_[y_id]) == 1) {
		if (V_MIN(vs_prop_[y_id]) == 0) {

			cl_v_del_val_m(&changed, &vs_prop_[z_id], 1 TTL_CTR_V);
			if (changed) {
				// if the removal of the value resulted in an empty domain return 0
				if (V_IS_EMPTY(vs_prop_[z_id])) {
					*prop_ok = 0;
0c8ce2b0   Pedro Roque   missing files
353
354
					return;
				}
4d26a735   Pedro Roque   Increased recogni...
355
				v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
0c8ce2b0   Pedro Roque   missing files
356
			}
0c8ce2b0   Pedro Roque   missing files
357

4d26a735   Pedro Roque   Increased recogni...
358
359
360
361
#if CL_CS_IGNORE
			cs_ignore[current_cs->c_id] = 1;
#endif
			return;
0c8ce2b0   Pedro Roque   missing files
362

0c8ce2b0   Pedro Roque   missing files
363
		} else {
4d26a735   Pedro Roque   Increased recogni...
364
365
366
367
368
369
370
371
372
373
374
375
			if (V_N_VALS(vs_prop_[z_id]) == 1) {
				if (V_MIN(vs_prop_[z_id]) == 1) {

					cl_v_del_val_m(&changed, &vs_prop_[x_id], 0 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[x_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, x_id);
					}
0c8ce2b0   Pedro Roque   missing files
376
377

#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
378
					cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
379
#endif
4d26a735   Pedro Roque   Increased recogni...
380
					return;
0c8ce2b0   Pedro Roque   missing files
381

4d26a735   Pedro Roque   Increased recogni...
382
383
384
385
386
387
388
389
390
391
				} else {
					cl_v_del_val_m(&changed, &vs_prop_[x_id], 1 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[x_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, x_id);
					}
0c8ce2b0   Pedro Roque   missing files
392

4d26a735   Pedro Roque   Increased recogni...
393
394
395
#if CL_CS_IGNORE
					cs_ignore[current_cs->c_id] = 1;
#endif
0c8ce2b0   Pedro Roque   missing files
396
397
					return;
				}
0c8ce2b0   Pedro Roque   missing files
398
399
			}
		}
4d26a735   Pedro Roque   Increased recogni...
400
401
402
403
404
405
406
407
408
409
410
411
412
	}

	// x and y have two values
	if (V_N_VALS(vs_prop_[z_id]) == 1) {

		if (V_MIN(vs_prop_[z_id]) == 1) {

			cl_v_bool_del_val_m(&vs_prop_[x_id], 0 TTL_CTR_V);
			v_add_to_prop(vs_id_to_prop_, vs_prop_, x_id);

			cl_v_bool_del_val_m(&vs_prop_[y_id], 0 TTL_CTR_V);
			v_add_to_prop(vs_id_to_prop_, vs_prop_, y_id);

0c8ce2b0   Pedro Roque   missing files
413
#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
414
			cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
415
#endif
4d26a735   Pedro Roque   Increased recogni...
416
		}
0c8ce2b0   Pedro Roque   missing files
417
418
	}
}
4d26a735   Pedro Roque   Increased recogni...
419
#pragma GCC diagnostic pop
0c8ce2b0   Pedro Roque   missing files
420
421
422
423

#if CS_R_BOOL_AND == 1
/*
 * Validate bool_and constraint to be normally propagated, when reified
4d26a735   Pedro Roque   Increased recogni...
424
 * (x & y) ↔ z
0c8ce2b0   Pedro Roque   missing files
425
426
427
428
429
 * vs_per_c_idx - vector with all constrained variables ID per constraint, per constraint ID order
 * vs_prop_ - all CSP variables with current step values
 * current_cs - constraint that should be propagated for the variable with prop_v_id ID
 * vs_id_to_prop_ - circular vector with the ids of the variables to propagate
 */
4d26a735   Pedro Roque   Increased recogni...
430
431
CUDA_FUNC void bool_and_reif( CL_INTS_MEM int *vs_per_c_idx, CL_MEMORY VARS_PROP *vs_prop_, CL_CS_MEM cl_constr *current_cs,
		CL_MEMORY unsigned short *vs_id_to_prop_ CS_IGNORE_FUNC TTL_CTR) {
0c8ce2b0   Pedro Roque   missing files
432

4d26a735   Pedro Roque   Increased recogni...
433
434
435
	int x_id = vs_per_c_idx[0];
	int y_id = vs_per_c_idx[1];
	int z_id = vs_per_c_idx[2];
0c8ce2b0   Pedro Roque   missing files
436

4d26a735   Pedro Roque   Increased recogni...
437
438
	if (V_N_VALS(vs_prop_[z_id]) == 1 && V_MIN(vs_prop_[z_id]) == 1 && V_N_VALS(vs_prop_[x_id]) == 1 && V_MIN(vs_prop_[x_id]) == 1
			&& V_N_VALS(vs_prop_[y_id]) == 1 && V_MIN(vs_prop_[y_id]) == 1) {
0c8ce2b0   Pedro Roque   missing files
439

4d26a735   Pedro Roque   Increased recogni...
440
441
		cl_v_bool_del_val_m(&vs_prop_[current_cs->reif_var_id], 0 TTL_CTR_V);
		v_add_to_prop(vs_id_to_prop_, vs_prop_, convert_int (current_cs->reif_var_id));
0c8ce2b0   Pedro Roque   missing files
442

0c8ce2b0   Pedro Roque   missing files
443
#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
444
		cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
445
#endif
0c8ce2b0   Pedro Roque   missing files
446

4d26a735   Pedro Roque   Increased recogni...
447
448
449
450
451
452
	} else if (V_N_VALS(vs_prop_[z_id]) == 1 && V_MIN(vs_prop_[z_id]) == 1
			&& ((V_N_VALS(vs_prop_[x_id]) == 1 && V_MIN(vs_prop_[x_id]) == 0) || (V_N_VALS(vs_prop_[y_id]) == 1 && V_MIN(vs_prop_[y_id]) == 0))) {

		cl_v_bool_del_val_m(&vs_prop_[current_cs->reif_var_id], 1 TTL_CTR_V);
		v_add_to_prop(vs_id_to_prop_, vs_prop_, convert_int (current_cs->reif_var_id));

0c8ce2b0   Pedro Roque   missing files
453
#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
454
		cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
455
#endif
0c8ce2b0   Pedro Roque   missing files
456

4d26a735   Pedro Roque   Increased recogni...
457
458
	} else if (V_N_VALS(vs_prop_[z_id]) == 1 && V_MIN(vs_prop_[z_id]) == 0
			&& ((V_N_VALS(vs_prop_[x_id]) == 1 && V_MIN(vs_prop_[x_id]) == 0) || (V_N_VALS(vs_prop_[y_id]) == 1 && V_MIN(vs_prop_[y_id]) == 0))) {
0c8ce2b0   Pedro Roque   missing files
459

4d26a735   Pedro Roque   Increased recogni...
460
461
		cl_v_bool_del_val_m(&vs_prop_[current_cs->reif_var_id], 0 TTL_CTR_V);
		v_add_to_prop(vs_id_to_prop_, vs_prop_, convert_int (current_cs->reif_var_id));
0c8ce2b0   Pedro Roque   missing files
462

0c8ce2b0   Pedro Roque   missing files
463
#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
464
		cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
465
#endif
0c8ce2b0   Pedro Roque   missing files
466

4d26a735   Pedro Roque   Increased recogni...
467
468
469
470
471
	} else if (V_N_VALS(vs_prop_[z_id]) == 1 && V_MIN(vs_prop_[z_id]) == 0 && V_N_VALS(vs_prop_[x_id]) == 1 && V_MIN(vs_prop_[x_id]) == 1
			&& V_N_VALS(vs_prop_[y_id]) == 1 && V_MIN(vs_prop_[y_id]) == 1) {

		cl_v_bool_del_val_m(&vs_prop_[current_cs->reif_var_id], 1 TTL_CTR_V);
		v_add_to_prop(vs_id_to_prop_, vs_prop_, convert_int (current_cs->reif_var_id));
0c8ce2b0   Pedro Roque   missing files
472

0c8ce2b0   Pedro Roque   missing files
473
#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
474
		cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
475
#endif
4d26a735   Pedro Roque   Increased recogni...
476

0c8ce2b0   Pedro Roque   missing files
477
478
479
480
481
	}
}

/*
 * Propagate the domain of the variable with the ID prop_v_id through all the other variables on the same c_numb ID bool_and opposite constraint
4d26a735   Pedro Roque   Increased recogni...
482
 * (x & y) != z
0c8ce2b0   Pedro Roque   missing files
483
484
 * vs_per_c_idx - vector with all constrained variables ID per constraint, per constraint ID order
 * vs_prop_ - all CSP variables with current step values
0c8ce2b0   Pedro Roque   missing files
485
486
 * current_cs - constraint that should be propagated for the variable with prop_v_id ID
 * vs_id_to_prop_ - circular vector with the ids of the variables to propagate
4d26a735   Pedro Roque   Increased recogni...
487
 * prop_ok - will be set to 1 or 0 if the constraint is respected or not
0c8ce2b0   Pedro Roque   missing files
488
 */
4d26a735   Pedro Roque   Increased recogni...
489
490
491
492
493
494
495
496
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
CUDA_FUNC void bool_and_prop_opposite(CL_INTS_MEM int *vs_per_c_idx, CL_MEMORY VARS_PROP *vs_prop_, CL_CS_MEM cl_constr *current_cs,
		CL_MEMORY unsigned short *vs_id_to_prop_, bool *prop_ok CS_IGNORE_FUNC TTL_CTR) {

	int x_id = vs_per_c_idx[0];
	int y_id = vs_per_c_idx[1];
	int z_id = vs_per_c_idx[2];
0c8ce2b0   Pedro Roque   missing files
497
	bool changed;
0c8ce2b0   Pedro Roque   missing files
498

4d26a735   Pedro Roque   Increased recogni...
499
500
	if (V_N_VALS(vs_prop_[x_id]) == 1) {
		if (V_MIN(vs_prop_[x_id]) == 0) {
0c8ce2b0   Pedro Roque   missing files
501

4d26a735   Pedro Roque   Increased recogni...
502
503
504
505
506
507
508
509
510
			cl_v_del_val_m(&changed, &vs_prop_[z_id], 0 TTL_CTR_V);
			if (changed) {
				// if the removal of the value resulted in an empty domain return 0
				if (V_IS_EMPTY(vs_prop_[z_id])) {
					*prop_ok = 0;
					return;
				}
				v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
			}
0c8ce2b0   Pedro Roque   missing files
511

4d26a735   Pedro Roque   Increased recogni...
512
513
514
515
#if CL_CS_IGNORE
			cs_ignore[current_cs->c_id] = 1;
#endif
			return;
0c8ce2b0   Pedro Roque   missing files
516

4d26a735   Pedro Roque   Increased recogni...
517
518
519
520
521
522
523
524
525
526
527
528
529
		} else {
			if (V_N_VALS(vs_prop_[y_id]) == 1) {
				if (V_MIN(vs_prop_[y_id]) == 1) {

					cl_v_del_val_m(&changed, &vs_prop_[z_id], 1 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[z_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
					}
0c8ce2b0   Pedro Roque   missing files
530
531
532
533
534
535
536

#if CL_CS_IGNORE
					cs_ignore[current_cs->c_id] = 1;
#endif
					return;

				} else {
4d26a735   Pedro Roque   Increased recogni...
537
538
539
540
541
542
543
544
545
					cl_v_del_val_m(&changed, &vs_prop_[z_id], 0 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[z_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
					}
0c8ce2b0   Pedro Roque   missing files
546
547

#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
548
					cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
549
#endif
4d26a735   Pedro Roque   Increased recogni...
550
551
					return;
				}
0c8ce2b0   Pedro Roque   missing files
552

4d26a735   Pedro Roque   Increased recogni...
553
554
				// y has 2 values and x is 1
			} else if (V_N_VALS(vs_prop_[z_id]) == 1) {
0c8ce2b0   Pedro Roque   missing files
555

4d26a735   Pedro Roque   Increased recogni...
556
557
558
				if (V_MIN(vs_prop_[z_id]) == 1) {
					cl_v_bool_del_val_m(&vs_prop_[y_id], 1 TTL_CTR_V);
					v_add_to_prop(vs_id_to_prop_, vs_prop_, y_id);
0c8ce2b0   Pedro Roque   missing files
559

4d26a735   Pedro Roque   Increased recogni...
560
561
562
563
				} else {
					cl_v_bool_del_val_m(&vs_prop_[y_id], 0 TTL_CTR_V);
					v_add_to_prop(vs_id_to_prop_, vs_prop_, y_id);
				}
0c8ce2b0   Pedro Roque   missing files
564
565

#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
566
				cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
567
#endif
4d26a735   Pedro Roque   Increased recogni...
568
569
570
571
572
573
574
575
576
577
578
579
580
				return;
			}
		}

		// x has 2 values and maybe y too
	} else if (V_N_VALS(vs_prop_[y_id]) == 1) {
		if (V_MIN(vs_prop_[y_id]) == 0) {

			cl_v_del_val_m(&changed, &vs_prop_[z_id], 0 TTL_CTR_V);
			if (changed) {
				// if the removal of the value resulted in an empty domain return 0
				if (V_IS_EMPTY(vs_prop_[z_id])) {
					*prop_ok = 0;
0c8ce2b0   Pedro Roque   missing files
581
582
					return;
				}
4d26a735   Pedro Roque   Increased recogni...
583
				v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
0c8ce2b0   Pedro Roque   missing files
584
			}
0c8ce2b0   Pedro Roque   missing files
585

4d26a735   Pedro Roque   Increased recogni...
586
587
588
589
#if CL_CS_IGNORE
			cs_ignore[current_cs->c_id] = 1;
#endif
			return;
0c8ce2b0   Pedro Roque   missing files
590

0c8ce2b0   Pedro Roque   missing files
591
		} else {
4d26a735   Pedro Roque   Increased recogni...
592
593
594
595
596
597
598
599
600
601
602
603
			if (V_N_VALS(vs_prop_[x_id]) == 1) {
				if (V_MIN(vs_prop_[x_id]) == 1) {

					cl_v_del_val_m(&changed, &vs_prop_[z_id], 1 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[z_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
					}
0c8ce2b0   Pedro Roque   missing files
604
605

#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
606
					cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
607
#endif
4d26a735   Pedro Roque   Increased recogni...
608
					return;
0c8ce2b0   Pedro Roque   missing files
609

4d26a735   Pedro Roque   Increased recogni...
610
611
612
613
614
615
616
617
618
619
				} else {
					cl_v_del_val_m(&changed, &vs_prop_[z_id], 0 TTL_CTR_V);
					if (changed) {
						// if the removal of the value resulted in an empty domain return 0
						if (V_IS_EMPTY(vs_prop_[z_id])) {
							*prop_ok = 0;
							return;
						}
						v_add_to_prop(vs_id_to_prop_, vs_prop_, z_id);
					}
0c8ce2b0   Pedro Roque   missing files
620

4d26a735   Pedro Roque   Increased recogni...
621
622
623
#if CL_CS_IGNORE
					cs_ignore[current_cs->c_id] = 1;
#endif
0c8ce2b0   Pedro Roque   missing files
624
					return;
4d26a735   Pedro Roque   Increased recogni...
625
626
627
628
629
630
631
632
633
				}

				// y has 2 values and x is 1
			} else if (V_N_VALS(vs_prop_[z_id]) == 1) {

				if (V_MIN(vs_prop_[z_id]) == 1) {
					cl_v_bool_del_val_m(&vs_prop_[x_id], 1 TTL_CTR_V);
					v_add_to_prop(vs_id_to_prop_, vs_prop_, x_id);

0c8ce2b0   Pedro Roque   missing files
634
				} else {
4d26a735   Pedro Roque   Increased recogni...
635
					cl_v_bool_del_val_m(&vs_prop_[x_id], 0 TTL_CTR_V);
0c8ce2b0   Pedro Roque   missing files
636
637
					v_add_to_prop(vs_id_to_prop_, vs_prop_, x_id);
				}
4d26a735   Pedro Roque   Increased recogni...
638

0c8ce2b0   Pedro Roque   missing files
639
#if CL_CS_IGNORE
4d26a735   Pedro Roque   Increased recogni...
640
				cs_ignore[current_cs->c_id] = 1;
0c8ce2b0   Pedro Roque   missing files
641
#endif
4d26a735   Pedro Roque   Increased recogni...
642
643
644
				return;
			}
		}
0c8ce2b0   Pedro Roque   missing files
645
646
	}
}
4d26a735   Pedro Roque   Increased recogni...
647
#pragma GCC diagnostic pop
0c8ce2b0   Pedro Roque   missing files
648
649
650

#endif

4d26a735   Pedro Roque   Increased recogni...
651
652
653
654
655
656
657
658
659
660
/*
 * Decides the propagator to call for this constraint
 * vs_per_c_idx - vector with all constrained variables ID per constraint, per constraint ID order
 * vs_prop_ - all CSP variables with current step values
 * current_cs - constraint that should be propagated for the variable with prop_v_id ID
 * vs_id_to_prop_ - circular vector with the ids of the variables to propagate
 * prop_ok - will be set to 1 or 0 if the constraint is respected or not
 */
CUDA_FUNC void bool_and_propagate(CL_INTS_MEM int *vs_per_c_idx, CL_MEMORY VARS_PROP *vs_prop_, CL_CS_MEM cl_constr *current_cs,
		CL_MEMORY unsigned short *vs_id_to_prop_, bool *prop_ok PROPAGATED_FUNC CS_IGNORE_FUNC TTL_CTR) {
0c8ce2b0   Pedro Roque   missing files
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692

#if CS_R_BOOL_AND == 0
	bool_and_prop(vs_per_c_idx, vs_prop_, current_cs, vs_id_to_prop_, prop_ok CS_IGNORE_CALL TTL_CTR_V);
#if CL_STATS == 1
	*propagated = true;
#endif

#elif CS_R_BOOL_AND == 1
	if (current_cs->reified == 1) {
		if (V_N_VALS(vs_prop_[current_cs->reif_var_id]) > 1) {
			bool_and_reif(vs_per_c_idx, vs_prop_, current_cs, vs_id_to_prop_ CS_IGNORE_CALL TTL_CTR_V);

		} else {
			if (V_MIN(vs_prop_[current_cs->reif_var_id]) == 1) {
				bool_and_prop(vs_per_c_idx, vs_prop_, current_cs, vs_id_to_prop_, prop_ok CS_IGNORE_CALL TTL_CTR_V);
			} else {
				bool_and_prop_opposite(vs_per_c_idx, vs_prop_, current_cs, vs_id_to_prop_, prop_ok CS_IGNORE_CALL TTL_CTR_V);
			}
#if CL_STATS == 1
			*propagated = true;
#endif
		}
	} else {
		bool_and_prop(vs_per_c_idx, vs_prop_, current_cs, vs_id_to_prop_, prop_ok CS_IGNORE_CALL TTL_CTR_V);
#if CL_STATS == 1
		*propagated = true;
#endif
	}
#endif
}

#endif