Blame view

src/constraints/plus-gt.c 978 Bytes
965dadaa   Salvador Abreu   initial commit fr...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* X + Y > k */

int fd_plus_gt_propagate(fd_constraint this, fd_int revise)
{
  fd_int other;
  int other_idx;
  int changed = 0;

  other_idx = revise == VAR(this, 0) ? 1 : 0;
  other = VAR(this, other_idx);

  changed = _fd_var_del_le(this->constants[0] - _fd_var_max(other), revise);

  if (changed && fd_domain_empty(revise))
    return FD_NOSOLUTION;

  // XXX: enqueue further updates here?
  if (changed)
    _fd_revise_connected(this, revise);

  return FD_OK;
}

fd_constraint fd_plus_gt(fd_int x, fd_int y, int k)
{
eef94371   Vasco Pedro   Update to PaCCS v...
26
  fd_constraint c = _fd_constraint_new(2, 1);
965dadaa   Salvador Abreu   initial commit fr...
27
28
29
30
31

  if (c)
    {
      c->variables[0] = FD_INT2C_VAR(x); c->variables[1] = FD_INT2C_VAR(y);
      c->constants[0] = k;
eef94371   Vasco Pedro   Update to PaCCS v...
32
#ifdef CONSTRAINT_CLASS
965dadaa   Salvador Abreu   initial commit fr...
33
      c->kind = FD_CONSTR_PLUS_GT;
965dadaa   Salvador Abreu   initial commit fr...
34
35
36
37
38
39
40
41
42
#else /* CONSTRAINT_CLASS */
      c->propagator = fd_plus_gt_propagate;
#endif /* CONSTRAINT_CLASS */

      _fd_var_add_constraint(x, c);
      _fd_var_add_constraint(y, c);

      _fd_add_constraint(c);
    }