Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
element.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, 2004
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_ELEMENT_HH__
37 #define __GECODE_INT_ELEMENT_HH__
38 
39 #include <gecode/int.hh>
40 #include <gecode/int/rel.hh>
41 #include <gecode/int/idx-view.hh>
42 
48 namespace Gecode { namespace Int { namespace Element {
49 
56  template<class V0, class V1, class Idx, class Val>
57  class Int : public Propagator {
58  protected:
67  class IdxVal {
68  public:
69  Idx idx_next;
70  Idx val_next;
71  Idx idx;
72  Val val;
73  void mark(void);
76  bool marked(void) const;
77  };
84  class IterIdxUnmark {
85  private:
86  IdxVal* iv;
87  Idx i;
88  public:
90  IterIdxUnmark(IdxVal* iv);
92  bool operator ()(void) const;
94  void operator ++(void);
96  Idx val(void) const;
97  };
104  class IterVal {
105  private:
106  IdxVal* iv;
107  Idx i;
108  public:
110  IterVal(IdxVal* iv);
112  bool operator ()(void) const;
114  void operator ++(void);
116  Val val(void) const;
117  };
127  private:
128  IdxVal* iv;
129  Idx i;
130  public:
132  IterValUnmark(IdxVal* iv);
134  bool operator ()(void) const;
136  void operator ++(void);
138  Val val(void) const;
139  };
141  class ByVal {
142  protected:
143  const IdxVal* iv;
144  public:
146  ByVal(const IdxVal* iv);
148  bool operator ()(Idx& i, Idx& j);
149  };
150 
152  V0 x0;
156  IdxSize s0;
158  V1 x1;
162  ValSize s1;
168  void prune_idx(void);
170  void prune_val(void);
172  static ExecStatus assigned_val(Space& home, IntSharedArray& c,
173  V0 x0, V1 x1);
175  Int(Space& home, Int& p);
177  Int(Home home, IntSharedArray& i, V0 x0, V1 x1);
178  public:
180  virtual Actor* copy(Space& home);
182  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
184  virtual void reschedule(Space& home);
186  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
188  static ExecStatus post(Home home, IntSharedArray& i, V0 x0, V1 x1);
190  virtual size_t dispose(Space& home);
191  };
192 
194  template<class V0, class V1>
195  ExecStatus post_int(Home home, IntSharedArray& c, V0 x0, V1 x1);
196 
197 
202  template<class VA, class VB, class VC, PropCond pc_ac>
203  class View : public Propagator {
204  protected:
208  VB x0;
210  VC x1;
212  View(Space& home, View& p);
214  View(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
215  public:
216  // Cost function (defined as low linear)
217  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
219  virtual void reschedule(Space& home);
221  virtual size_t dispose(Space& home);
222  };
223 
224 
231  template<class VA, class VB, class VC>
232  class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
233  protected:
237 
239  ViewBnd(Space& home, ViewBnd& p);
241  ViewBnd(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
242  public:
244  virtual Actor* copy(Space& home);
246  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
248  static ExecStatus post(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
249  };
250 
261  template<class VA, class VB, class VC>
262  class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
263  protected:
267 
269  ViewDom(Space& home, ViewDom& p);
271  ViewDom(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
272  public:
274  virtual Actor* copy(Space& home);
282  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
284  virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
286  static ExecStatus post(Home home, IdxViewArray<VA>& iv,
287  VB x0, VC x1);
288  };
289 
298  : public TernaryPropagator<IntView,PC_INT_DOM> {
299  protected:
304  int w;
306  Pair(Space& home, Pair& p);
307  public:
309  Pair(Home home, IntView x0, IntView x1, IntView x2, int w);
311  static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2,
312  int w, int h);
314  GECODE_INT_EXPORT virtual Actor* copy(Space& home);
317  };
318 
319 }}}
320 
324 
325 #endif
326 
327 
328 // STATISTICS: int-prop
329 
Domain consistent element propagator for array of views.
Definition: element.hh:262
IdxVal * iv
The index-value data structure.
Definition: element.hh:166
bool marked(void) const
Return whether this pair is marked for removal.
Definition: int.hpp:45
IdxSize s0
Size of x0 at last execution.
Definition: element.hh:156
Value iterator for values in index-value map.
Definition: element.hh:104
Linked index-value pairs.
Definition: element.hh:67
VC x1
View for result.
Definition: element.hh:210
virtual void reschedule(Space &home)
Schedule function.
Definition: int.hpp:215
const IdxVal * iv
Index-value pairs.
Definition: element.hh:143
Base-class for propagators.
Definition: core.hpp:1023
ValSize s1
Size of x1 at last execution.
Definition: element.hh:162
V1 x1
View for result.
Definition: element.hh:158
Value iterator for indices in index-value map.
Definition: element.hh:84
IntSharedArray c
Shared array of integer values.
Definition: element.hh:164
Computation spaces.
Definition: core.hpp:1701
Base-class for both propagators and branchers.
Definition: core.hpp:627
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Support::IntTypeTraits< Val >::utype ValSize
Type for value size.
Definition: element.hh:160
IdxViewArray< VA > iv
Current index-view map.
Definition: element.hh:206
Val val
The value Mark that this pair should be removed.
Definition: element.hh:72
Value iterator for values in index-value map.
Definition: element.hh:126
Idx idx_next
The position of the next pair in index order.
Definition: element.hh:69
void prune_val(void)
Prune values according to x1.
Definition: int.hpp:244
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1034
Ternary propagator.
Definition: pattern.hpp:113
Gecode::Support::IntTypeTraits< Idx >::utype IdxSize
Type for index size.
Definition: element.hh:154
V0 x0
View for index.
Definition: element.hh:152
static ExecStatus post(Home home, IntSharedArray &i, V0 x0, V1 x1)
Post propagator for .
Definition: int.hpp:178
Base-class for element propagator for array of views.
Definition: element.hh:203
Traits to for information about integer types.
Definition: int-type.hpp:52
VB x0
View for index.
Definition: element.hh:208
Integer view for integer variables.
Definition: view.hpp:129
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high binary)
Definition: int.hpp:205
Domain consistent pair propagator.
Definition: element.hh:297
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition: int.hpp:199
Propagation cost.
Definition: core.hpp:485
ExecStatus
Definition: core.hpp:471
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: int.hpp:167
Int(Space &home, Int &p)
Constructor for cloning p.
Definition: int.hpp:191
ExecStatus post_int(Home home, IntSharedArray &c, V0 x0, V1 x1)
Post propagator with apropriate index and value types.
Definition: int.hpp:405
void prune_idx(void)
Prune index according to x0.
Definition: int.hpp:222
Idx val_next
The position of the next pair in value order.
Definition: element.hh:70
Gecode toplevel namespace
#define GECODE_VTABLE_EXPORT
Definition: support.hh:72
Sorting pointers to (index,value) pairs in value order.
Definition: element.hh:141
#define GECODE_INT_EXPORT
Definition: int.hh:77
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Element propagator for array of integers
Definition: element.hh:57
Home class for posting propagators
Definition: core.hpp:853
static ExecStatus assigned_val(Space &home, IntSharedArray &c, V0 x0, V1 x1)
Prune when x1 is assigned.
Definition: int.hpp:267
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int.hpp:282
Bounds consistent element propagator for array of views.
Definition: element.hh:232