Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
element.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 * Copyright:
8 * Christian Schulte, 2004
9 * Guido Tack, 2004
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#ifndef __GECODE_INT_ELEMENT_HH__
37#define __GECODE_INT_ELEMENT_HH__
38
39#include <gecode/int.hh>
40#include <gecode/int/rel.hh>
42
47
48namespace Gecode { namespace Int { namespace Element {
49
56 template<class V0, class V1, class Idx, class Val>
57 class Int : public Propagator {
58 protected:
67 class IdxVal {
68 public:
71 Idx idx;
74 void mark(void);
76 bool marked(void) const;
77 };
78
85 private:
86 IdxVal* iv;
87 Idx i;
88 public:
92 bool operator ()(void) const;
94 void operator ++(void);
96 Idx val(void) const;
97 };
98
104 class IterVal {
105 private:
106 IdxVal* iv;
107 Idx i;
108 public:
110 IterVal(IdxVal* iv);
112 bool operator ()(void) const;
114 void operator ++(void);
116 Val val(void) const;
117 };
118
127 private:
128 IdxVal* iv;
129 Idx i;
130 public:
134 bool operator ()(void) const;
136 void operator ++(void);
138 Val val(void) const;
139 };
140
141 class ByVal {
142 protected:
143 const IdxVal* iv;
144 public:
146 ByVal(const IdxVal* iv);
148 bool operator ()(Idx& i, Idx& j);
149 };
150
152 V0 x0;
158 V1 x1;
168 void prune_idx(void);
170 void prune_val(void);
173 V0 x0, V1 x1);
175 Int(Space& home, Int& p);
177 Int(Home home, IntSharedArray& i, V0 x0, V1 x1);
178 public:
180 virtual Actor* copy(Space& home);
182 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
184 virtual void reschedule(Space& home);
186 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
188 static ExecStatus post(Home home, IntSharedArray& i, V0 x0, V1 x1);
190 virtual size_t dispose(Space& home);
191 };
192
194 template<class V0, class V1>
195 ExecStatus post_int(Home home, IntSharedArray& c, V0 x0, V1 x1);
196
197
202 template<class VA, class VB, class VC, PropCond pc_ac>
203 class View : public Propagator {
204 protected:
208 VB x0;
210 VC x1;
212 View(Space& home, View& p);
214 View(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
215 public:
216 // Cost function (defined as low linear)
217 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
219 virtual void reschedule(Space& home);
221 virtual size_t dispose(Space& home);
222 };
223
224
231 template<class VA, class VB, class VC>
232 class ViewBnd : public View<VA,VB,VC,PC_INT_BND> {
233 protected:
234 using View<VA,VB,VC,PC_INT_BND>::iv;
235 using View<VA,VB,VC,PC_INT_BND>::x0;
236 using View<VA,VB,VC,PC_INT_BND>::x1;
237
239 ViewBnd(Space& home, ViewBnd& p);
241 ViewBnd(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
242 public:
244 virtual Actor* copy(Space& home);
246 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
248 static ExecStatus post(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
249 };
250
261 template<class VA, class VB, class VC>
262 class ViewDom : public View<VA,VB,VC,PC_INT_DOM> {
263 protected:
264 using View<VA,VB,VC,PC_INT_DOM>::iv;
265 using View<VA,VB,VC,PC_INT_DOM>::x0;
266 using View<VA,VB,VC,PC_INT_DOM>::x1;
267
269 ViewDom(Space& home, ViewDom& p);
271 ViewDom(Home home, IdxViewArray<VA>& iv, VB x0, VC x1);
272 public:
274 virtual Actor* copy(Space& home);
282 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
284 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
286 static ExecStatus post(Home home, IdxViewArray<VA>& iv,
287 VB x0, VC x1);
288 };
289
298 : public TernaryPropagator<IntView,PC_INT_DOM> {
299 protected:
304 int w;
306 Pair(Space& home, Pair& p);
307 public:
309 Pair(Home home, IntView x0, IntView x1, IntView x2, int w);
312 int w, int h);
314 GECODE_INT_EXPORT virtual Actor* copy(Space& home);
317 };
318
319}}}
320
324
325#endif
326
327
328// STATISTICS: int-prop
329
Home class for posting propagators
Definition core.hpp:856
bool operator()(Idx &i, Idx &j)
Compare pairs at positions i and j.
Definition int.hpp:147
const IdxVal * iv
Index-value pairs.
Definition element.hh:143
ByVal(const IdxVal *iv)
Initialize with index value pairs.
Definition int.hpp:143
Linked index-value pairs.
Definition element.hh:67
Idx val_next
The position of the next pair in value order.
Definition element.hh:70
Val val
The value Mark that this pair should be removed.
Definition element.hh:72
bool marked(void) const
Return whether this pair is marked for removal.
Definition int.hpp:45
Idx idx_next
The position of the next pair in index order.
Definition element.hh:69
Idx val(void) const
Return index of current index value pair.
Definition int.hpp:77
void operator++(void)
Move to next index value pair (next index)
Definition int.hpp:68
IterIdxUnmark(IdxVal *iv)
Initialize with start.
Definition int.hpp:53
bool operator()(void) const
Test whether more pairs to be iterated.
Definition int.hpp:63
void operator++(void)
Move to next index value pair (next value)
Definition int.hpp:124
bool operator()(void) const
Test whether more pairs to be iterated.
Definition int.hpp:119
Val val(void) const
Return value of current index value pair.
Definition int.hpp:133
IterValUnmark(IdxVal *iv)
Initialize with start.
Definition int.hpp:109
bool operator()(void) const
Test whether more pairs to be iterated.
Definition int.hpp:90
IterVal(IdxVal *iv)
Initialize with start.
Definition int.hpp:86
Val val(void) const
Return value of current index value pair.
Definition int.hpp:100
void operator++(void)
Move to next index value pair (next value)
Definition int.hpp:95
Element propagator for array of integers
Definition element.hh:57
Int(Space &home, Int &p)
Constructor for cloning p.
Definition int.hpp:191
ValSize s1
Size of x1 at last execution.
Definition element.hh:162
void prune_val(void)
Prune values according to x1.
Definition int.hpp:244
IntSharedArray c
Shared array of integer values.
Definition element.hh:164
V1 x1
View for result.
Definition element.hh:158
static ExecStatus post(Home home, IntSharedArray &i, V0 x0, V1 x1)
Post propagator for .
Definition int.hpp:178
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition int.hpp:199
virtual void reschedule(Space &home)
Schedule function.
Definition int.hpp:215
static ExecStatus assigned_val(Space &home, IntSharedArray &c, V0 x0, V1 x1)
Prune when x1 is assigned.
Definition int.hpp:267
IdxSize s0
Size of x0 at last execution.
Definition element.hh:156
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int.hpp:282
IdxVal * iv
The index-value data structure.
Definition element.hh:166
Gecode::Support::IntTypeTraits< Idx >::utype IdxSize
Type for index size.
Definition element.hh:154
Gecode::Support::IntTypeTraits< Val >::utype ValSize
Type for value size.
Definition element.hh:160
V0 x0
View for index.
Definition element.hh:152
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as high binary)
Definition int.hpp:205
void prune_idx(void)
Prune index according to x0.
Definition int.hpp:222
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition int.hpp:167
Pair(Space &home, Pair &p)
Constructor for cloning p.
Definition pair.hpp:64
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition pair.cpp:97
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:43
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition pair.cpp:39
ViewBnd(Space &home, ViewBnd &p)
Constructor for cloning p.
Definition view.hpp:301
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition view.hpp:306
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view.hpp:312
static ExecStatus post(Home home, IdxViewArray< VA > &iv, VB x0, VC x1)
Post propagator for .
Definition view.hpp:284
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition view.hpp:388
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition view.hpp:402
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition view.hpp:395
static ExecStatus post(Home home, IdxViewArray< VA > &iv, VB x0, VC x1)
Post propagator for .
Definition view.hpp:366
ViewDom(Space &home, ViewDom &p)
Constructor for cloning p.
Definition view.hpp:383
IdxViewArray< VA > iv
Current index-view map.
Definition element.hh:206
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition view.hpp:131
virtual void reschedule(Space &home)
Schedule function.
Definition view.hpp:140
View(Space &home, View &p)
Constructor for cloning p.
Definition view.hpp:122
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition view.hpp:148
VC x1
View for result.
Definition element.hh:210
VB x0
View for index.
Definition element.hh:208
An array of IdxView pairs.
Definition idx-view.hh:67
Integer view for integer variables.
Definition view.hpp:129
Propagation cost.
Definition core.hpp:486
friend class Space
Definition core.hpp:1068
ModEventDelta med
A set of modification events (used during propagation)
Definition core.hpp:1077
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3505
Traits to for information about integer types.
Definition int-type.hpp:52
TernaryPropagator(Space &home, TernaryPropagator &p)
#define GECODE_INT_EXPORT
Definition int.hh:81
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
Element propagators
ExecStatus post_int(Home home, IntSharedArray &c, V0 x0, V1 x1)
Post propagator with apropriate index and value types.
Definition int.hpp:405
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition var-type.hpp:91
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Gecode toplevel namespace
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1492
ExecStatus
Definition core.hpp:472
#define GECODE_VTABLE_EXPORT
Definition support.hh:72