constraints.h 1.83 KB

extern int _fd_constraint_count;
extern fd_constraint _fd_constraints[];

#define CONSTRAINT(v,c) _fd_constraints[(v)->constraints[c]]

#ifdef CONSTRAINT_CLASS

typedef enum {
  FD_CONSTR_NE = 0,
  FD_CONSTR_EQ,
  FD_CONSTR_LT,
  FD_CONSTR_GT = FD_CONSTR_LT,          // XXX: is this standard C?
  FD_CONSTR_LE,
  FD_CONSTR_GE = FD_CONSTR_LE,          // XXX: is this standard C?
  FD_CONSTR_MINUS_NE,
  FD_CONSTR_MINUS_EQ,
  FD_CONSTR_PLUS_GT,
  FD_CONSTR_VAR_EQ_MINUS,
  FD_CONSTR_ALL_DIFFERENT,
  FD_CONSTR_EXACTLY_ONE,
  FD_CONSTR_NOGOODS,
  FD_CONSTR_EXACTLY,
  FD_CONSTR_EXACTLY_VAR,
  FD_CONSTR_SUM,
  FD_CONSTR_VAR_EQ_TIMES,
  FD_CONSTR_SUM_PROD,
  FD_CONSTR_ELEMENT,
  FD_CONSTR_KNAPSACK2,
  FD_CONSTR_SUM2,
  FD_CONSTR_MIN,
  FD_CONSTR_MAX,
  FD_CONSTR_POLY_EQ,
  FD_CONSTR_ELEMENT_VAR,
  FD_CONSTR_EXACTLY_VARS,
  FD_CONSTR_KINDS		// number of kinds of constraints
} _fd_constraint_kind;

typedef struct _fd_constraint_class {
  int (*propagator2)(fd_constraint, fd_int);
  int (*filter)(fd_constraint);
} _fd_constraint_class;

extern _fd_constraint_class _fd_constraint_data[FD_CONSTR_KINDS];


#define _FD_CONSTRAINT_INITIALISATION(name, code) \
  static void _fd_ ## name ## _init(_fd_constraint_class data[]) \
  { \
    data[code].propagator2 = fd_ ## name ## _propagate2; \
    data[code].filter = fd_ ## name ## _filter; \
  }

#define _fd_init_constraint(name) _fd_ ## name ## _init(_fd_constraint_data)

#define _fd_propagate(c,v) (_fd_constraint_data[(c)->kind].propagator2(c, v))
#define _fd_filter(c) (_fd_constraint_data[(c)->kind].filter(c))

#else /* CONSTRAINT_CLASS */

#define _fd_propagate(c,v) ((c)->propagator2(c, v))
#define _fd_filter(c) ((c)->filter(c))

#endif /* CONSTRAINT_CLASS */

#if defined(CONSTRAINT_TEMPS) && !defined(DISABLE_ENTAILED)
int fd__constraint_entailed(fd_constraint);
#else
#define fd__constraint_entailed(_) 0
#endif