Blame view

src/constraints.h 3.14 KB
94b2b13d   Pedro Roque   PHACT source
1
2
3
4
/*
 * constraints.h
 *
 *  Created on: 23/08/2014
4d26a735   Pedro Roque   Increased recogni...
5
 *      Author: pedro
94b2b13d   Pedro Roque   PHACT source
6
7
8
9
10
11
12
13
14
15
16
 */

#ifndef SRC_CONSTRAINTS_H_
#define SRC_CONSTRAINTS_H_

#include "config.h"
#include "kernels/cl_constraints.h"

typedef struct constr constr;	// CSP constraint
typedef struct var var;		// CSP variable

4d26a735   Pedro Roque   Increased recogni...
17
18
extern constr* CS;	// Vector with all the CSP constraints
extern constr* CS_AUX;	// Vector with all the CSP constraints for increasing size
94b2b13d   Pedro Roque   PHACT source
19
20
21
22
23
24
extern bool USE_CS[N_C_TYPES];	// flags for compiling each constraint type in kernel // @suppress("Symbol is not resolved")
extern bool USE_CS_REIFI[N_C_TYPES];	// flags for compiling reification for the constraint types that use it // @suppress("Symbol is not resolved")
extern bool USE_NON_CS_REIFI[N_C_TYPES];	// flags for printing the stats of used constraints

//CSP variable
struct var {
4d26a735   Pedro Roque   Increased recogni...
25
	bitmap domain_b;	// bitmap domain
94b2b13d   Pedro Roque   PHACT source
26
	cl_ushort2 domain_i;	// interval domain
4d26a735   Pedro Roque   Increased recogni...
27
	cl_ushort v_id;	// Variable id in the CSP
94b2b13d   Pedro Roque   PHACT source
28
	cl_ushort v_id_print;	// Variable id in the CSP for printing after sorting the variables
4d26a735   Pedro Roque   Increased recogni...
29
30
	cl_ushort min;	// Minimum domain value
	cl_ushort max;	// Maximum domain value
94b2b13d   Pedro Roque   PHACT source
31
	cl_ushort n_vals;	// Number of domain values
4d26a735   Pedro Roque   Increased recogni...
32
	cl_ushort n_cs;	// Number of constraints that constrain this variable
94b2b13d   Pedro Roque   PHACT source
33
34
35
36
37
	cl_char to_prop;	// True if this variable is assigned for propagation
	cl_char to_label;	// True if this variable is assigned for labeling
	cl_char expanded;	// True if this variable was fully expanded during sub-search space creation, or false if not
	cl_char reif;		// True if this is a boolean variable used for reification of a constraint
	cl_char boolean;	// True if this variable is a boolean or false if not
4d26a735   Pedro Roque   Increased recogni...
38
39
40
41
42
	struct constr** cs; // Pointers to constraints that constrain this variable
};

//CSP constraint
struct constr {
94b2b13d   Pedro Roque   PHACT source
43
44
45
46
47
48
	cl_uint reif_v_id;	// ID of the reification variable
	cl_uint c_id;		// Constraint id in the CSP
	cl_int constant_val;		// Constant value constrained by this constraint (if only one)
	cl_ushort n_c_vs;		// Number of variables constrained by this constraint
	cl_ushort n_c_consts;	// number of constant values constrained by this constraint in cs_const_idx vector
	c_kind kind;	// Constraint type
4d26a735   Pedro Roque   Increased recogni...
49
	cl_char reified;		// True of this constraint is reified
94b2b13d   Pedro Roque   PHACT source
50
51
	cl_int* c_consts;	// Constant values constrained by this constraint (if more than one)
	var** c_vs;		// Pointers to variables constrained by this constraint
4d26a735   Pedro Roque   Increased recogni...
52
53
54
55
56
57
	bool (*check_sol_f)(constr* c, bool explored);	// Pointer to the consistency check function for this constraint
	cl_char ignore;	// After filtering, the constraint may be ignored
	cl_char boolean;	// true if all the constrained variables are boolean
};

unsigned int c_new(unsigned int* vs_id, unsigned int n_vs, int* consts, unsigned int n_consts, int reif_v_id);
94b2b13d   Pedro Roque   PHACT source
58
59
60
void cs_copy(constr* cs_dest, constr* cs_src, unsigned int n_cs);

int cs_cnt_vals(constr* cs, unsigned int n_cs);
4d26a735   Pedro Roque   Increased recogni...
61
62
int cs_cnt_vs(constr* cs, unsigned int n_cs);
int cs_cnt_diff_vs(constr* cs, unsigned int n_cs);
94b2b13d   Pedro Roque   PHACT source
63
int cs_cnt_constants(constr* cs, unsigned int n_cs);
4d26a735   Pedro Roque   Increased recogni...
64
65
66
67

void cs_remove_ignored();

bool cs_check(bool explored);
94b2b13d   Pedro Roque   PHACT source
68
69
70
71
72
73
74
75

void cs_clear();

void cs_print_all_vs_id();
void cs_print_type(constr* cs);
char* cs_get_type(c_kind kind);
void cs_print_used();

4d26a735   Pedro Roque   Increased recogni...
76
#endif /* SRC_CONSTRAINTS_H_ */
94b2b13d   Pedro Roque   PHACT source