Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
rel.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  * Guido Tack <tack@gecode.org>
6  *
7  * Contributing authors:
8  * Gabor Szokoli <szokoli@gecode.org>
9  *
10  * Copyright:
11  * Christian Schulte, 2002
12  * Guido Tack, 2004
13  * Gabor Szokoli, 2003
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #ifndef __GECODE_INT_REL_HH__
41 #define __GECODE_INT_REL_HH__
42 
43 #include <gecode/int.hh>
44 
50 namespace Gecode { namespace Int { namespace Rel {
51 
52  /*
53  * Equality propagators
54  *
55  */
56 
66  template<class View0,class View1>
67  class EqDom :
68  public MixBinaryPropagator<View0,PC_INT_DOM,View1,PC_INT_DOM> {
69  protected:
72 
75  public:
77  EqDom(Home home, View0 x0, View1 x1);
79  EqDom(Space& home, Propagator& p, View0 x0, View1 x1);
81  virtual Actor* copy(Space& home);
89  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
91  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
93  static ExecStatus post(Home home, View0 x0, View1 x1);
94  };
95 
102  template<class View0, class View1>
103  class EqVal :
104  public MixBinaryPropagator<View0,PC_INT_VAL,View1,PC_INT_VAL> {
105  protected:
108 
110  EqVal(Space& home, EqVal<View0,View1>& p);
111  public:
113  EqVal(Home home, View0 x0, View1 x1);
115  EqVal(Space& home, Propagator& p, View0 x0, View1 x1);
117  virtual Actor* copy(Space& home);
119  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
121  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
123  static ExecStatus post(Home home, View0 x0, View1 x1);
124  };
125 
132  template<class View0, class View1>
133  class EqBnd :
134  public MixBinaryPropagator<View0,PC_INT_BND,View1,PC_INT_BND> {
135  protected:
138 
140  EqBnd(Space& home, EqBnd<View0,View1>& p);
141  public:
143  EqBnd(Home home, View0 x0, View1 x1);
145  EqBnd(Space& home, Propagator& p, View0 x0, View1 x1);
147  virtual Actor* copy(Space& home);
149  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
151  static ExecStatus post(Home home, View0 x0, View1 x1);
152  };
153 
163  template<class View>
164  class NaryEqDom : public NaryPropagator<View,PC_INT_DOM> {
165  protected:
167 
169  NaryEqDom(Space& home, NaryEqDom<View>& p);
172  public:
174  virtual Actor* copy(Space& home);
182  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
184  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
186  static ExecStatus post(Home home, ViewArray<View>& x);
187  };
188 
195  template<class View>
196  class NaryEqBnd : public NaryPropagator<View,PC_INT_BND> {
197  protected:
199 
201  NaryEqBnd(Space& home, NaryEqBnd<View>& p);
204  public:
206  virtual Actor* copy(Space& home);
213  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
215  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
217  static ExecStatus post(Home home, ViewArray<View>& x);
218  };
219 
229  template<class View, int o>
230  class NaryLqLe : public NaryPropagator<View,PC_INT_NONE> {
231  protected:
234  class Index : public Advisor {
235  public:
237  int i;
239  Index(Space& home, Propagator& p, Council<Index>& c, int i);
241  Index(Space& home, Index& a);
242  };
246  class Pos : public FreeList {
247  public:
249  int p;
250 
252 
253  Pos(int p, Pos* n);
256 
258 
259  Pos* next(void) const;
262 
264 
265  void dispose(Space& home);
267 
269  static void* operator new(size_t s, Space& home);
271  static void operator delete(void* p);
273  static void operator delete(void* p, Space& home);
275  };
279  bool empty(void) const;
281  int pop(Space& home);
283  void push(Space& home, int p);
285  bool run;
289  static const int n_threshold = 7;
291  NaryLqLe(Space& home, NaryLqLe<View,o>& p);
293  NaryLqLe(Home home, ViewArray<View>&);
294  public:
296  virtual Actor* copy(Space& home);
298  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
300  virtual void reschedule(Space& home);
302  virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
304  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
306  virtual size_t dispose(Space& home);
308  static ExecStatus post(Home home, ViewArray<View>& x);
309  };
310 
317  template<class View>
318  class NaryNq : public NaryPropagator<View,PC_INT_VAL> {
319  protected:
322  NaryNq(Home home, ViewArray<View>& x);
324  NaryNq(Space& home, NaryNq<View>& p);
325  public:
327  virtual Actor* copy(Space& home);
329  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
331  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
333  static ExecStatus post(Home home, ViewArray<View>& x);
335  virtual size_t dispose(Space& home);
336  };
337 
338 
345  template<class View, class CtrlView, ReifyMode rm>
346  class ReEqDom : public ReBinaryPropagator<View,PC_INT_DOM,CtrlView> {
347  protected:
351 
353  ReEqDom(Space& home, ReEqDom& p);
355  ReEqDom(Home home, View x0, View x1, CtrlView b);
356  public:
358  virtual Actor* copy(Space& home);
360  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
362  static ExecStatus post(Home home, View x0, View x1, CtrlView b);
363  };
364 
371  template<class View, class CtrlView, ReifyMode rm>
372  class ReEqBnd : public ReBinaryPropagator<View,PC_INT_BND,CtrlView> {
373  protected:
377 
379  ReEqBnd(Space& home, ReEqBnd& p);
381  ReEqBnd(Home home, View x0, View x1, CtrlView b);
382  public:
384  virtual Actor* copy(Space& home);
386  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
388  static ExecStatus post(Home home, View x0, View x1, CtrlView b);
389  };
390 
397  template<class View, class CtrlView, ReifyMode rm>
398  class ReEqDomInt : public ReUnaryPropagator<View,PC_INT_DOM,CtrlView> {
399  protected:
402 
404  int c;
406  ReEqDomInt(Space& home, ReEqDomInt& p);
408  ReEqDomInt(Home home, View x, int c, CtrlView b);
409  public:
411  virtual Actor* copy(Space& home);
413  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
415  static ExecStatus post(Home home, View x, int c, CtrlView b);
416  };
417 
424  template<class View, class CtrlView, ReifyMode rm>
425  class ReEqBndInt : public ReUnaryPropagator<View,PC_INT_BND,CtrlView> {
426  protected:
429 
431  int c;
433  ReEqBndInt(Space& home, ReEqBndInt& p);
435  ReEqBndInt(Home home, View x, int c, CtrlView b);
436  public:
438  virtual Actor* copy(Space& home);
440  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
442  static ExecStatus post(Home home, View x, int c, CtrlView b);
443  };
444 
445 
446 
447 
448  /*
449  * Disequality propagators
450  *
451  */
452 
459  template<class V0, class V1>
460  class Nq : public MixBinaryPropagator<V0,PC_INT_VAL,V1,PC_INT_VAL> {
461  protected:
464 
466  Nq(Space& home, Nq<V0,V1>& p);
468  Nq(Home home, V0 x0, V1 x1);
469  public:
471  virtual Actor* copy(Space& home);
473  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
475  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
477  static ExecStatus post(Home home, V0 x0, V1 x1);
478  };
479 
480  /*
481  * Order propagators
482  *
483  */
484 
492  template<class V0, class V1>
493  class Lq : public MixBinaryPropagator<V0,PC_INT_BND,V1,PC_INT_BND> {
494  protected:
498  static bool same(V0 x0, V1 x1);
500  Lq(Space& home, Lq& p);
502  Lq(Home home, V0 x0, V1 x1);
503  public:
505  virtual Actor* copy(Space& home);
507  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
509  static ExecStatus post(Home home, V0 x0, V1 x1);
510  };
511 
518  template<class V0, class V1>
519  class Le : public MixBinaryPropagator<V0,PC_INT_BND,V1,PC_INT_BND> {
520  protected:
524  static bool same(V0 x0, V1 x1);
526  Le(Space& home, Le& p);
528  Le(Home home, V0 x0, V1 x1);
529  public:
531  virtual Actor* copy(Space& home);
533  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
535  static ExecStatus post(Home home, V0 x0, V1 x1);
536  };
537 
538 
539  /*
540  * Reified order propagators
541  *
542  */
543 
551  template<class View, class CtrlView, ReifyMode rm>
552  class ReLq : public ReBinaryPropagator<View,PC_INT_BND,CtrlView> {
553  protected:
557 
559  ReLq(Space& home, ReLq& p);
561  ReLq(Home home, View x0, View x1, CtrlView b);
562  public:
564  virtual Actor* copy(Space& home);
566  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
568  static ExecStatus post(Home home, View x0, View x1, CtrlView b);
569  };
570 
578  template<class View, class CtrlView, ReifyMode rm>
579  class ReLqInt : public ReUnaryPropagator<View,PC_INT_BND,CtrlView> {
580  protected:
583 
585  int c;
587  ReLqInt(Space& home, ReLqInt& p);
589  ReLqInt(Home home, View x, int c, CtrlView b);
590  public:
592  virtual Actor* copy(Space& home);
594  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
596  static ExecStatus post(Home home, View x, int c, CtrlView b);
597  };
598 
599 
600 
601 
602 
626  template<class VX, class VY>
627  class LexLqLe : public Propagator {
628  protected:
633  bool strict;
635  LexLqLe(Space& home, LexLqLe<VX,VY>& p);
637  LexLqLe(Home home, ViewArray<VX>& x, ViewArray<VY>& y, bool strict);
638  public:
640  virtual Actor* copy(Space& home);
642  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
644  virtual void reschedule(Space& home);
646  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
648  static ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y,
649  bool strict);
651  virtual size_t dispose(Space& home);
652  };
653 
660  template<class VX, class VY>
661  class LexNq : public Propagator {
662  protected:
664  VX x0;
666  VY y0;
668  VX x1;
670  VY y1;
677  RelTest rt, VX& x0, VY& y0, VX x1, VY y1);
679  LexNq(Home home, ViewArray<VX>& x, ViewArray<VY>& y);
681  LexNq(Space& home, LexNq<VX,VY>& p);
682  public:
684  virtual Actor* copy(Space& home);
686  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
688  virtual void reschedule(Space& home);
690  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
692  static ExecStatus post(Home home, ViewArray<VX>& x, ViewArray<VY>& y);
694  virtual size_t dispose(Space& home);
695  };
696 
697 }}}
698 
699 #include <gecode/int/rel/eq.hpp>
700 #include <gecode/int/rel/nq.hpp>
701 #include <gecode/int/rel/lq-le.hpp>
702 #include <gecode/int/rel/lex.hpp>
703 
704 #endif
705 
706 
707 // STATISTICS: int-prop
708 
VX x1
View currently subscribed to.
Definition: rel.hh:668
Council of advisors
Definition: core.hpp:154
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: eq.hpp:223
int c
Integer constant to check.
Definition: rel.hh:431
VX x0
View currently subscribed to.
Definition: rel.hh:664
ViewArray< VY > y
Definition: rel.hh:631
Binary domain consistent equality propagator.
Definition: rel.hh:67
Reified unary propagator.
Definition: propagator.hpp:54
Binary value propagation equality propagator.
Definition: rel.hh:103
ExecStatus resubscribe(Space &home, Propagator &p, VX &x0, ViewArray< VX > &x, VY &x1, ViewArray< VY > &y)
Definition: clause.hpp:138
ViewArray< VX > x
Views not yet subscribed to.
Definition: rel.hh:672
int n_subsumed
Number of already subsumed advisors (or views)
Definition: rel.hh:287
Reified binary propagator.
Definition: propagator.hpp:87
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition: eq.hpp:176
int c
Integer constant to check.
Definition: rel.hh:585
VY y1
View currently subscribed to.
Definition: rel.hh:670
int p
Position of view in view array.
Definition: rel.hh:249
EqDom(Space &home, EqDom< View0, View1 > &p)
Constructor for cloning p.
Definition: eq.hpp:194
Reified less or equal with integer propagator.
Definition: rel.hh:579
Base-class for propagators.
Definition: core.hpp:1023
Lexical disequality propagator.
Definition: rel.hh:661
Base-class for advisors.
Definition: core.hpp:1251
n-ary domain consistent equality propagator
Definition: rel.hh:164
virtual void reschedule(Space &home)
Schedule function.
Definition: pattern.hpp:621
Computation spaces.
Definition: core.hpp:1701
Base-class for both propagators and branchers.
Definition: core.hpp:627
Gecode::IntSet d(v, 7)
bool run
Whether the propagator is currently running.
Definition: rel.hh:285
Reified less or equal propagator.
Definition: rel.hh:552
Nary disequality propagator.
Definition: rel.hh:318
int c
Integer constant to check.
Definition: rel.hh:404
bool same(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:401
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Council< Index > c
The advisor council.
Definition: rel.hh:244
RelTest
Result of testing relation.
Definition: view.hpp:1660
Reified binary domain consistent equality propagator.
Definition: rel.hh:346
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1034
Binary bounds consistent equality propagator.
Definition: rel.hh:133
Less or equal propagator.
Definition: rel.hh:493
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: eq.hpp:206
Reified binary bounds consistent equality propagator.
Definition: rel.hh:372
n-ary propagator
Definition: pattern.hpp:142
virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d)
Advise function.
Definition: core.cpp:67
View arrays.
Definition: array.hpp:224
ViewArray< VY > y
Views not yet subscribed to.
Definition: rel.hh:674
n-ary less and less or equal propagator
Definition: rel.hh:230
Reified bounds consistent equality with integer propagator.
Definition: rel.hh:425
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
Mixed binary propagator.
Definition: pattern.hpp:204
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
Lexical ordering propagator.
Definition: rel.hh:627
Propagation cost.
Definition: core.hpp:485
ExecStatus
Definition: core.hpp:471
Base-class for freelist-managed objects.
Definition: manager.hpp:98
bool strict
Determines whether propagator is strict or not.
Definition: rel.hh:633
Binary disequality propagator.
Definition: rel.hh:460
Post propagator for SetVar x
Definition: set.hh:765
ViewArray< VX > x
View arrays.
Definition: rel.hh:630
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: eq.hpp:212
Positions in view array that have to be propagated.
Definition: rel.hh:246
n-ary bounds consistent equality propagator
Definition: rel.hh:196
int i
The position of the view in the view array.
Definition: rel.hh:237
Gecode toplevel namespace
Advisors for views (by position in array)
Definition: rel.hh:234
Less propagator.
Definition: rel.hh:519
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Reified domain consistent equality with integer propagator.
Definition: rel.hh:398
Home class for posting propagators
Definition: core.hpp:853
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: pattern.hpp:630
VY y0
View currently subscribed to.
Definition: rel.hh:666
Pos * pos
Stack of positions.
Definition: rel.hh:277