Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
count.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  * Copyright:
8  * Christian Schulte, 2002
9  * Guido Tack, 2004
10  *
11  * Last modified:
12  * $Date$ by $Author$
13  * $Revision$
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_COUNT_HH__
41 #define __GECODE_INT_COUNT_HH__
42 
43 #include <gecode/int.hh>
44 
50 namespace Gecode { namespace Int { namespace Count {
51 
57  template<class VY>
59  bool isintset(VY y);
61  template<class VY>
62  bool isval(VY y);
63 
65  template<class VY>
66  void subscribe(Space& home, Propagator& p, VY y);
68  template<class VY>
69  void cancel(Space& home, Propagator& p, VY y);
71  template<class VY>
72  void reschedule(Space& home, Propagator& p, VY y);
74  template<class VY>
75  void update(VY& y, Space& home, bool shared, VY py);
76 
78  template<class VX>
79  RelTest holds(VX x, VX y);
81  template<class VX>
82  RelTest holds(VX x, ConstIntView y);
84  template<class VX>
85  RelTest holds(VX x, ZeroIntView y);
87  template<class VX>
88  RelTest holds(VX x, const IntSet& y);
89 
91  template<class VX>
92  ExecStatus post_true(Home home, ViewArray<VX>& x, VX y);
94  template<class VX>
95  ExecStatus post_true(Home home, ViewArray<VX>& x, ConstIntView y);
97  template<class VX>
98  ExecStatus post_true(Home home, ViewArray<VX>& x, ZeroIntView y);
100  template<class VX>
101  ExecStatus post_true(Home home, ViewArray<VX>& x, const IntSet& y);
102 
104  template<class VX>
105  ExecStatus post_false(Home home, ViewArray<VX>& x, VX y);
107  template<class VX>
108  ExecStatus post_false(Home home, ViewArray<VX>& x, ConstIntView y);
110  template<class VX>
111  ExecStatus post_false(Home home, ViewArray<VX>& x, ZeroIntView y);
113  template<class VX>
114  ExecStatus post_false(Home home, ViewArray<VX>& x, const IntSet& y);
115 
117  template<class VX>
118  ExecStatus prune(Home home, ViewArray<VX>& x, VX y);
120  template<class VX>
121  ExecStatus prune(Home home, ViewArray<VX>& x, ConstIntView y);
123  template<class VX>
124  ExecStatus prune(Home home, ViewArray<VX>& x, ZeroIntView y);
126  template<class VX>
127  ExecStatus prune(Home home, ViewArray<VX>& x, const IntSet& y);
129 
130 }}}
131 
132 #include <gecode/int/count/rel.hpp>
133 
134 
135 namespace Gecode { namespace Int { namespace Count {
136 
141  template<class VX, class VY>
142  class IntBase : public Propagator {
143  protected:
147  int n_s;
149  VY y;
151  int c;
153  IntBase(Space& home, IntBase& p);
155  IntBase(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
156  public:
158  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
160  virtual void reschedule(Space& home);
162  virtual size_t dispose(Space& home);
163  };
164 
175  template<class VX, class VY>
176  class EqInt : public IntBase<VX,VY> {
177  protected:
178  using IntBase<VX,VY>::x;
179  using IntBase<VX,VY>::n_s;
180  using IntBase<VX,VY>::y;
181  using IntBase<VX,VY>::c;
183  EqInt(Space& home, EqInt& p);
185  EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
186  public:
188  virtual Actor* copy(Space& home);
190  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
192  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
193  };
194 
205  template<class VX, class VY>
206  class GqInt : public IntBase<VX,VY> {
207  protected:
208  using IntBase<VX,VY>::x;
209  using IntBase<VX,VY>::n_s;
210  using IntBase<VX,VY>::y;
211  using IntBase<VX,VY>::c;
213  GqInt(Space& home, GqInt& p);
215  GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
216  public:
218  virtual Actor* copy(Space& home);
220  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
222  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
223  };
224 
235  template<class VX, class VY>
236  class LqInt : public IntBase<VX,VY> {
237  protected:
238  using IntBase<VX,VY>::x;
239  using IntBase<VX,VY>::n_s;
240  using IntBase<VX,VY>::y;
241  using IntBase<VX,VY>::c;
243  LqInt(Space& home, LqInt& p);
245  LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
246  public:
248  virtual Actor* copy(Space& home);
250  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
252  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
253  };
254 
255 }}}
256 
261 
262 
263 namespace Gecode { namespace Int { namespace Count {
264 
269  template<class VX, class VY, class VZ>
270  class ViewBase : public Propagator {
271  protected:
275  VY y;
277  VZ z;
279  int c;
281  ViewBase(Space& home, ViewBase& p);
283  ViewBase(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
284  public:
286  virtual size_t dispose(Space& home);
288  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
290  virtual void reschedule(Space& home);
291  protected:
293  void count(Space& home);
295  int atleast(void) const;
297  int atmost(void) const;
299  static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
300  };
301 
312  template<class VX, class VY, class VZ, bool shr, bool dom>
313  class EqView : public ViewBase<VX,VY,VZ> {
314  protected:
315  using ViewBase<VX,VY,VZ>::x;
316  using ViewBase<VX,VY,VZ>::z;
317  using ViewBase<VX,VY,VZ>::c;
318  using ViewBase<VX,VY,VZ>::y;
323 
325  EqView(Space& home, EqView& p);
326  public:
328  EqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
330  virtual Actor* copy(Space& home);
332  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
334  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
335  };
336 
347  template<class VX, class VY, class VZ, bool shr>
348  class LqView : public ViewBase<VX,VY,VZ> {
349  protected:
350  using ViewBase<VX,VY,VZ>::x;
351  using ViewBase<VX,VY,VZ>::z;
352  using ViewBase<VX,VY,VZ>::c;
353  using ViewBase<VX,VY,VZ>::y;
358 
360  LqView(Space& home, LqView& p);
361  public:
363  LqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
365  virtual Actor* copy(Space& home);
367  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
369  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
370  };
371 
382  template<class VX, class VY, class VZ, bool shr, bool dom>
383  class GqView : public ViewBase<VX,VY,VZ> {
384  protected:
385  using ViewBase<VX,VY,VZ>::x;
386  using ViewBase<VX,VY,VZ>::z;
387  using ViewBase<VX,VY,VZ>::c;
388  using ViewBase<VX,VY,VZ>::y;
393 
395  GqView(Space& home, GqView& p);
396  public:
398  GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
400  virtual Actor* copy(Space& home);
402  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
404  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
405  };
406 
407 }}}
408 
413 
414 #endif
415 
416 // STATISTICS: int-prop
417 
VY y
View to compare to.
Definition: count.hh:149
ViewArray< VX > x
Views still to count.
Definition: count.hh:145
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
Definition: count.cpp:44
int n_s
Views from x[0] ... x[n_s-1] have subscriptions.
Definition: count.hh:147
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
VZ z
View which yields result of counting.
Definition: count.hh:277
Base-class for count propagators (view)
Definition: count.hh:270
void atmost(Home home, const IntVarArgs &x, int n, int m, IntPropLevel ipl=IPL_DEF)
Post constraint .
Definition: minimodel.hh:1803
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:119
Base-class for propagators.
Definition: core.hpp:1016
Baseclass for count propagators (integer)
Definition: count.hh:142
bool isval(VY y)
Return whether y is a value.
Definition: rel.hpp:63
Propagator for counting views (equal to number of equal views)
Definition: count.hh:313
Computation spaces.
Definition: core.hpp:1668
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:268
bool shared(const IntSet &, VX)
Definition: view-base.hpp:122
Base-class for both propagators and branchers.
Definition: core.hpp:620
void atleast(Home home, const IntVarArgs &x, int n, int m, IntPropLevel ipl=IPL_DEF)
Post constraint .
Definition: minimodel.hh:1864
Propagator for counting views (less or equal integer to number of equal views)
Definition: count.hh:236
Propagator for counting views (greater or equal to number of equal views)
Definition: count.hh:383
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
VY y
View to compare to.
Definition: count.hh:275
Propagator for counting views (equal integer to number of equal views)
Definition: count.hh:176
ViewArray< VX > x
Views still to count.
Definition: count.hh:273
int c
Number of views which are equal and have been eliminated.
Definition: count.hh:279
RelTest
Result of testing relation.
Definition: view.hpp:1632
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
Propagator for counting views (less or equal to number of equal views)
Definition: count.hh:348
int c
Number of views which are equal and have been eliminated.
Definition: count.hh:151
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:769
Propagator for counting views (greater or equal integer to number of equal views) ...
Definition: count.hh:206
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Propagation cost.
Definition: core.hpp:478
ExecStatus
Definition: core.hpp:464
Post propagator for SetVar x
Definition: set.hh:769
bool isintset(VY y)
Return whether y is an integer set.
Definition: rel.hpp:49
Gecode toplevel namespace
ExecStatus post_false(Home home, VX x, ConstIntView y)
Definition: rel.hpp:198
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
Home class for posting propagators
Definition: core.hpp:846
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:107
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:142
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:155