Generated on Tue Jan 19 2021 06:15:49 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  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 #ifndef __GECODE_INT_COUNT_HH__
37 #define __GECODE_INT_COUNT_HH__
38 
39 #include <gecode/int.hh>
40 
46 namespace Gecode { namespace Int { namespace Count {
47 
53  template<class VY>
55  bool isintset(VY y);
57  template<class VY>
58  bool isval(VY y);
59 
61  template<class VY>
62  void subscribe(Space& home, Propagator& p, VY y);
64  template<class VY>
65  void cancel(Space& home, Propagator& p, VY y);
67  template<class VY>
68  void reschedule(Space& home, Propagator& p, VY y);
70  template<class VY>
71  void update(VY& y, Space& home, bool shared, VY py);
72 
74  template<class VX>
75  RelTest holds(VX x, VX y);
77  template<class VX>
78  RelTest holds(VX x, ConstIntView y);
80  template<class VX>
81  RelTest holds(VX x, ZeroIntView y);
83  template<class VX>
84  RelTest holds(VX x, const IntSet& y);
85 
87  template<class VX>
88  ExecStatus post_true(Home home, ViewArray<VX>& x, VX y);
90  template<class VX>
91  ExecStatus post_true(Home home, ViewArray<VX>& x, ConstIntView y);
93  template<class VX>
94  ExecStatus post_true(Home home, ViewArray<VX>& x, ZeroIntView y);
96  template<class VX>
97  ExecStatus post_true(Home home, ViewArray<VX>& x, const IntSet& y);
98 
100  template<class VX>
101  ExecStatus post_false(Home home, ViewArray<VX>& x, VX y);
103  template<class VX>
104  ExecStatus post_false(Home home, ViewArray<VX>& x, ConstIntView y);
106  template<class VX>
107  ExecStatus post_false(Home home, ViewArray<VX>& x, ZeroIntView y);
109  template<class VX>
110  ExecStatus post_false(Home home, ViewArray<VX>& x, const IntSet& y);
111 
113  template<class VX>
114  ExecStatus prune(Home home, ViewArray<VX>& x, VX y);
116  template<class VX>
117  ExecStatus prune(Home home, ViewArray<VX>& x, ConstIntView y);
119  template<class VX>
120  ExecStatus prune(Home home, ViewArray<VX>& x, ZeroIntView y);
122  template<class VX>
123  ExecStatus prune(Home home, ViewArray<VX>& x, const IntSet& y);
125 
126 }}}
127 
128 #include <gecode/int/count/rel.hpp>
129 
130 
131 namespace Gecode { namespace Int { namespace Count {
132 
137  template<class VX, class VY>
138  class IntBase : public Propagator {
139  protected:
143  int n_s;
145  VY y;
147  int c;
149  IntBase(Space& home, IntBase& p);
151  IntBase(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
152  public:
154  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
156  virtual void reschedule(Space& home);
158  virtual size_t dispose(Space& home);
159  };
160 
171  template<class VX, class VY>
172  class EqInt : public IntBase<VX,VY> {
173  protected:
174  using IntBase<VX,VY>::x;
175  using IntBase<VX,VY>::n_s;
176  using IntBase<VX,VY>::y;
177  using IntBase<VX,VY>::c;
179  EqInt(Space& home, EqInt& p);
181  EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
182  public:
184  virtual Actor* copy(Space& home);
186  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
188  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
189  };
190 
201  template<class VX, class VY>
202  class GqInt : public IntBase<VX,VY> {
203  protected:
204  using IntBase<VX,VY>::x;
205  using IntBase<VX,VY>::n_s;
206  using IntBase<VX,VY>::y;
207  using IntBase<VX,VY>::c;
209  GqInt(Space& home, GqInt& p);
211  GqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
212  public:
214  virtual Actor* copy(Space& home);
216  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
218  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
219  };
220 
231  template<class VX, class VY>
232  class LqInt : public IntBase<VX,VY> {
233  protected:
234  using IntBase<VX,VY>::x;
235  using IntBase<VX,VY>::n_s;
236  using IntBase<VX,VY>::y;
237  using IntBase<VX,VY>::c;
239  LqInt(Space& home, LqInt& p);
241  LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c);
242  public:
244  virtual Actor* copy(Space& home);
246  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
248  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, int c);
249  };
250 
251 }}}
252 
257 
258 
259 namespace Gecode { namespace Int { namespace Count {
260 
265  template<class VX, class VY, class VZ>
266  class ViewBase : public Propagator {
267  protected:
271  VY y;
273  VZ z;
275  int c;
277  ViewBase(Space& home, ViewBase& p);
279  ViewBase(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
280  public:
282  virtual size_t dispose(Space& home);
284  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
286  virtual void reschedule(Space& home);
287  protected:
289  void count(Space& home);
291  int atleast(void) const;
293  int atmost(void) const;
295  static bool sharing(const ViewArray<VX>& x, const VY& y, const VZ& z);
296  };
297 
308  template<class VX, class VY, class VZ, bool shr, bool dom>
309  class EqView : public ViewBase<VX,VY,VZ> {
310  protected:
311  using ViewBase<VX,VY,VZ>::x;
312  using ViewBase<VX,VY,VZ>::z;
313  using ViewBase<VX,VY,VZ>::c;
314  using ViewBase<VX,VY,VZ>::y;
319 
321  EqView(Space& home, EqView& p);
322  public:
324  EqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
326  virtual Actor* copy(Space& home);
328  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
330  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
331  };
332 
343  template<class VX, class VY, class VZ, bool shr>
344  class LqView : public ViewBase<VX,VY,VZ> {
345  protected:
346  using ViewBase<VX,VY,VZ>::x;
347  using ViewBase<VX,VY,VZ>::z;
348  using ViewBase<VX,VY,VZ>::c;
349  using ViewBase<VX,VY,VZ>::y;
354 
356  LqView(Space& home, LqView& p);
357  public:
359  LqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
361  virtual Actor* copy(Space& home);
363  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
365  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
366  };
367 
378  template<class VX, class VY, class VZ, bool shr, bool dom>
379  class GqView : public ViewBase<VX,VY,VZ> {
380  protected:
381  using ViewBase<VX,VY,VZ>::x;
382  using ViewBase<VX,VY,VZ>::z;
383  using ViewBase<VX,VY,VZ>::c;
384  using ViewBase<VX,VY,VZ>::y;
389 
391  GqView(Space& home, GqView& p);
392  public:
394  GqView(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
396  virtual Actor* copy(Space& home);
398  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
400  static ExecStatus post(Home home, ViewArray<VX>& x, VY y, VZ z, int c);
401  };
402 
403 }}}
404 
409 
410 #endif
411 
412 // STATISTICS: int-prop
413 
VY y
View to compare to.
Definition: count.hh:145
ViewArray< VX > x
Views still to count.
Definition: count.hh:141
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel)
Post propagator for .
Definition: count.cpp:40
int n_s
Views from x[0] ... x[n_s-1] have subscriptions.
Definition: count.hh:143
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
VZ z
View which yields result of counting.
Definition: count.hh:273
Base-class for count propagators (view)
Definition: count.hh:266
void atmost(Home home, const IntVarArgs &x, int n, int m, IntPropLevel ipl=IPL_DEF)
Post constraint .
Definition: minimodel.hh:1799
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:115
Base-class for propagators.
Definition: core.hpp:1023
Baseclass for count propagators (integer)
Definition: count.hh:138
bool isval(VY y)
Return whether y is a value.
Definition: rel.hpp:59
Propagator for counting views (equal to number of equal views)
Definition: count.hh:309
Computation spaces.
Definition: core.hpp:1701
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:264
bool shared(const IntSet &, VX)
Definition: view-base.hpp:118
Base-class for both propagators and branchers.
Definition: core.hpp:627
void atleast(Home home, const IntVarArgs &x, int n, int m, IntPropLevel ipl=IPL_DEF)
Post constraint .
Definition: minimodel.hh:1860
Propagator for counting views (less or equal integer to number of equal views)
Definition: count.hh:232
Propagator for counting views (greater or equal to number of equal views)
Definition: count.hh:379
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
VY y
View to compare to.
Definition: count.hh:271
Propagator for counting views (equal integer to number of equal views)
Definition: count.hh:172
ViewArray< VX > x
Views still to count.
Definition: count.hh:269
int c
Number of views which are equal and have been eliminated.
Definition: count.hh:275
RelTest
Result of testing relation.
Definition: view.hpp:1701
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
Propagator for counting views (less or equal to number of equal views)
Definition: count.hh:344
int c
Number of views which are equal and have been eliminated.
Definition: count.hh:147
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
Propagator for counting views (greater or equal integer to number of equal views) ...
Definition: count.hh:202
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Propagation cost.
Definition: core.hpp:485
ExecStatus
Definition: core.hpp:471
Post propagator for SetVar x
Definition: set.hh:767
bool isintset(VY y)
Return whether y is an integer set.
Definition: rel.hpp:45
Gecode toplevel namespace
ExecStatus post_false(Home home, VX x, ConstIntView y)
Definition: rel.hpp:194
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Home class for posting propagators
Definition: core.hpp:853
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:151