Generated on Fri Jan 10 2020 11:38:25 for Gecode by doxygen 1.8.16
distinct.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_DISTINCT_HH__
41 #define __GECODE_INT_DISTINCT_HH__
42 
43 #include <gecode/int.hh>
44 
46 #include <gecode/int/rel.hh>
47 
53 namespace Gecode { namespace Int { namespace Distinct {
54 
63  template<class View>
64  class Val : public NaryPropagator<View,PC_INT_VAL> {
65  protected:
67 
69  Val(Home home, ViewArray<View>& x);
71  Val(Space& home, Val<View>& p);
72  public:
73 #ifdef GECODE_HAS_CBS
74  virtual void solndistrib(Space& home, Propagator::SendMarginal send) const;
77  virtual void domainsizesum(Propagator::InDecision in,
78  unsigned int& size, unsigned int& size_b) const;
79 #endif
80  virtual Actor* copy(Space& home);
83  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
85  static ExecStatus post(Home home, ViewArray<View>& x);
86  };
87 
88 #ifdef GECODE_HAS_CBS
89 
99  template<class View>
100  void cbsdistinct(Space& home, unsigned int prop_id, const ViewArray<View>& x,
101  Propagator::SendMarginal send);
102 
103  template<class View>
104  void cbssize(const ViewArray<View>& x, Propagator::InDecision in,
105  unsigned int& size, unsigned int& size_b);
106 #endif
107 
121  template<class View, bool complete>
123 
124 
125 
151  template<class View>
152  class Bnd : public Propagator {
153  protected:
159  int min_x;
161  int max_x;
163  Bnd(Home home, ViewArray<View>& x);
165  Bnd(Space& home, Bnd<View>& p);
166  public:
167 #ifdef GECODE_HAS_CBS
168  virtual void solndistrib(Space& home, Propagator::SendMarginal send) const;
171  virtual void domainsizesum(Propagator::InDecision in,
172  unsigned int& size, unsigned int& size_b) const;
173 #endif
174  static ExecStatus post(Home home, ViewArray<View>& x);
177  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
184  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
186  virtual void reschedule(Space& home);
188  virtual Actor* copy(Space& home);
190  virtual size_t dispose(Space& home);
191  };
192 
201  template<class View>
202  ExecStatus prop_bnd(Space& home, ViewArray<View>& x, int& min_x, int& max_x);
203 
212  template<class View>
214 
215 
217  template<class View>
218  class Graph : public ViewValGraph::Graph<View> {
219  public:
228  Graph(void);
232  bool mark(void);
234  ExecStatus prune(Space& home, bool& assigned);
236  bool sync(void);
237  };
238 
249  template<class View>
250  class DomCtrl {
251  protected:
254  public:
256  DomCtrl(void);
258  bool available(void);
262  ExecStatus sync(void);
264  ExecStatus propagate(Space& home, bool& assigned);
265  };
266 
282  template<class View>
283  class Dom : public NaryPropagator<View,PC_INT_DOM> {
284  protected:
289  Dom(Space& home, Dom<View>& p);
291  Dom(Home home, ViewArray<View>& x);
292  public:
293 #ifdef GECODE_HAS_CBS
294  virtual void solndistrib(Space& home, Propagator::SendMarginal send) const;
297  virtual void domainsizesum(Propagator::InDecision in,
298  unsigned int& size, unsigned int& size_b) const;
299 #endif
300  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
308  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
310  virtual Actor* copy(Space& home);
312  static ExecStatus post(Home home, ViewArray<View>& x);
313  };
314 
321  template<class View>
322  class TerDom : public TernaryPropagator<View,PC_INT_DOM> {
323  protected:
327 
329  TerDom(Space& home, TerDom<View>& p);
331  TerDom(Home home, View x0, View x1, View x2);
332  public:
334  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
336  virtual Actor* copy(Space& home);
338  static ExecStatus post(Home home, View x0, View x1, View x2);
339  };
340 
349  class EqIte : public BinaryPropagator<IntView,PC_INT_DOM> {
350  protected:
354  int c0, c1;
356  EqIte(Space& home, EqIte& p);
358  EqIte(Home home, IntView x0, IntView x1, int c0, int c1);
359  public:
362  virtual Actor* copy(Space& home);
365  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
368  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
370  static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1);
371  };
372 
373 }}}
374 
383 
384 #endif
385 
386 // STATISTICS: int-prop
387 
Val(Home home, ViewArray< View > &x)
Constructor for posting.
Definition: val.hpp:147
TerDom(Space &home, TerDom< View > &p)
Constructor for cloning p.
Definition: ter-dom.hpp:56
Post propagator for SetVar x
Definition: set.hh:767
View-value graph base class.
Graph(void)
Construct graph as not yet initialized.
Definition: graph.hpp:40
Bnd(Home home, ViewArray< View > &x)
Constructor for posting.
Definition: bnd.hpp:38
size_t size
The size of the propagator (used during subsumption)
Definition: core.hpp:1077
Dom(Space &home, Dom< View > &p)
Constructor for cloning p.
Definition: dom.hpp:60
View x1
Definition: pattern.hpp:116
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition: ter-dom.hpp:49
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: val.hpp:172
int c1
Definition: distinct.hh:354
ExecStatus init(Space &home, ViewArray< View > &x)
Initialize view-value graph for views x.
Definition: dom-ctrl.hpp:55
Bounds consistent distinct propagator.
Definition: distinct.hh:152
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition: dom.hpp:45
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition: bnd.hpp:476
unsigned int size(I &i)
Size of all ranges of range iterator i.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: bnd.hpp:381
ExecStatus prop_bnd(Space &home, ViewArray< View > &x, int *minsorted, int *maxsorted)
Definition: bnd.hpp:197
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
EqIte(Space &home, EqIte &p)
Constructor for cloning p.
Definition: eqite.hpp:43
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition: eqite.cpp:41
Computation spaces.
Definition: core.hpp:1742
Base-class for both propagators and branchers.
Definition: core.hpp:628
static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1)
Post if-then-else propagator.
Definition: eqite.hpp:49
ViewArray< View > x
Array of views.
Definition: pattern.hpp:145
DomCtrl< View > dc
Propagation controller.
Definition: distinct.hh:287
virtual size_t dispose(Space &home)
Destructor.
Definition: bnd.hpp:56
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: eqite.cpp:51
View x2
Definition: pattern.hpp:116
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
ExecStatus prop_val(Space &home, ViewArray< View > &x)
Eliminate singletons by naive value propagation.
Definition: val.hpp:42
Propagation controller for domain consistent distinct.
Definition: distinct.hh:250
DomCtrl(void)
Initialize with non-initialized view-value graph.
Definition: dom-ctrl.hpp:45
bool sync(void)
Synchronize graph with new view domains.
Definition: graph.hpp:112
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ter-dom.hpp:93
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: ter-dom.hpp:61
ExecStatus sync(void)
Synchronize available view-value graph.
Definition: dom-ctrl.hpp:61
#define GECODE_INT_EXPORT
Definition: int.hh:81
Ternary domain consistent distinct propagator.
Definition: distinct.hh:322
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: val.hpp:178
Equal-if-then-else domain-consistent propagator.
Definition: distinct.hh:349
Home class for posting propagators
Definition: core.hpp:856
Ternary propagator.
Definition: pattern.hpp:113
n-ary propagator
Definition: pattern.hpp:142
IntView x1
Definition: pattern.hpp:87
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: dom.hpp:65
View x0
Three views.
Definition: pattern.hpp:116
int min_x
Minimum (approximation) of view in x.
Definition: distinct.hh:159
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1075
int c0
The integer constant.
Definition: distinct.hh:354
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: dom.hpp:96
virtual void reschedule(Space &home)
Schedule function.
Definition: bnd.hpp:87
Domain consistent distinct propagator.
Definition: distinct.hh:283
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: dom.hpp:74
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: bnd.hpp:78
ViewArray< View > y
Views on which to perform value-propagation (subset of x)
Definition: distinct.hh:157
Propagation cost.
Definition: core.hpp:486
ExecStatus prune(Space &home, bool &assigned)
Prune unmarked edges, assigned is true if a view got assigned.
Definition: graph.hpp:240
View-value graph for propagation.
Definition: distinct.hh:218
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition: val.hpp:185
Integer view for integer variables.
Definition: view.hpp:129
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: bnd.hpp:72
int max_x
Maximum (approximation) of view in x.
Definition: distinct.hh:161
ExecStatus propagate(Space &home, bool &assigned)
Perform propagation, assigned is true if a view gets assigned.
Definition: dom-ctrl.hpp:68
Graph< View > g
Propagation is performed on a view-value graph.
Definition: distinct.hh:253
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: eqite.cpp:46
View arrays.
Definition: array.hpp:253
Binary propagator.
Definition: pattern.hpp:84
ViewArray< View > x
Views on which to perform bounds-propagation.
Definition: distinct.hh:155
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
ExecStatus init(Space &home, ViewArray< View > &x)
Initialize graph.
Definition: graph.hpp:44
IntView x0
Two views.
Definition: pattern.hpp:87
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
bool mark(void)
Mark edges in graph, return true if pruning is at all possible.
Definition: graph.hpp:176
bool available(void)
Check whether a view-value graph is available.
Definition: dom-ctrl.hpp:49
ExecStatus
Definition: core.hpp:472
Naive value distinct propagator.
Definition: distinct.hh:64