Blame view

src/constraints/lt.c 2.21 KB
eef94371   Vasco Pedro   Update to PaCCS v...
1
/* X lt Y */
965dadaa   Salvador Abreu   initial commit fr...
2

eef94371   Vasco Pedro   Update to PaCCS v...
3
int fd_lt_filter(fd_constraint this)
965dadaa   Salvador Abreu   initial commit fr...
4
5
6
7
8
9
10
11
{
  fd_int x, y;

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

#ifndef DISABLE_ENTAILED
  if (_fd_var_max(x) < _fd_var_min(y))
eef94371   Vasco Pedro   Update to PaCCS v...
12
13
14
15
16
    fd__constraint_set_entailed(this);
#endif

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

      _fd_revise_connected(NULL, y);
    }

  if (_fd_var_del_ge(_fd_var_max(y), x))
eef94371   Vasco Pedro   Update to PaCCS v...
24
    {
965dadaa   Salvador Abreu   initial commit fr...
25
26
27
28
29
30
31
      if (fd_domain_empty(x))
	return FD_NOSOLUTION;

      _fd_revise_connected(NULL, x);
    }

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

int fd_lt_propagate2(fd_constraint this, fd_int culprit)
eef94371   Vasco Pedro   Update to PaCCS v...
35
36
37
38
39
{
  fd_int revise;
  int changed = 0;

#if !defined(DISABLE_ENTAILED) && CONSTRAINT_TEMPS > 2
965dadaa   Salvador Abreu   initial commit fr...
40
41
42
  if (_fd_var_max(VAR(this, 0)) < _fd_var_min(VAR(this, 1)))
    {
      fd__constraint_set_entailed(this);
eef94371   Vasco Pedro   Update to PaCCS v...
43

965dadaa   Salvador Abreu   initial commit fr...
44
      return FD_OK;
eef94371   Vasco Pedro   Update to PaCCS v...
45
46
    }
#endif
965dadaa   Salvador Abreu   initial commit fr...
47
48
49

  if (culprit == VAR(this, 0))
    {
eef94371   Vasco Pedro   Update to PaCCS v...
50
51
52
53
54
55
56
57
      revise = VAR(this, 1);

      changed = _fd_var_del_le(_fd_var_min(culprit), revise);
    }
  else
    {
      revise = VAR(this, 0);

965dadaa   Salvador Abreu   initial commit fr...
58
59
60
61
62
63
64
      changed = _fd_var_del_ge(_fd_var_max(culprit), revise);
    }

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

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

eef94371   Vasco Pedro   Update to PaCCS v...
67
  return FD_OK;
965dadaa   Salvador Abreu   initial commit fr...
68
}
eef94371   Vasco Pedro   Update to PaCCS v...
69
70
71

int fd_lt_propagate(fd_constraint this, fd_int revise)
{
965dadaa   Salvador Abreu   initial commit fr...
72
73
74
  int changed = 0;

  if (revise == VAR(this, 0))
eef94371   Vasco Pedro   Update to PaCCS v...
75
    changed = _fd_var_del_ge(_fd_var_max(VAR(this, 1)), revise);
965dadaa   Salvador Abreu   initial commit fr...
76
  else
eef94371   Vasco Pedro   Update to PaCCS v...
77
    changed = _fd_var_del_le(_fd_var_min(VAR(this, 0)), revise);
965dadaa   Salvador Abreu   initial commit fr...
78

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

#ifdef USE_ENTAILED
eef94371   Vasco Pedro   Update to PaCCS v...
83
84
85
86
87
88
89
90
91
92
93
94
  if (_fd_var_max(VAR(this, 0)) < _fd_var_min(VAR(this, 1)))
    _fd_constraint_set_entailed(this);
#endif

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

  return FD_OK;
}

fd_constraint fd_lt(fd_int x, fd_int y)
965dadaa   Salvador Abreu   initial commit fr...
95
96
97
98
{
  fd_constraint c = _fd_constraint_new(2, 0);

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

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

      _fd_add_constraint(c);
    }
eef94371   Vasco Pedro   Update to PaCCS v...
113

965dadaa   Salvador Abreu   initial commit fr...
114
115
  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...

965dadaa   Salvador Abreu   initial commit fr...