Blame view

src/constraints/le.c 2.16 KB
eef94371   Vasco Pedro   Update to PaCCS v...
1
/* X le Y */
965dadaa   Salvador Abreu   initial commit fr...
2
3
4
5
6
7
8
9

static int fd_le_filter(fd_constraint this)
{
  fd_int x, y;

  x = VAR(this, 0);
  y = VAR(this, 1);

eef94371   Vasco Pedro   Update to PaCCS v...
10
11
12
13
14
15
16
17
18
  if (_fd_var_del_lt(_fd_var_min(x), y))
    {
      if (fd_domain_empty(y))
	return FD_NOSOLUTION;

      _fd_revise_connected(NULL, y);
    }

  if (_fd_var_del_gt(_fd_var_max(y), x))
965dadaa   Salvador Abreu   initial commit fr...
19
20
21
22
23
    {
      if (fd_domain_empty(x))
	return FD_NOSOLUTION;

      _fd_revise_connected(NULL, x);
eef94371   Vasco Pedro   Update to PaCCS v...
24
    }
965dadaa   Salvador Abreu   initial commit fr...
25
26
27
28
29
30
31

#if CONSTRAINT_TEMPS > 3
  if (_fd_var_max(x) <= _fd_var_min(y))
    fd__constraint_set_entailed(this);
#endif

  return FD_OK;
eef94371   Vasco Pedro   Update to PaCCS v...
32
}
965dadaa   Salvador Abreu   initial commit fr...
33
34

int fd_le_propagate2(fd_constraint this, fd_int culprit)
eef94371   Vasco Pedro   Update to PaCCS v...
35
{
965dadaa   Salvador Abreu   initial commit fr...
36
37
38
39
40
41
42
  fd_int revise;
  int changed = 0;

  if (culprit == VAR(this, 0))
    {
      revise = VAR(this, 1);

eef94371   Vasco Pedro   Update to PaCCS v...
43
      changed = _fd_var_del_lt(_fd_var_min(culprit), revise);
965dadaa   Salvador Abreu   initial commit fr...
44
    }
eef94371   Vasco Pedro   Update to PaCCS v...
45
46
  else
    {
965dadaa   Salvador Abreu   initial commit fr...
47
48
49
      revise = VAR(this, 0);

      changed = _fd_var_del_gt(_fd_var_max(culprit), revise);
eef94371   Vasco Pedro   Update to PaCCS v...
50
51
52
53
54
55
56
57
    }

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

#if CONSTRAINT_TEMPS > 3
  if (_fd_var_max(VAR(this, 0)) <= _fd_var_min(VAR(this, 1)))
    fd__constraint_set_entailed(this);
965dadaa   Salvador Abreu   initial commit fr...
58
#endif
eef94371   Vasco Pedro   Update to PaCCS v...
59

965dadaa   Salvador Abreu   initial commit fr...
60
  if (changed)
eef94371   Vasco Pedro   Update to PaCCS v...
61
    _fd_revise_connected(0, revise);
965dadaa   Salvador Abreu   initial commit fr...
62

eef94371   Vasco Pedro   Update to PaCCS v...
63
64
65
  return FD_OK;
}

965dadaa   Salvador Abreu   initial commit fr...
66
int fd_le_propagate(fd_constraint this, fd_int revise)
eef94371   Vasco Pedro   Update to PaCCS v...
67
{
965dadaa   Salvador Abreu   initial commit fr...
68
  int changed = 0;
eef94371   Vasco Pedro   Update to PaCCS v...
69
70
71

  if (revise == VAR(this, 0))
    changed = _fd_var_del_gt(_fd_var_max(VAR(this, 1)), revise);
965dadaa   Salvador Abreu   initial commit fr...
72
  else
eef94371   Vasco Pedro   Update to PaCCS v...
73
74
75
    changed = _fd_var_del_lt(_fd_var_min(VAR(this, 0)), revise);

  if (changed && fd_domain_empty(revise))
965dadaa   Salvador Abreu   initial commit fr...
76
    return FD_NOSOLUTION;
eef94371   Vasco Pedro   Update to PaCCS v...
77

965dadaa   Salvador Abreu   initial commit fr...
78
#ifdef USE_ENTAILED
eef94371   Vasco Pedro   Update to PaCCS v...
79
80
  if (_fd_var_max(VAR(this, 0)) <= _fd_var_min(VAR(this, 1)))
    _fd_constraint_set_entailed(this);
965dadaa   Salvador Abreu   initial commit fr...
81
82
#endif

eef94371   Vasco Pedro   Update to PaCCS v...
83
84
85
86
87
88
89
90
91
92
93
94
  // XXX: enqueue further updates here?
  if (changed)
    _fd_revise_connected(this, revise);

  return FD_OK;
}

fd_constraint fd_le(fd_int x, fd_int y)
{
  fd_constraint c = _fd_constraint_new(2, 0);

  if (c)
965dadaa   Salvador Abreu   initial commit fr...
95
96
97
98
    {
      c->variables[0] = FD_INT2C_VAR(x); c->variables[1] = FD_INT2C_VAR(y);
#ifdef CONSTRAINT_CLASS
      c->kind = FD_CONSTR_LE;
eef94371   Vasco Pedro   Update to PaCCS v...
99
#else /* CONSTRAINT_CLASS */
965dadaa   Salvador Abreu   initial commit fr...
100
101
102
103
104
105
106
107
108
109
110
111
      c->propagator2 = fd_le_propagate2;
      c->propagator = fd_le_propagate;
#endif /* CONSTRAINT_CLASS */

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

      _fd_add_constraint(c);
    }

  return c;
}
eef94371   Vasco Pedro   Update to PaCCS v...

965dadaa   Salvador Abreu   initial commit fr...

eef94371   Vasco Pedro   Update to PaCCS v...

965dadaa   Salvador Abreu   initial commit fr...

eef94371   Vasco Pedro   Update to PaCCS v...

965dadaa   Salvador Abreu   initial commit fr...

965dadaa   Salvador Abreu   initial commit fr...