Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
36namespace Gecode { namespace Int { namespace Distinct {
37
38 template<class View>
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
53 (void) new (home) Dom<View>(home,x);
54 }
55 return ES_OK;
56 }
57
58 template<class View>
62
63 template<class View>
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) {
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
Base-class for both propagators and branchers.
Definition core.hpp:628
Home class for posting propagators
Definition core.hpp:856
Domain consistent distinct propagator.
Definition distinct.hh:283
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition dom.hpp:45
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition dom.hpp:96
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition dom.hpp:74
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition dom.hpp:65
Dom(Space &home, Dom< View > &p)
Constructor for cloning p.
Definition dom.hpp:60
DomCtrl< View > dc
Propagation controller.
Definition distinct.hh:287
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition ter-dom.hpp:49
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition nq.hpp:49
NaryPropagator(Space &home, NaryPropagator &p)
Propagation cost.
Definition core.hpp:486
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:4794
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition core.hpp:4803
@ HI
Expensive.
Definition core.hpp:514
friend class Space
Definition core.hpp:1068
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1077
Computation spaces.
Definition core.hpp:1744
View arrays.
Definition array.hpp:253
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition core.hpp:3576
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3570
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition macros.hpp:91
Distinct propagators
ExecStatus prop_bnd(Space &home, ViewArray< View > &x, int &min_x, int &max_x)
Perform bounds consistent distinct propagation.
Definition bnd.hpp:308
ExecStatus prop_val(Space &home, ViewArray< View > &)
Eliminate singletons by naive value propagation.
Definition val.hpp:42
Domain propagators.
Finite domain integers.
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition var-type.hpp:56
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition var-type.hpp:72
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
Post propagator for SetVar x
Definition set.hh:773
#define forceinline
Definition config.hpp:194