main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 13 2014 04:39:30 for Gecode by
doxygen
1.8.1.2
gecode
int
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
* Last modified:
12
* $Date: 2010-05-04 02:31:57 +1000 (Tue, 04 May 2010) $ by $Author: schulte $
13
* $Revision: 10846 $
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_ELEMENT_HH__
41
#define __GECODE_INT_ELEMENT_HH__
42
43
#include <
gecode/int.hh
>
44
#include <
gecode/int/rel.hh
>
45
51
namespace
Gecode {
namespace
Int {
namespace
Element {
52
59
template
<
class
V0,
class
V1,
class
Idx,
class
Val>
60
class
Int
:
public
Propagator
{
61
protected
:
70
class
IdxVal
{
71
public
:
72
Idx
idx_next
;
73
Idx
val_next
;
74
Idx
idx
;
75
Val
val
;
76
77
void
mark
(
void
);
79
bool
marked
(
void
)
const
;
80
};
87
class
IterIdxUnmark
{
88
private
:
89
IdxVal
* iv;
90
Idx i;
91
public
:
93
IterIdxUnmark
(
IdxVal
* iv);
95
bool
operator ()
(
void
)
const
;
97
void
operator ++
(
void
);
99
Idx
val
(
void
)
const
;
100
};
107
class
IterVal
{
108
private
:
109
IdxVal
* iv;
110
Idx i;
111
public
:
113
IterVal
(
IdxVal
* iv);
115
bool
operator ()
(
void
)
const
;
117
void
operator ++
(
void
);
119
Val
val
(
void
)
const
;
120
};
129
class
IterValUnmark
{
130
private
:
131
IdxVal
* iv;
132
Idx i;
133
public
:
135
IterValUnmark
(
IdxVal
* iv);
137
bool
operator ()
(
void
)
const
;
139
void
operator ++
(
void
);
141
Val
val
(
void
)
const
;
142
};
144
class
ByVal
{
145
protected
:
146
const
IdxVal
*
iv
;
147
public
:
149
ByVal
(
const
IdxVal
*
iv
);
151
bool
operator ()
(Idx&
i
, Idx& j);
152
};
153
155
V0
x0
;
157
typedef
typename
Gecode::Support::IntTypeTraits<Idx>::utype
IdxSize
;
159
IdxSize
s0
;
161
V1
x1
;
163
typedef
typename
Gecode::Support::IntTypeTraits<Val>::utype
ValSize
;
165
ValSize
s1
;
167
IntSharedArray
c
;
169
IdxVal
*
iv
;
171
void
prune_idx
(
void
);
173
void
prune_val
(
void
);
175
static
ExecStatus
assigned_val
(
Space
& home,
IntSharedArray
&
c
,
176
V0
x0
, V1
x1
);
178
Int
(
Space
& home,
bool
shared
,
Int
& p);
180
Int
(
Home
home,
IntSharedArray
&
i
, V0
x0
, V1
x1
);
181
public
:
183
virtual
Actor
*
copy
(
Space
& home,
bool
share);
185
virtual
PropCost
cost
(
const
Space
& home,
const
ModEventDelta
&
med
)
const
;
187
virtual
ExecStatus
propagate
(
Space
& home,
const
ModEventDelta
&
med
);
189
static
ExecStatus
post
(
Home
home,
IntSharedArray
&
i
, V0
x0
, V1
x1
);
191
virtual
size_t
dispose
(
Space
& home);
192
};
193
195
template
<
class
V0,
class
V1>
196
ExecStatus
post_int
(
Home
home,
IntSharedArray
&
c
, V0 x0, V1 x1);
197
198
203
template
<
class
ViewB>
class
IdxView
;
204
206
template
<
class
View>
207
class
ViewToVarArg
{};
208
213
template
<
class
View>
214
class
IdxViewArray
{
215
private
:
217
IdxView<View>
* xs;
219
int
n;
220
public
:
222
IdxViewArray
(
void
);
224
IdxViewArray
(
const
IdxViewArray<View>
&);
226
IdxViewArray
(
Space
& home,
const
typename
ViewToVarArg<View>::argtype
& x);
228
IdxViewArray
(
Space
& home,
int
n);
229
231
int
size
(
void
)
const
;
233
void
size
(
int
n);
234
236
IdxView<View>
&
operator []
(
int
n);
238
const
IdxView<View>
&
operator []
(
int
)
const
;
239
244
void
subscribe
(
Space
& home,
Propagator
& p,
PropCond
pc,
bool
process=
true
);
249
void
cancel
(
Space
& home,
Propagator
& p,
PropCond
pc);
250
252
void
update
(
Space
& home,
bool
share,
IdxViewArray<View>
& x);
253
};
254
259
template
<
class
VA,
class
VB,
class
VC, PropCond pc_ac>
260
class
View
:
public
Propagator
{
261
protected
:
263
IdxViewArray<VA>
iv
;
265
VB
x0
;
267
VC
x1
;
269
View
(
Space
& home,
bool
share,
View
& p);
271
View
(
Home
home,
IdxViewArray<VA>
&
iv
, VB
x0
, VC
x1
);
272
public
:
273
// Cost function (defined as low linear)
274
virtual
PropCost
cost
(
const
Space
& home,
const
ModEventDelta
&
med
)
const
;
276
virtual
size_t
dispose
(
Space
& home);
277
};
278
279
286
template
<
class
VA,
class
VB,
class
VC>
287
class
ViewBnd
:
public
View
<VA,VB,VC,PC_INT_BND> {
288
protected
:
289
using
View<VA,VB,VC,PC_INT_BND>::iv
;
290
using
View<VA,VB,VC,PC_INT_BND>::x0
;
291
using
View<VA,VB,VC,PC_INT_BND>::x1
;
292
294
ViewBnd
(
Space
& home,
bool
share,
ViewBnd
& p);
296
ViewBnd
(
Home
home,
IdxViewArray<VA>
&
iv
, VB
x0
, VC
x1
);
297
public
:
299
virtual
Actor
*
copy
(
Space
& home,
bool
share);
301
virtual
ExecStatus
propagate
(
Space
& home,
const
ModEventDelta
&
med
);
303
static
ExecStatus
post
(
Home
home,
IdxViewArray<VA>
& iv, VB x0, VC x1);
304
};
305
316
template
<
class
VA,
class
VB,
class
VC>
317
class
ViewDom
:
public
View
<VA,VB,VC,PC_INT_DOM> {
318
protected
:
319
using
View<VA,VB,VC,PC_INT_DOM>::iv
;
320
using
View<VA,VB,VC,PC_INT_DOM>::x0
;
321
using
View<VA,VB,VC,PC_INT_DOM>::x1
;
322
324
ViewDom
(
Space
& home,
bool
share,
ViewDom
& p);
326
ViewDom
(
Home
home,
IdxViewArray<VA>
&
iv
, VB
x0
, VC
x1
);
327
public
:
329
virtual
Actor
*
copy
(
Space
& home,
bool
share);
337
virtual
PropCost
cost
(
const
Space
& home,
const
ModEventDelta
&
med
)
const
;
339
virtual
ExecStatus
propagate
(
Space
& home,
const
ModEventDelta
& med);
341
static
ExecStatus
post
(
Home
home,
IdxViewArray<VA>
& iv,
342
VB x0, VC x1);
343
};
344
352
class
GECODE_VTABLE_EXPORT
Pair
353
:
public
TernaryPropagator
<IntView,PC_INT_DOM> {
354
protected
:
355
using
TernaryPropagator<IntView,PC_INT_DOM>::x0
;
356
using
TernaryPropagator<IntView,PC_INT_DOM>::x1
;
357
using
TernaryPropagator<IntView,PC_INT_DOM>::x2
;
359
int
w
;
361
Pair
(
Space
& home,
bool
share,
Pair
& p);
362
public
:
364
Pair
(
Home
home,
IntView
x0,
IntView
x1,
IntView
x2,
int
w);
366
static
ExecStatus
post
(
Home
home,
IntView
x0,
IntView
x1,
IntView
x2,
367
int
w,
int
h);
369
GECODE_INT_EXPORT
virtual
Actor
* copy(
Space
& home,
bool
share);
371
GECODE_INT_EXPORT
virtual
ExecStatus
propagate(
Space
& home,
const
ModEventDelta
& med);
372
};
373
374
}}}
375
376
#include <
gecode/int/element/int.hpp
>
377
#include <
gecode/int/element/view.hpp
>
378
#include <
gecode/int/element/pair.hpp
>
379
380
#endif
381
382
383
// STATISTICS: int-prop
384