main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Feb 14 2013 20:59:41 for Gecode by
doxygen
1.8.3.1
gecode
int
var-imp.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
* Contributing authors:
7
* Guido Tack <tack@gecode.org>
8
*
9
* Copyright:
10
* Christian Schulte, 2002
11
* Guido Tack, 2004
12
*
13
* Last modified:
14
* $Date: 2010-06-03 05:01:00 +1000 (Thu, 03 Jun 2010) $ by $Author: schulte $
15
* $Revision: 11008 $
16
*
17
* This file is part of Gecode, the generic constraint
18
* development environment:
19
* http://www.gecode.org
20
*
21
* Permission is hereby granted, free of charge, to any person obtaining
22
* a copy of this software and associated documentation files (the
23
* "Software"), to deal in the Software without restriction, including
24
* without limitation the rights to use, copy, modify, merge, publish,
25
* distribute, sublicense, and/or sell copies of the Software, and to
26
* permit persons to whom the Software is furnished to do so, subject to
27
* the following conditions:
28
*
29
* The above copyright notice and this permission notice shall be
30
* included in all copies or substantial portions of the Software.
31
*
32
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
*
40
*/
41
42
#include <cmath>
43
44
namespace
Gecode {
namespace
Int {
45
46
class
IntVarImp;
47
class
BoolVarImp;
48
55
class
IntDelta
:
public
Delta
{
56
friend
class
IntVarImp
;
57
friend
class
BoolVarImp
;
58
private
:
59
int
_min
;
60
int
_max
;
61
public
:
63
IntDelta
(
void
);
65
IntDelta
(
int
min
,
int
max
);
67
IntDelta
(
int
min
);
68
private
:
70
int
min
(
void
)
const
;
72
int
max
(
void
)
const
;
74
bool
any
(
void
)
const
;
75
};
76
77
}}
78
79
#include <
gecode/int/var-imp/delta.hpp
>
80
81
namespace
Gecode {
namespace
Int {
82
83
class
IntVarImpFwd;
84
class
IntVarImpBwd;
85
91
class
IntVarImp
:
public
IntVarImpBase
{
92
friend
class
IntVarImpFwd
;
93
friend
class
IntVarImpBwd
;
94
protected
:
104
class
RangeList
:
public
FreeList
{
105
protected
:
107
int
_min
;
109
int
_max
;
110
public
:
112
113
114
RangeList
(
void
);
116
RangeList
(
int
min
,
int
max
);
118
RangeList
(
int
min
,
int
max
,
RangeList
* p,
RangeList
* n);
120
122
123
124
int
min
(
void
)
const
;
126
int
max
(
void
)
const
;
128
unsigned
int
width
(
void
)
const
;
129
131
RangeList
*
next
(
const
RangeList
* p)
const
;
133
RangeList
*
prev
(
const
RangeList
* n)
const
;
135
137
138
139
void
min
(
int
n);
141
void
max
(
int
n);
142
144
void
prevnext
(
RangeList
* p,
RangeList
* n);
146
void
next
(
RangeList
* o,
RangeList
* n);
148
void
prev
(
RangeList
* o,
RangeList
* n);
150
void
fix
(
RangeList
* n);
152
154
155
160
void
dispose
(
Space
& home,
RangeList
* p,
RangeList
* l);
166
void
dispose
(
Space
& home,
RangeList
* l);
168
void
dispose
(
Space
& home);
169
171
static
void
*
operator
new
(
size_t
s,
Space
& home);
173
static
void
*
operator
new
(
size_t
s,
void
* p);
175
static
void
operator
delete
(
void
*);
177
static
void
operator
delete
(
void
*,
Space
&);
179
static
void
operator
delete
(
void
*,
void
*);
181
};
182
190
RangeList
dom
;
192
RangeList
*
_lst
;
194
RangeList
*
fst
(
void
)
const
;
196
void
fst
(
RangeList
* f);
198
RangeList
*
lst
(
void
)
const
;
200
void
lst
(
RangeList
* l);
202
unsigned
int
holes
;
203
204
protected
:
206
IntVarImp
(
Space
& home,
bool
share,
IntVarImp
& x);
207
public
:
209
IntVarImp
(
Space
& home,
int
min
,
int
max
);
211
IntVarImp
(
Space
& home,
const
IntSet
&
d
);
212
214
215
216
int
min
(
void
)
const
;
218
int
max
(
void
)
const
;
220
int
val
(
void
)
const
;
222
GECODE_INT_EXPORT
int
med
(
void
)
const
;
223
225
unsigned
int
size
(
void
)
const
;
227
unsigned
int
width
(
void
)
const
;
229
unsigned
int
regret_min
(
void
)
const
;
231
unsigned
int
regret_max
(
void
)
const
;
233
234
private
:
236
GECODE_INT_EXPORT
bool
in_full(
int
n)
const
;
237
238
public
:
240
241
242
bool
range
(
void
)
const
;
244
bool
assigned
(
void
)
const
;
245
247
bool
in
(
int
n)
const
;
249
bool
in
(
double
n)
const
;
251
252
protected
:
254
255
256
const
RangeList
*
ranges_fwd
(
void
)
const
;
258
const
RangeList
*
ranges_bwd
(
void
)
const
;
260
261
private
:
263
bool
closer_min(
int
b)
const
;
265
266
267
GECODE_INT_EXPORT
ModEvent
lq_full(
Space
& home,
int
n);
269
GECODE_INT_EXPORT
ModEvent
gq_full(
Space
& home,
int
n);
271
GECODE_INT_EXPORT
ModEvent
eq_full(
Space
& home,
int
n);
273
GECODE_INT_EXPORT
ModEvent
nq_full(
Space
& home,
int
n);
275
public
:
277
278
279
ModEvent
lq
(
Space
& home,
int
n);
281
ModEvent
lq
(
Space
& home,
double
n);
282
284
ModEvent
gq
(
Space
& home,
int
n);
286
ModEvent
gq
(
Space
& home,
double
n);
287
289
ModEvent
nq
(
Space
& home,
int
n);
291
ModEvent
nq
(
Space
& home,
double
n);
292
294
ModEvent
eq
(
Space
& home,
int
n);
296
ModEvent
eq
(
Space
& home,
double
n);
298
315
316
template
<
class
I>
317
ModEvent
narrow_r
(
Space
& home, I&
i
,
bool
depends=
true
);
319
template
<
class
I>
320
ModEvent
inter_r
(
Space
& home, I&
i
,
bool
depends=
true
);
322
template
<
class
I>
323
ModEvent
minus_r
(
Space
& home, I&
i
,
bool
depends=
true
);
325
template
<
class
I>
326
ModEvent
narrow_v
(
Space
& home, I&
i
,
bool
depends=
true
);
328
template
<
class
I>
329
ModEvent
inter_v
(
Space
& home, I&
i
,
bool
depends=
true
);
331
template
<
class
I>
332
ModEvent
minus_v
(
Space
& home, I&
i
,
bool
depends=
true
);
334
336
337
345
void
subscribe
(
Space
& home,
Propagator
& p,
PropCond
pc,
bool
schedule
=
true
);
347
void
cancel
(
Space
& home,
Propagator
& p,
PropCond
pc);
349
void
subscribe
(
Space
& home,
Advisor
&
a
);
351
void
cancel
(
Space
& home,
Advisor
&
a
);
353
355
356
357
static
ModEventDelta
med
(
ModEvent
me
);
359
360
361
private
:
363
GECODE_INT_EXPORT
IntVarImp
* perform_copy(
Space
& home,
bool
share);
364
public
:
366
367
368
IntVarImp
*
copy
(
Space
& home,
bool
share);
370
372
373
374
static
int
min
(
const
Delta
&
d
);
376
static
int
max
(
const
Delta
&
d
);
378
static
bool
any
(
const
Delta
&
d
);
380
};
381
382
387
class
IntVarImpFwd
{
388
private
:
390
const
IntVarImp::RangeList
* p;
392
const
IntVarImp::RangeList
* c;
393
public
:
395
396
397
IntVarImpFwd
(
void
);
399
IntVarImpFwd
(
const
IntVarImp
* x);
401
void
init
(
const
IntVarImp
* x);
403
405
406
407
bool
operator ()
(
void
)
const
;
409
void
operator ++
(
void
);
411
413
414
415
int
min
(
void
)
const
;
417
int
max
(
void
)
const
;
419
unsigned
int
width
(
void
)
const
;
421
};
422
430
class
IntVarImpBwd
{
431
private
:
433
const
IntVarImp::RangeList
* n;
435
const
IntVarImp::RangeList
* c;
436
public
:
438
439
440
IntVarImpBwd
(
void
);
442
IntVarImpBwd
(
const
IntVarImp
* x);
444
void
init
(
const
IntVarImp
* x);
446
448
449
450
bool
operator ()
(
void
)
const
;
452
void
operator ++
(
void
);
454
456
457
458
int
min
(
void
)
const
;
460
int
max
(
void
)
const
;
462
unsigned
int
width
(
void
)
const
;
464
};
465
466
}}
467
468
#include <
gecode/int/var-imp/int.hpp
>
469
470
namespace
Gecode {
471
472
class
IntVar;
473
class
BoolVar;
474
}
475
476
namespace
Gecode {
namespace
Int {
477
479
typedef
unsigned
int
BoolStatus
;
480
486
class
BoolVarImp
:
public
BoolVarImpBase
{
487
friend
class ::Gecode::BoolVar;
488
private
:
500
GECODE_INT_EXPORT
static
BoolVarImp
s_one;
501
GECODE_INT_EXPORT
static
BoolVarImp
s_zero;
502
504
BoolVarImp
(
Space
& home,
bool
share,
BoolVarImp
& x);
506
BoolVarImp
(
int
n);
507
public
:
509
BoolVarImp
(
Space
& home,
int
min
,
int
max
);
510
512
513
514
static
const
int
BITS
= 2;
516
static
const
BoolStatus
ZERO
= 0;
518
static
const
BoolStatus
ONE
= 3;
520
static
const
BoolStatus
NONE
= 2;
522
BoolStatus
status
(
void
)
const
;
524
526
527
528
int
min
(
void
)
const
;
530
int
max
(
void
)
const
;
532
int
val
(
void
)
const
;
534
int
med
(
void
)
const
;
535
537
unsigned
int
size
(
void
)
const
;
539
unsigned
int
width
(
void
)
const
;
541
unsigned
int
regret_min
(
void
)
const
;
543
unsigned
int
regret_max
(
void
)
const
;
545
547
548
549
bool
zero
(
void
)
const
;
551
bool
one
(
void
)
const
;
553
bool
none
(
void
)
const
;
555
557
558
559
bool
range
(
void
)
const
;
561
bool
assigned
(
void
)
const
;
562
564
bool
in
(
int
n)
const
;
566
bool
in
(
double
n)
const
;
568
570
571
572
ModEvent
lq
(
Space
& home,
int
n);
574
ModEvent
lq
(
Space
& home,
double
n);
575
577
ModEvent
gq
(
Space
& home,
int
n);
579
ModEvent
gq
(
Space
& home,
double
n);
580
582
ModEvent
nq
(
Space
& home,
int
n);
584
ModEvent
nq
(
Space
& home,
double
n);
585
587
ModEvent
eq
(
Space
& home,
int
n);
589
ModEvent
eq
(
Space
& home,
double
n);
591
608
609
template
<
class
I>
610
ModEvent
narrow_r
(
Space
& home, I&
i
,
bool
depends=
true
);
612
template
<
class
I>
613
ModEvent
inter_r
(
Space
& home, I&
i
,
bool
depends=
true
);
615
template
<
class
I>
616
ModEvent
minus_r
(
Space
& home, I&
i
,
bool
depends=
true
);
618
template
<
class
I>
619
ModEvent
narrow_v
(
Space
& home, I&
i
,
bool
depends=
true
);
621
template
<
class
I>
622
ModEvent
inter_v
(
Space
& home, I&
i
,
bool
depends=
true
);
624
template
<
class
I>
625
ModEvent
minus_v
(
Space
& home, I&
i
,
bool
depends=
true
);
627
629
630
631
ModEvent
zero
(
Space
& home);
633
ModEvent
one
(
Space
& home);
635
GECODE_INT_EXPORT
ModEvent
zero_none
(
Space
& home);
637
GECODE_INT_EXPORT
ModEvent
one_none
(
Space
& home);
639
640
public
:
642
643
653
void
subscribe
(
Space
& home,
Propagator
& p,
PropCond
pc,
bool
schedule
=
true
);
660
void
cancel
(
Space
& home,
Propagator
& p,
PropCond
pc);
662
void
subscribe
(
Space
& home,
Advisor
&
a
);
664
void
cancel
(
Space
& home,
Advisor
&
a
);
666
668
669
676
static
void
schedule
(
Space
& home,
Propagator
& p,
ModEvent
me
);
678
static
ModEventDelta
med
(
ModEvent
me
);
680
682
683
684
static
ModEvent
modevent
(
const
Delta
&
d
);
686
static
int
min
(
const
Delta
&
d
);
688
static
int
max
(
const
Delta
&
d
);
690
static
bool
any
(
const
Delta
&
d
);
692
static
bool
zero
(
const
Delta
&
d
);
694
static
bool
one
(
const
Delta
&
d
);
696
698
699
700
BoolVarImp
*
copy
(
Space
& home,
bool
share);
702
703
};
704
705
}}
706
707
#include <
gecode/int/var-imp/bool.hpp
>
708
709
// STATISTICS: int-var
710