Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.9.1
basic.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: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
15  * $Revision: 13068 $
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 
42 namespace Gecode { namespace Int { namespace Extensional {
43 
44  /*
45  * The propagator proper
46  *
47  */
48 
49  template<class View, bool shared>
52  const TupleSet& t)
53  : Base<View>(home,x,t) {
54  }
55 
56  template<class View, bool shared>
59  const TupleSet& t) {
60  // All variables in the correct domain
61  for (int i = x.size(); i--; ) {
62  GECODE_ME_CHECK(x[i].gq(home, t.min()));
63  GECODE_ME_CHECK(x[i].lq(home, t.max()));
64  }
65  (void) new (home) Basic<View,shared>(home,x,t);
66  return ES_OK;
67  }
68 
69  template<class View, bool shared>
72  : Base<View>(home,share,p) {
73  }
74 
75  template<class View, bool shared>
76  PropCost
77  Basic<View,shared>::cost(const Space&, const ModEventDelta& med) const {
78  if (View::me(med) == ME_INT_VAL)
79  return PropCost::quadratic(PropCost::HI,x.size());
80  else
81  return PropCost::cubic(PropCost::HI,x.size());
82  }
83 
84  template<class View, bool shared>
85  Actor*
86  Basic<View,shared>::copy(Space& home, bool share) {
87  return new (home) Basic<View,shared>(home,share,*this);
88  }
89 
90  template<class View, bool shared>
93  // Set up datastructures
94 
95  // Bit-sets for amortized O(1) access to domains
96  Region r(home);
97  BitSet* dom = r.alloc<BitSet>(x.size());
98  init_dom(home, dom);
99 
100  // Bit-sets for processed values.
101  BitSet* has_support = r.alloc<BitSet>(x.size());
102  for (int i = x.size(); i--; )
103  has_support[i].init(home, ts()->domsize);
104 
105 
106  // Values to prune
107  Support::StaticStack<int,Region> nq(r,static_cast<int>(ts()->domsize));
108 
109  // Run algorithm
110 
111  // Check consistency for each view-value pair
112  for (int i = x.size(); i--; ) {
113  for (ViewValues<View> vv(x[i]); vv(); ++vv) {
114  // Value offset for indexing
115  int val = vv.val() - ts()->min;
116  if (!has_support[i].get(static_cast<unsigned int>(val))) {
117  // Find support for value vv.val() in view
118  Tuple l = find_support(dom, i, val);
119  if (l == NULL) {
120  // No possible supports left
121  nq.push(vv.val());
122  } else {
123  // Mark values as supported
124  // Only forward direction marking is needed since all
125  // previous values have been checked
126  for (int j = i; j--; ) {
127  has_support[j].set(static_cast<unsigned int>(l[j]- ts()->min));
128  assert(has_support[j].get(l[j] - ts()->min));
129  }
130  }
131  }
132  }
133 
134  // Prune values for x[i] which do not have support anymore
135  while (!nq.empty())
136  GECODE_ME_CHECK(x[i].nq(home,nq.pop()));
137  }
138 
139  for (int i = x.size(); i--; )
140  if (!x[i].assigned())
141  return shared ? ES_NOFIX : ES_FIX;
142  return home.ES_SUBSUMED(*this);
143  }
144 
145 }}}
146 
147 // STATISTICS: int-prop
148 
void push(const T &x)
Push element x on top of stack.
NodeType t
Type of node.
Definition: bool-expr.cpp:234
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4032
int min(void) const
Minimum domain element.
Definition: tuple-set.hpp:155
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:326
Basic bitset support.
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Expensive.
Definition: core.hpp:564
Handle to region.
Definition: region.hpp:61
Value iterator for integer views.
Definition: view.hpp:94
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: basic.hpp:86
Base-class for both propagators and branchers.
Definition: core.hpp:666
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: basic.hpp:92
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
bool empty(void) const
Test whether stack is empty.
Gecode::IntArgs i(4, 1, 2, 3, 4)
TupleSet::Tuple Tuple
Definition: extensional.hh:227
Domain consistent extensional propagator.
Definition: extensional.hh:295
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
void set(unsigned int i)
Set bit i.
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: basic.hpp:77
View arrays.
Definition: array.hpp:234
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
int max(void) const
Maximum domain element.
Definition: tuple-set.hpp:162
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Class represeting a set of tuples.
Definition: int.hh:2022
static ExecStatus post(Home home, ViewArray< View > &x, const TupleSet &t)
Post propagator for views x.
Definition: basic.hpp:58
static PropCost cubic(PropCost::Mod m, unsigned int n)
Cubic complexity for modifier m and size measure n.
Definition: core.hpp:4023
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Basic(Space &home, bool share, Basic< View, shared > &p)
Constructor for cloning p.
Definition: basic.hpp:71
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:132
Stack with fixed number of elements.
T pop(void)
Pop topmost element from stack and return it.
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Base for domain consistent extensional propagation
Definition: extensional.hh:242
Gecode toplevel namespace
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717