Generated on Sat Feb 7 2015 02:01:20 for Gecode by doxygen 1.8.9.1
dom.hpp
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  *
6  * Copyright:
7  * Christian Schulte, 2003
8  *
9  * Last modified:
10  * $Date: 2011-09-06 14:19:49 +0200 (Tue, 06 Sep 2011) $ by $Author: schulte $
11  * $Revision: 12393 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <climits>
39 
40 namespace Gecode { namespace Int { namespace Distinct {
41 
42  template<class View>
45  : NaryPropagator<View,PC_INT_DOM>(home,x) {}
46 
47  template<class View>
50  if (x.size() == 2)
51  return Rel::Nq<View>::post(home,x[0],x[1]);
52  if (x.size() == 3)
53  return TerDom<View>::post(home,x[0],x[1],x[2]);
54  if (x.size() > 3) {
55  // Do bounds propagation to make view-value graph smaller
56  GECODE_ES_CHECK(prop_bnd<View>(home,x));
57  (void) new (home) Dom<View>(home,x);
58  }
59  return ES_OK;
60  }
61 
62  template<class View>
64  Dom<View>::Dom(Space& home, bool share, Dom<View>& p)
65  : NaryPropagator<View,PC_INT_DOM>(home,share,p) {}
66 
67  template<class View>
68  PropCost
69  Dom<View>::cost(const Space&, const ModEventDelta& med) const {
70  if (View::me(med) == ME_INT_VAL)
71  return PropCost::linear(PropCost::LO, x.size());
72  else
73  return PropCost::quadratic(PropCost::HI, x.size());
74  }
75 
76  template<class View>
77  Actor*
78  Dom<View>::copy(Space& home, bool share) {
79  return new (home) Dom<View>(home,share,*this);
80  }
81 
82  template<class View>
85  if (View::me(med) == ME_INT_VAL) {
86  ExecStatus es = prop_val<View,false>(home,x);
87  GECODE_ES_CHECK(es);
88  if (x.size() < 2)
89  return home.ES_SUBSUMED(*this);
90  if (es == ES_FIX)
91  return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
92  es = prop_bnd<View>(home,x);
93  GECODE_ES_CHECK(es);
94  if (x.size() < 2)
95  return home.ES_SUBSUMED(*this);
96  es = prop_val<View,true>(home,x);
97  GECODE_ES_CHECK(es);
98  if (x.size() < 2)
99  return home.ES_SUBSUMED(*this);
100  return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
101  }
102 
103  if (x.size() == 2)
104  GECODE_REWRITE(*this,Rel::Nq<View>::post(home(*this),x[0],x[1]));
105  if (x.size() == 3)
106  GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
107 
108  if (dc.available()) {
109  GECODE_ES_CHECK(dc.sync(home));
110  } else {
111  GECODE_ES_CHECK(dc.init(home,x));
112  }
113 
114  bool assigned;
115  GECODE_ES_CHECK(dc.propagate(home,assigned));
116 
117  return ES_FIX;
118  }
119 
120 }}}
121 
122 // STATISTICS: int-prop
123 
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4032
Dom(Space &home, bool share, Dom< View > &p)
Constructor for cloning p.
Definition: dom.hpp:64
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition: core.hpp:4041
Domain consistent distinct propagator.
Definition: distinct.hh:251
Expensive.
Definition: core.hpp:564
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition: dom.hpp:49
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Base-class for both propagators and branchers.
Definition: core.hpp:666
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: dom.hpp:69
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
n-ary propagator
Definition: propagator.hpp:143
View arrays.
Definition: array.hpp:234
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: dom.hpp:78
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Ternary domain consistent distinct propagator.
Definition: distinct.hh:283
Propagation cost.
Definition: core.hpp:537
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition: var-type.hpp:72
ExecStatus
Definition: core.hpp:523
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: dom.hpp:84
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:132
Binary disequality propagator.
Definition: rel.hh:432
Execution is okay.
Definition: core.hpp:527
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Gecode toplevel namespace
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717