Generated on Thu Jan 31 2019 20:56:34 for Gecode by doxygen 1.8.15
base.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Mikael Lagerkvist <lagerkvist@gecode.org>
5  *
6  * Contributing authors:
7  * Christian Schulte <schulte@gecode.org>
8  *
9  * Copyright:
10  * Mikael Lagerkvist, 2007
11  * Christian Schulte, 2008
12  *
13  * Last modified:
14  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
15  * $Revision: 15137 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 namespace Gecode { namespace Int { namespace Extensional {
42  /*
43  * The propagator proper
44  *
45  */
46 
47  template<class View, bool subscribe>
50  const TupleSet& t)
51  : Propagator(home), x(x0), tupleSet(t), last_data(NULL) {
52  if (subscribe)
53  x.subscribe(home, *this, PC_INT_DOM);
54 
55  assert(ts()->finalized());
56 
57  init_last(home, ts()->last, ts()->tuple_data);
58 
59  home.notice(*this,AP_DISPOSE);
60  }
61 
62  template<class View, bool subscribe>
65  : Propagator(home,share,p), last_data(NULL) {
66  x.update(home, share, p.x);
67  tupleSet.update(home, share, p.tupleSet);
68 
69  init_last(home, p.last_data, p.ts()->tuple_data);
70  }
71 
72  template<class View, bool subscribe>
73  forceinline void
75  if (last_data == NULL) {
76  int literals = static_cast<int>(ts()->domsize*x.size());
77  last_data = home.alloc<Tuple*>(literals);
78  for (int i = literals; i--; )
79  last_data[i] = ts()->tuple_data+(source[i]-base);
80  }
81  }
82 
83  template<class View, bool subscribe>
86  return tupleSet.implementation();
87  }
88 
89  template<class View, bool subscribe>
90  void
92  if (subscribe)
93  x.reschedule(home, *this, PC_INT_DOM);
94  }
95 
96  template<class View, bool subscribe>
97  PropCost
99  return PropCost::quadratic(PropCost::HI,x.size());
100  }
101 
102 #define GECODE_LAST_TUPLE(l) (*(l))
103 
104  template<class View, bool subscribe>
107  return GECODE_LAST_TUPLE(last_data[(i*ts()->domsize) + n]);
108  }
109 
110  template<class View, bool subscribe>
113  assert(last(i,n) != NULL);
114  assert(last(i,n)[i] == n+ts()->min);
115  int pos = (i*static_cast<int>(ts()->domsize)) + n;
116  ++(last_data[pos]);
117  if (last(i,n)[i] != (n+ts()->min))
118  last_data[pos] = ts()->nullpointer;
119  return last(i,n);
120  }
121 
122 
123  template<class View, bool subscribe>
124  forceinline void
126  unsigned int domsize = ts()->domsize;
127  for (int i = x.size(); i--; ) {
128  dom[i].init(home, domsize);
129  for (ViewValues<View> vv(x[i]); vv(); ++vv)
130  dom[i].set(static_cast<unsigned int>(vv.val()-ts()->min));
131  }
132  }
133 
134  template<class View, bool subscribe>
135  forceinline bool
137  for (int i = x.size(); i--; )
138  if (!dom[i].get(static_cast<unsigned int>(t[i]-ts()->min)))
139  return false;
140  return true;
141  }
142 #undef GECODE_LAST_TUPLE
143  template<class View, bool subscribe>
146  Tuple l = last(i,n);
147  while ((l != NULL) && !valid(l, dom))
148  l = last_next(i,n);
149  return l;
150  }
151 
152 
153  template<class View, bool subscribe>
154  forceinline size_t
156  home.ignore(*this,AP_DISPOSE);
157  (void) Propagator::dispose(home);
158  if (subscribe)
159  x.cancel(home,*this,PC_INT_DOM);
160  // take care of last_data
161  unsigned int literals = ts()->domsize*x.size();
162  home.rfree(last_data, sizeof(Tuple*)*literals);
163  (void) tupleSet.~TupleSet();
164  return sizeof(*this);
165  }
166 
167 }}}
168 
169 // STATISTICS: int-prop
170 
NodeType t
Type of node.
Definition: bool-expr.cpp:234
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
bool valid(const FloatVal &n)
Return whether float n is a valid number.
Definition: limits.hpp:43
Actor must always be disposed.
Definition: core.hpp:630
Basic bitset support.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Base-class for propagators.
Definition: core.hpp:1092
Value iterator for integer views.
Definition: view.hpp:94
Computation spaces.
Definition: core.hpp:1748
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition: core.hpp:2868
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
TupleSet::Tuple Tuple
Definition: extensional.hh:229
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
Data stored for a Table.
Definition: int.hh:2173
View arrays.
Definition: array.hpp:234
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3321
Class represeting a set of tuples.
Definition: int.hh:2161
const double base
Base for geometric restart sequence.
Definition: search.hh:122
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Base(Space &home, bool share, Base< View, subscribe > &p)
Constructor for cloning p.
Definition: base.hpp:64
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:4141
Propagation cost.
Definition: core.hpp:554
int pos(int h, int w, int h1, int w1)
#define forceinline
Definition: config.hpp:173
Post propagator for SetVar x
Definition: set.hh:784
Base for domain consistent extensional propagation
Definition: extensional.hh:244
Gecode toplevel namespace
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
FloatVal min(const FloatVal &x, const FloatVal &y)
Return minimum of x and y.
Definition: val.hpp:402
Home class for posting propagators
Definition: core.hpp:922
#define GECODE_LAST_TUPLE(l)
Definition: base.hpp:102
void rfree(void *p, size_t s)
Free memory previously allocated with alloc (might be reused later)
Definition: core.hpp:2834