Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
46namespace Gecode { namespace Int { namespace Count {
47
54 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>
80 template<class VX>
83 template<class VX>
84 RelTest holds(VX x, const IntSet& y);
85
87 template<class VX>
90 template<class VX>
93 template<class VX>
96 template<class VX>
98
100 template<class VX>
103 template<class VX>
106 template<class VX>
109 template<class VX>
111
113 template<class VX>
116 template<class VX>
119 template<class VX>
122 template<class VX>
125
126}}}
127
129
130
131namespace 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
259namespace 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;
315 using ViewBase<VX,VY,VZ>::count;
316 using ViewBase<VX,VY,VZ>::atleast;
317 using ViewBase<VX,VY,VZ>::atmost;
318 using ViewBase<VX,VY,VZ>::sharing;
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;
350 using ViewBase<VX,VY,VZ>::count;
351 using ViewBase<VX,VY,VZ>::atleast;
352 using ViewBase<VX,VY,VZ>::atmost;
353 using ViewBase<VX,VY,VZ>::sharing;
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;
385 using ViewBase<VX,VY,VZ>::count;
386 using ViewBase<VX,VY,VZ>::atleast;
387 using ViewBase<VX,VY,VZ>::atmost;
388 using ViewBase<VX,VY,VZ>::sharing;
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
int p
Number of positive literals for node type.
Base-class for both propagators and branchers.
Definition core.hpp:628
Home class for posting propagators
Definition core.hpp:856
Integer sets.
Definition int.hh:174
Constant integer view.
Definition view.hpp:851
Propagator for counting views (equal integer to number of equal views)
Definition count.hh:172
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-eq.hpp:87
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-eq.hpp:81
EqInt(Space &home, EqInt &p)
Constructor for cloning p.
Definition int-eq.hpp:76
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition int-eq.hpp:43
Propagator for counting views (equal to number of equal views)
Definition count.hh:309
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, VZ z, int c)
Post propagator for .
Definition view-eq.hpp:44
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view-eq.hpp:70
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition view-eq.hpp:64
EqView(Space &home, EqView &p)
Constructor for cloning p.
Definition view-eq.hpp:59
Propagator for counting views (greater or equal integer to number of equal views)
Definition count.hh:202
GqInt(Space &home, GqInt &p)
Constructor for cloning p.
Definition int-gq.hpp:73
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition int-gq.hpp:43
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-gq.hpp:84
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-gq.hpp:78
Propagator for counting views (greater or equal to number of equal views)
Definition count.hh:379
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view-gq.hpp:68
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, VZ z, int c)
Post propagator for .
Definition view-gq.hpp:43
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition view-gq.hpp:62
GqView(Space &home, GqView &p)
Constructor for cloning p.
Definition view-gq.hpp:57
Baseclass for count propagators (integer)
Definition count.hh:138
IntBase(Space &home, IntBase &p)
Constructor for cloning p.
Definition int-base.hpp:62
int n_s
Views from x[0] ... x[n_s-1] have subscriptions.
Definition count.hh:143
ViewArray< VX > x
Views still to count.
Definition count.hh:141
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low linear)
Definition int-base.hpp:70
int c
Number of views which are equal and have been eliminated.
Definition count.hh:147
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition int-base.hpp:50
VY y
View to compare to.
Definition count.hh:145
virtual void reschedule(Space &home)
Schedule function.
Definition int-base.hpp:76
Propagator for counting views (less or equal integer to number of equal views)
Definition count.hh:232
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition int-lq.hpp:43
LqInt(Space &home, LqInt &p)
Constructor for cloning p.
Definition int-lq.hpp:71
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition int-lq.hpp:76
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int-lq.hpp:82
Propagator for counting views (less or equal to number of equal views)
Definition count.hh:344
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, VZ z, int c)
Post propagator for .
Definition view-lq.hpp:44
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition view-lq.hpp:63
LqView(Space &home, LqView &p)
Constructor for cloning p.
Definition view-lq.hpp:58
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view-lq.hpp:69
Base-class for count propagators (view)
Definition count.hh:266
int atleast(void) const
How many views are at least equal.
ViewArray< VX > x
Views still to count.
Definition count.hh:269
void count(Space &home)
Count how many views are equal now.
Definition view-base.hpp:85
virtual void reschedule(Space &home)
Schedule function.
Definition view-base.hpp:65
VZ z
View which yields result of counting.
Definition count.hh:273
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition view-base.hpp:73
int atmost(void) const
How many views are at most equal.
int c
Number of views which are equal and have been eliminated.
Definition count.hh:275
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low linear)
Definition view-base.hpp:59
VY y
View to compare to.
Definition count.hh:271
ViewBase(Space &home, ViewBase &p)
Constructor for cloning p.
Definition view-base.hpp:50
static bool sharing(const ViewArray< VX > &x, const VY &y, const VZ &z)
Test whether there is sharing of z with x or y.
Zero integer view.
Definition view.hpp:1014
Propagation cost.
Definition core.hpp:486
Base-class for propagators.
Definition core.hpp:1064
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1075
Computation spaces.
Definition core.hpp:1742
View arrays.
Definition array.hpp:253
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
void cancel(Space &home, Propagator &p, VY y)
Cancel propagator p for view y.
Definition rel.hpp:87
void update(VY &y, Space &home, bool shared, VY py)
Update view y from py.
ExecStatus prune(Home home, ViewArray< VX > &x, VX y)
Prune that y is the union of x.
bool isval(VY y)
Return whether y is a value.
Definition rel.hpp:59
ExecStatus post_false(Home home, ViewArray< VX > &x, VX y)
Post that all views in x are not equal to y.
Definition rel.hpp:251
ExecStatus post_true(Home home, ViewArray< VX > &x, VX y)
Post that all views in x are equal to y.
Definition rel.hpp:237
bool isintset(VY y)
Return whether y is an integer set.
Definition rel.hpp:45
void subscribe(Space &home, Propagator &p, VY y)
Subscribe propagator p to view y.
Definition rel.hpp:76
void reschedule(Space &home, Propagator &p, VY y)
Schedule propagator p for view y.
Definition rel.hpp:97
bool shared(const IntSet &, VX)
RelTest holds(VX x, VX y)
Test whether x and y are equal.
Definition rel.hpp:145
RelTest
Result of testing relation.
Definition view.hpp:1734
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:767
ExecStatus
Definition core.hpp:472
Post propagator for SetVar x
Definition set.hh:767