/* * constraints.h * * Created on: 23/08/2014 * Author: Pedro */ #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 extern constr *CS; // Vector with all the CSP constraints extern constr *CS_AUX; // Vector with all the CSP constraints for increasing size 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 { bitmap domain_b; // bitmap domain cl_ushort2 domain_i; // interval domain cl_ushort v_id; // Variable id in the CSP cl_ushort v_id_print; // Variable id in the CSP for printing after sorting the variables cl_ushort min; // Minimum domain value cl_ushort max; // Maximum domain value cl_ushort n_vals; // Number of domain values cl_ushort n_cs; // Number of constraints that constrain this variable 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 #if FZN_SEQ label_heur label_h; // Labeling heuristic for which this variables may be selected in FlatZinc models assign_heur assign_h; // Assign heuristic for which this variables may be selected in FlatZinc models #endif struct constr **cs; // Pointers to constraints that constrain this variable }; //CSP constraint struct constr { 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 cl_char reified; // True of this constraint is reified cl_int *c_consts; // Constant values constrained by this constraint (if more than one) var **c_vs; // Pointers to variables constrained by this constraint 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); void cs_copy(constr *cs_dest, constr *cs_src, unsigned int n_cs); int cs_cnt_vals(constr *cs, unsigned int n_cs); int cs_cnt_vs(constr *cs, unsigned int n_cs); int cs_cnt_diff_vs(constr *cs, unsigned int n_cs); int cs_cnt_constants(constr *cs, unsigned int n_cs); void cs_remove_ignored(); bool cs_check(bool explored); 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(); #endif /* SRC_CONSTRAINTS_H_ */