Generated on Thu Jan 31 2019 20:56:36 for Gecode by doxygen 1.8.15
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  * Last modified:
16  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
17  * $Revision: 15137 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #ifndef __GECODE_INT_DISTINCT_HH__
45 #define __GECODE_INT_DISTINCT_HH__
46 
47 #include <gecode/int.hh>
48 
50 #include <gecode/int/rel.hh>
51 
57 namespace Gecode { namespace Int { namespace Distinct {
58 
67  template<class View>
68  class Val : public NaryPropagator<View,PC_INT_VAL> {
69  protected:
71 
73  Val(Home home, ViewArray<View>& x);
75  Val(Space& home, bool share, Val<View>& p);
76  public:
78  virtual Actor* copy(Space& home, bool share);
80  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
82  static ExecStatus post(Home home, ViewArray<View>& x);
83  };
84 
98  template<class View, bool complete>
100 
101 
102 
128  template<class View>
129  class Bnd : public Propagator {
130  protected:
136  int min_x;
138  int max_x;
140  Bnd(Home home, ViewArray<View>& x);
142  Bnd(Space& home, bool share, Bnd<View>& p);
143  public:
145  static ExecStatus post(Home home, ViewArray<View>& x);
147  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
154  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
156  virtual void reschedule(Space& home);
158  virtual Actor* copy(Space& home, bool share);
160  virtual size_t dispose(Space& home);
161  };
162 
171  template<class View>
172  ExecStatus prop_bnd(Space& home, ViewArray<View>& x, int& min_x, int& max_x);
173 
182  template<class View>
184 
185 
187  template<class View>
188  class Graph : public ViewValGraph::Graph<View> {
189  public:
198  Graph(void);
202  bool mark(Space& home);
204  ExecStatus prune(Space& home, bool& assigned);
206  bool sync(Space& home);
207  };
208 
219  template<class View>
220  class DomCtrl {
221  protected:
224  public:
226  DomCtrl(void);
228  bool available(void);
232  ExecStatus sync(Space& home);
234  ExecStatus propagate(Space& home, bool& assigned);
235  };
236 
252  template<class View>
253  class Dom : public NaryPropagator<View,PC_INT_DOM> {
254  protected:
259  Dom(Space& home, bool share, Dom<View>& p);
261  Dom(Home home, ViewArray<View>& x);
262  public:
264  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
271  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
273  virtual Actor* copy(Space& home, bool share);
275  static ExecStatus post(Home home, ViewArray<View>& x);
276  };
277 
284  template<class View>
285  class TerDom : public TernaryPropagator<View,PC_INT_DOM> {
286  protected:
290 
292  TerDom(Space& home, bool share, TerDom<View>& p);
294  TerDom(Home home, View x0, View x1, View x2);
295  public:
297  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
299  virtual Actor* copy(Space& home, bool share);
301  static ExecStatus post(Home home, View x0, View x1, View x2);
302  };
303 
312  class EqIte : public BinaryPropagator<IntView,PC_INT_DOM> {
313  protected:
317  int c0, c1;
319  EqIte(Space& home, bool share, EqIte& p);
321  EqIte(Home home, IntView x0, IntView x1, int c0, int c1);
322  public:
325  virtual Actor* copy(Space& home, bool share);
328  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, IntView x0, IntView x1, int c0, int c1);
334  };
335 
336 }}}
337 
345 
346 #endif
347 
348 // STATISTICS: int-prop
349 
bool mark(Space &home)
Mark edges in graph, return true if pruning is at all possible.
Definition: graph.hpp:178
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition: ter-dom.hpp:53
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: val.hpp:167
DomCtrl< View > dc
Propagation controller.
Definition: distinct.hh:257
int min_x
Minimum (approximation) of view in x.
Definition: distinct.hh:136
ViewArray< View > x
Views on which to perform bounds-propagation.
Definition: distinct.hh:132
Dom(Space &home, bool share, Dom< View > &p)
Constructor for cloning p.
Definition: dom.hpp:64
ExecStatus init(Space &home, ViewArray< View > &x)
Initialize view-value graph for views x.
Definition: dom-ctrl.hpp:59
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: bnd.hpp:82
Val(Home home, ViewArray< View > &x)
Constructor for posting.
Definition: val.hpp:151
View-value graph for propagation.
Definition: distinct.hh:188
TerDom(Space &home, bool share, TerDom< View > &p)
Constructor for cloning p.
Definition: ter-dom.hpp:60
static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1)
Post if-then-else propagator.
Definition: eqite.hpp:53
Domain consistent distinct propagator.
Definition: distinct.hh:253
ViewArray< View > x
Array of views.
Definition: propagator.hpp:152
Base-class for propagators.
Definition: core.hpp:1092
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition: dom.hpp:49
ExecStatus prune(Space &home, bool &assigned)
Prune unmarked edges, assigned is true if a view got assigned.
Definition: graph.hpp:242
EqIte(Space &home, bool share, EqIte &p)
Constructor for cloning p.
Definition: eqite.hpp:47
Bnd(Home home, ViewArray< View > &x)
Constructor for posting.
Definition: bnd.hpp:42
Computation spaces.
Definition: core.hpp:1748
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: bnd.hpp:385
Base-class for both propagators and branchers.
Definition: core.hpp:696
Graph< View > g
Propagation is performed on a view-value graph.
Definition: distinct.hh:223
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: val.hpp:161
ExecStatus init(Space &home, ViewArray< View > &x)
Initialize graph.
Definition: graph.hpp:48
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition: eqite.cpp:45
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Graph(void)
Construct graph as not yet initialized.
Definition: graph.hpp:44
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition: bnd.hpp:465
ViewArray< View > y
Views on which to perform value-propagation (subset of x)
Definition: distinct.hh:134
Binary propagator.
Definition: propagator.hpp:89
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: bnd.hpp:76
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1103
virtual void reschedule(Space &home)
Schedule function.
Definition: bnd.hpp:91
int c0
The integer constant.
Definition: distinct.hh:317
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: eqite.cpp:55
Ternary propagator.
Definition: propagator.hpp:119
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: eqite.cpp:50
n-ary propagator
Definition: propagator.hpp:149
View arrays.
Definition: array.hpp:234
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: ter-dom.hpp:97
View-value graph base class.
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition: val.hpp:174
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: dom.hpp:78
ExecStatus sync(Space &home)
Synchronize available view-value graph.
Definition: dom-ctrl.hpp:65
ExecStatus prop_val(Space &home, ViewArray< View > &x)
Eliminate singletons by naive value propagation.
Definition: val.hpp:46
Naive value distinct propagator.
Definition: distinct.hh:68
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: ter-dom.hpp:65
Integer view for integer variables.
Definition: view.hpp:129
Ternary domain consistent distinct propagator.
Definition: distinct.hh:285
Propagation cost.
Definition: core.hpp:554
ExecStatus
Definition: core.hpp:540
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: dom.hpp:84
DomCtrl(void)
Initialize with non-initialized view-value graph.
Definition: dom-ctrl.hpp:49
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
int max_x
Maximum (approximation) of view in x.
Definition: distinct.hh:138
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: dom.hpp:69
ExecStatus propagate(Space &home, bool &assigned)
Perform propagation, assigned is true if a view gets assigned.
Definition: dom-ctrl.hpp:72
Post propagator for SetVar x
Definition: set.hh:784
Equal-if-then-else domain-consistent propagator.
Definition: distinct.hh:312
Bounds consistent distinct propagator.
Definition: distinct.hh:129
Gecode toplevel namespace
bool available(void)
Check whether a view-value graph is available.
Definition: dom-ctrl.hpp:53
#define GECODE_INT_EXPORT
Definition: int.hh:81
ExecStatus prop_bnd(Space &home, ViewArray< View > &x, int *minsorted, int *maxsorted)
Definition: bnd.hpp:201
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
bool sync(Space &home)
Synchronize graph with new view domains.
Definition: graph.hpp:116
virtual size_t dispose(Space &home)
Destructor.
Definition: bnd.hpp:60
Home class for posting propagators
Definition: core.hpp:922
Propagation controller for domain consistent distinct.
Definition: distinct.hh:220