Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <climits>
35 
36 namespace Gecode { namespace Int { namespace Distinct {
37 
38  template<class View>
41  : NaryPropagator<View,PC_INT_DOM>(home,x) {}
42 
43  template<class View>
46  if (x.size() == 2)
47  return Rel::Nq<View,View>::post(home,x[0],x[1]);
48  if (x.size() == 3)
49  return TerDom<View>::post(home,x[0],x[1],x[2]);
50  if (x.size() > 3) {
51  // Do bounds propagation to make view-value graph smaller
52  GECODE_ES_CHECK(prop_bnd<View>(home,x));
53  (void) new (home) Dom<View>(home,x);
54  }
55  return ES_OK;
56  }
57 
58  template<class View>
61  : NaryPropagator<View,PC_INT_DOM>(home,p) {}
62 
63  template<class View>
64  PropCost
65  Dom<View>::cost(const Space&, const ModEventDelta& med) const {
66  if (View::me(med) == ME_INT_VAL)
67  return PropCost::linear(PropCost::LO, x.size());
68  else
69  return PropCost::quadratic(PropCost::HI, x.size());
70  }
71 
72  template<class View>
73  Actor*
75  return new (home) Dom<View>(home,*this);
76  }
77 
78 #ifdef GECODE_HAS_CBS
79  template<class View>
80  void
81  Dom<View>::solndistrib(Space& home, Propagator::SendMarginal send) const {
82  cbsdistinct(home,this->id(),x,send);
83  }
84 
85  template<class View>
86  void
87  Dom<View>::domainsizesum(Propagator::InDecision in, unsigned int& size,
88  unsigned int& size_b) const {
89  cbssize(x,in,size,size_b);
90  }
91 #endif
92 
93 
94  template<class View>
97  if (View::me(med) == ME_INT_VAL) {
98  ExecStatus es = prop_val<View,false>(home,x);
99  GECODE_ES_CHECK(es);
100  if (x.size() < 2)
101  return home.ES_SUBSUMED(*this);
102  if (es == ES_FIX)
103  return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
104  es = prop_bnd<View>(home,x);
105  GECODE_ES_CHECK(es);
106  if (x.size() < 2)
107  return home.ES_SUBSUMED(*this);
108  es = prop_val<View,true>(home,x);
109  GECODE_ES_CHECK(es);
110  if (x.size() < 2)
111  return home.ES_SUBSUMED(*this);
112  return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
113  }
114 
115  if (x.size() == 2)
116  GECODE_REWRITE(*this,(Rel::Nq<View,View>::post(home(*this),x[0],x[1])));
117  if (x.size() == 3)
118  GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
119 
120  if (dc.available()) {
121  GECODE_ES_CHECK(dc.sync());
122  } else {
123  GECODE_ES_CHECK(dc.init(home,x));
124  }
125 
126  bool assigned;
127  GECODE_ES_CHECK(dc.propagate(home,assigned));
128 
129  return ES_FIX;
130  }
131 
132 }}}
133 
134 // STATISTICS: int-prop
135 
Post propagator for SetVar x
Definition: set.hh:767
Dom(Space &home, Dom< View > &p)
Constructor for cloning p.
Definition: dom.hpp:60
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition: ter-dom.hpp:49
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition: dom.hpp:45
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition: nq.hpp:49
unsigned int size(I &i)
Size of all ranges of range iterator i.
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
@ LO
Cheap.
Definition: core.hpp:513
Computation spaces.
Definition: core.hpp:1742
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition: core.hpp:4796
Base-class for both propagators and branchers.
Definition: core.hpp:628
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4787
Binary disequality propagator.
Definition: rel.hh:460
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
Gecode toplevel namespace
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
Ternary domain consistent distinct propagator.
Definition: distinct.hh:322
Home class for posting propagators
Definition: core.hpp:856
n-ary propagator
Definition: pattern.hpp:142
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: dom.hpp:65
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: dom.hpp:96
Domain consistent distinct propagator.
Definition: distinct.hh:283
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: dom.hpp:74
Propagation cost.
Definition: core.hpp:486
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:477
#define forceinline
Definition: config.hpp:185
@ HI
Expensive.
Definition: core.hpp:514
View arrays.
Definition: array.hpp:253
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition: core.hpp:3569
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition: var-type.hpp:72
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:116
@ ES_OK
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
ExecStatus
Definition: core.hpp:472