Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
distinct.hh
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 * Guido Tack <tack@gecode.org>
6 *
7 * Contributing authors:
8 * Gabor Szokoli <szokoli@gecode.org>
9 *
10 * Copyright:
11 * Christian Schulte, 2002
12 * Guido Tack, 2004
13 * Gabor Szokoli, 2003
14 *
15 * This file is part of Gecode, the generic constraint
16 * development environment:
17 * http://www.gecode.org
18 *
19 * Permission is hereby granted, free of charge, to any person obtaining
20 * a copy of this software and associated documentation files (the
21 * "Software"), to deal in the Software without restriction, including
22 * without limitation the rights to use, copy, modify, merge, publish,
23 * distribute, sublicense, and/or sell copies of the Software, and to
24 * permit persons to whom the Software is furnished to do so, subject to
25 * the following conditions:
26 *
27 * The above copyright notice and this permission notice shall be
28 * included in all copies or substantial portions of the Software.
29 *
30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 *
38 */
39
40#ifndef __GECODE_INT_DISTINCT_HH__
41#define __GECODE_INT_DISTINCT_HH__
42
43#include <gecode/int.hh>
44
46#include <gecode/int/rel.hh>
47
53namespace Gecode { namespace Int { namespace Distinct {
54
63 template<class View>
64 class Val : public NaryPropagator<View,PC_INT_VAL> {
65 protected:
66 using NaryPropagator<View,PC_INT_VAL>::x;
67
69 Val(Home home, ViewArray<View>& x);
71 Val(Space& home, Val<View>& p);
72 public:
73#ifdef GECODE_HAS_CBS
75 virtual void solndistrib(Space& home, Propagator::SendMarginal send) const;
77 virtual void domainsizesum(Propagator::InDecision in,
78 unsigned int& size, unsigned int& size_b) const;
79#endif
81 virtual Actor* copy(Space& home);
83 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
85 static ExecStatus post(Home home, ViewArray<View>& x);
86 };
87
88#ifdef GECODE_HAS_CBS
99 template<class View>
100 void cbsdistinct(Space& home, unsigned int prop_id, const ViewArray<View>& x,
101 Propagator::SendMarginal send);
102
103 template<class View>
104 void cbssize(const ViewArray<View>& x, Propagator::InDecision in,
105 unsigned int& size, unsigned int& size_b);
106#endif
107
121 template<class View, bool complete>
123
124
125
151 template<class View>
152 class Bnd : public Propagator {
153 protected:
159 int min_x;
161 int max_x;
163 Bnd(Home home, ViewArray<View>& x);
165 Bnd(Space& home, Bnd<View>& p);
166 public:
167#ifdef GECODE_HAS_CBS
169 virtual void solndistrib(Space& home, Propagator::SendMarginal send) const;
171 virtual void domainsizesum(Propagator::InDecision in,
172 unsigned int& size, unsigned int& size_b) const;
173#endif
175 static ExecStatus post(Home home, ViewArray<View>& x);
177 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
184 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
186 virtual void reschedule(Space& home);
188 virtual Actor* copy(Space& home);
190 virtual size_t dispose(Space& home);
191 };
192
201 template<class View>
202 ExecStatus prop_bnd(Space& home, ViewArray<View>& x, int& min_x, int& max_x);
203
212 template<class View>
214
215
217 template<class View>
218 class Graph : public ViewValGraph::Graph<View> {
219 public:
220 using ViewValGraph::Graph<View>::view;
221 using ViewValGraph::Graph<View>::n_view;
222 using ViewValGraph::Graph<View>::val;
223 using ViewValGraph::Graph<View>::n_val;
224 using ViewValGraph::Graph<View>::count;
225 using ViewValGraph::Graph<View>::scc;
226 using ViewValGraph::Graph<View>::match;
228 Graph(void);
232 bool mark(void);
234 ExecStatus prune(Space& home, bool& assigned);
236 bool sync(void);
237 };
238
249 template<class View>
250 class DomCtrl {
251 protected:
254 public:
256 DomCtrl(void);
258 bool available(void);
262 ExecStatus sync(void);
264 ExecStatus propagate(Space& home, bool& assigned);
265 };
266
282 template<class View>
283 class Dom : public NaryPropagator<View,PC_INT_DOM> {
284 protected:
285 using NaryPropagator<View,PC_INT_DOM>::x;
289 Dom(Space& home, Dom<View>& p);
291 Dom(Home home, ViewArray<View>& x);
292 public:
293#ifdef GECODE_HAS_CBS
295 virtual void solndistrib(Space& home, Propagator::SendMarginal send) const;
297 virtual void domainsizesum(Propagator::InDecision in,
298 unsigned int& size, unsigned int& size_b) const;
299#endif
301 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
308 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
310 virtual Actor* copy(Space& home);
312 static ExecStatus post(Home home, ViewArray<View>& x);
313 };
314
321 template<class View>
322 class TerDom : public TernaryPropagator<View,PC_INT_DOM> {
323 protected:
327
329 TerDom(Space& home, TerDom<View>& p);
331 TerDom(Home home, View x0, View x1, View x2);
332 public:
334 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
336 virtual Actor* copy(Space& home);
338 static ExecStatus post(Home home, View x0, View x1, View x2);
339 };
340
349 class EqIte : public BinaryPropagator<IntView,PC_INT_DOM> {
350 protected:
354 int c0, c1;
356 EqIte(Space& home, EqIte& p);
358 EqIte(Home home, IntView x0, IntView x1, int c0, int c1);
359 public:
362 virtual Actor* copy(Space& home);
365 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
368 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
370 static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1);
371 };
372
373}}}
374
383
384#endif
385
386// STATISTICS: int-prop
387
int p
Number of positive literals for node type.
Base-class for both propagators and branchers.
Definition core.hpp:628
Binary propagator.
Definition pattern.hpp:84
Home class for posting propagators
Definition core.hpp:856
Bounds consistent distinct propagator.
Definition distinct.hh:152
int max_x
Maximum (approximation) of view in x.
Definition distinct.hh:161
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition bnd.hpp:476
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition bnd.hpp:381
virtual void reschedule(Space &home)
Schedule function.
Definition bnd.hpp:87
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition bnd.hpp:72
ViewArray< View > y
Views on which to perform value-propagation (subset of x)
Definition distinct.hh:157
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition bnd.hpp:78
Bnd(Home home, ViewArray< View > &x)
Constructor for posting.
Definition bnd.hpp:38
virtual size_t dispose(Space &home)
Destructor.
Definition bnd.hpp:56
ViewArray< View > x
Views on which to perform bounds-propagation.
Definition distinct.hh:155
int min_x
Minimum (approximation) of view in x.
Definition distinct.hh:159
Propagation controller for domain consistent distinct.
Definition distinct.hh:250
ExecStatus init(Space &home, ViewArray< View > &x)
Initialize view-value graph for views x.
Definition dom-ctrl.hpp:55
ExecStatus propagate(Space &home, bool &assigned)
Perform propagation, assigned is true if a view gets assigned.
Definition dom-ctrl.hpp:68
bool available(void)
Check whether a view-value graph is available.
Definition dom-ctrl.hpp:49
ExecStatus sync(void)
Synchronize available view-value graph.
Definition dom-ctrl.hpp:61
Graph< View > g
Propagation is performed on a view-value graph.
Definition distinct.hh:253
DomCtrl(void)
Initialize with non-initialized view-value graph.
Definition dom-ctrl.hpp:45
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
DomCtrl< View > dc
Propagation controller.
Definition distinct.hh:287
Equal-if-then-else domain-consistent propagator.
Definition distinct.hh:349
EqIte(Space &home, EqIte &p)
Constructor for cloning p.
Definition eqite.hpp:43
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition eqite.cpp:46
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high ternary)
Definition eqite.cpp:41
static ExecStatus post(Home home, IntView x0, IntView x1, int c0, int c1)
Post if-then-else propagator.
Definition eqite.hpp:49
int c0
The integer constant.
Definition distinct.hh:354
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition eqite.cpp:51
View-value graph for propagation.
Definition distinct.hh:218
Graph(void)
Construct graph as not yet initialized.
Definition graph.hpp:40
bool mark(void)
Mark edges in graph, return true if pruning is at all possible.
Definition graph.hpp:176
bool sync(void)
Synchronize graph with new view domains.
Definition graph.hpp:112
ExecStatus init(Space &home, ViewArray< View > &x)
Initialize graph.
Definition graph.hpp:44
ExecStatus prune(Space &home, bool &assigned)
Prune unmarked edges, assigned is true if a view got assigned.
Definition graph.hpp:240
Ternary domain consistent distinct propagator.
Definition distinct.hh:322
TerDom(Space &home, TerDom< View > &p)
Constructor for cloning p.
Definition ter-dom.hpp:56
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition ter-dom.hpp:93
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition ter-dom.hpp:49
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition ter-dom.hpp:61
Naive value distinct propagator.
Definition distinct.hh:64
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition val.hpp:172
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition val.hpp:178
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for view array x.
Definition val.hpp:185
Val(Home home, ViewArray< View > &x)
Constructor for posting.
Definition val.hpp:147
Integer view for integer variables.
Definition view.hpp:129
View-value graph base class.
unsigned int count
Marking counter.
ViewNode< View > ** view
Array of view nodes.
bool match(ViewNodeStack &m, ViewNode< View > *x)
Find a matching for node x.
Definition graph.hpp:87
int n_view
Number of view nodes.
int n_val
Number of value nodes.
void scc(void)
Compute the strongly connected components.
Definition graph.hpp:142
ValNode< View > * val
Array of value nodes.
n-ary propagator
Definition pattern.hpp:142
Propagation cost.
Definition core.hpp:486
Base-class for propagators.
Definition core.hpp:1064
size_t size
The size of the propagator (used during subsumption)
Definition core.hpp:1077
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1075
Computation spaces.
Definition core.hpp:1742
Ternary propagator.
Definition pattern.hpp:113
View arrays.
Definition array.hpp:253
#define GECODE_INT_EXPORT
Definition int.hh:81
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
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
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition var-type.hpp:82
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
Post propagator for SetVar x
Definition set.hh:767