main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
gecode
int
element
pair.cpp
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, 2009
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 <
gecode/int/element.hh
>
35
36
namespace
Gecode
{
namespace
Int {
namespace
Element {
37
38
Actor*
39
Pair::copy
(
Space
& home) {
40
return
new
(home)
Pair
(home,*
this
);
41
}
42
44
class
PairValues
{
45
private
:
47
IntView
x;
49
ViewValues<IntView>
xv;
51
ViewValues<IntView>
yv;
53
int
w;
54
public
:
56
57
PairValues
(
IntView
x
,
IntView
y
,
int
w);
60
62
63
bool
operator ()
(
void
)
const
;
66
void
operator ++
(
void
);
68
70
71
int
val
(
void
)
const
;
74
};
75
76
forceinline
77
PairValues::PairValues
(
IntView
x0,
IntView
y0,
int
w0)
78
:
x
(x0), xv(x0), yv(y0), w(w0) {}
79
forceinline
void
80
PairValues::operator ++
(
void
) {
81
++xv;
82
if
(!xv()) {
83
xv.
init
(x); ++yv;
84
}
85
}
86
forceinline
bool
87
PairValues::operator ()
(
void
)
const
{
88
return
yv();
89
}
90
forceinline
int
91
PairValues::val
(
void
)
const
{
92
return
xv.
val
()+w*yv.
val
();
93
}
94
95
96
ExecStatus
97
Pair::propagate
(
Space
& home,
const
ModEventDelta
&) {
98
Region
r
;
99
100
if
(
x0
.
assigned
()) {
101
// Bitset for supported div and mod values
102
Support::BitSet<Region>
d
(
r
,
static_cast<
unsigned
int
>
((
x2
.
max
() /
w
)+1));
103
for
(
ViewValues<IntView>
i
(
x2
);
i
(); ++
i
) {
104
d
.set(
static_cast<
unsigned
int
>
(
i
.val() /
w
));
105
}
106
Iter::Values::BitSet<Support::BitSet<Region>
>
id
(
d
,
x1
.
min
(),
x1
.
max
());
107
GECODE_ME_CHECK
(
x1
.
inter_v
(home,
id
,
false
));
108
}
else
{
109
// Bitset for supported div and mod values
110
Support::BitSet<Region>
111
d
(
r
,
static_cast<
unsigned
int
>
((
x2
.
max
() /
w
)+1)),
112
m(
r
,
static_cast<
unsigned
int
>
(
w
));
113
for
(
ViewValues<IntView>
i
(
x2
);
i
(); ++
i
) {
114
d
.set(
static_cast<
unsigned
int
>
(
i
.val() /
w
));
115
m.
set
(
static_cast<
unsigned
int
>
(
i
.val() %
w
));
116
}
117
Iter::Values::BitSet<Support::BitSet<Region>
> im(m,
x0
.
min
(),
x0
.
max
());
118
GECODE_ME_CHECK
(
x0
.
inter_v
(home,im,
false
));
119
Iter::Values::BitSet<Support::BitSet<Region>
>
id
(
d
,
x1
.
min
(),
x1
.
max
());
120
GECODE_ME_CHECK
(
x1
.
inter_v
(home,
id
,
false
));
121
}
122
123
if
(
x0
.
assigned
() &&
x1
.
assigned
()) {
124
GECODE_ME_CHECK
(
x2
.
eq
(home,
x0
.
val
()+
w
*
x1
.
val
()));
125
return
home.
ES_SUBSUMED
(*
this
);
126
}
else
if
(
x1
.
assigned
()) {
127
OffsetView
x0x1w(
x0
,
x1
.
val
()*
w
);
128
GECODE_REWRITE
(*
this
,(
Rel::EqDom<OffsetView,IntView>
129
::
post
(home(*
this
),x0x1w,
x2
)));
130
}
131
132
PairValues
xy(
x0
,
x1
,
w
);
133
GECODE_ME_CHECK
(
x2
.
inter_v
(home,xy,
false
));
134
135
if
(
x2
.
assigned
()) {
136
GECODE_ME_CHECK
(
x0
.
eq
(home,
x2
.
val
() %
w
));
137
GECODE_ME_CHECK
(
x1
.
eq
(home,
static_cast<
int
>
(
x2
.
val
() /
w
)));
138
return
home.
ES_SUBSUMED
(*
this
);
139
}
140
141
return
ES_NOFIX
;
142
}
143
144
}}}
145
146
// STATISTICS: int-prop
147
Gecode::Int::Element::PairValues::operator++
void operator++(void)
Move iterator to next value (if possible)
Definition:
pair.cpp:80
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Int::Element::PairValues::PairValues
PairValues(IntView x, IntView y, int w)
Initialize with views x and y and width w.
Definition:
pair.cpp:77
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::Support::BitSetBase::set
void set(unsigned int i)
Set bit i.
Definition:
bitset-base.hpp:595
Gecode::Iter::Values::BitSet
Value iterator for values in a bitset.
Definition:
values-bitset.hpp:42
Gecode::Propagator::id
unsigned int id(void) const
Return propagator id.
Definition:
core.hpp:3542
Gecode::VarImpView::assigned
bool assigned(void) const
Test whether view is assigned.
Definition:
view.hpp:516
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::x1
IntView x1
Definition:
pattern.hpp:116
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Int::IntView::min
int min(void) const
Return minimum of domain.
Definition:
int.hpp:58
Gecode::Int::Element::PairValues::val
int val(void) const
Return current value.
Definition:
pair.cpp:91
Gecode::Int::Element::Pair::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
pair.cpp:39
Gecode::Int::ViewValues::init
void init(const View &x)
Initialize with values x.
Definition:
iter.hpp:53
Gecode::Int::ViewValues< IntView >
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Int::Element::Pair::w
int w
Width.
Definition:
element.hh:304
Gecode::Int::Element::PairValues::operator()
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition:
pair.cpp:87
Gecode::Iter::Ranges::ToValues::val
int val(void) const
Return current value.
Definition:
ranges-values.hpp:129
Gecode::Int::Element::Pair::post
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition:
pair.hpp:43
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::x2
IntView x2
Definition:
pattern.hpp:116
Gecode
Gecode toplevel namespace
Gecode::Int::IntView::max
int max(void) const
Return maximum of domain.
Definition:
int.hpp:62
Gecode::Int::Rel::EqDom
Binary domain consistent equality propagator.
Definition:
rel.hh:67
Gecode::Int::Element::Pair::Pair
Pair(Space &home, Pair &p)
Constructor for cloning p.
Definition:
pair.hpp:64
Gecode::Int::IntView::val
int val(void) const
Return assigned value (only if assigned)
Definition:
int.hpp:70
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Gecode::Region
Handle to region.
Definition:
region.hpp:55
Gecode::Int::IntView::inter_v
ModEvent inter_v(Space &home, I &i, bool depends=true)
Intersect domain with values described by i.
Definition:
int.hpp:201
element.hh
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::TernaryPropagator< IntView, PC_INT_DOM >::x0
IntView x0
Three views.
Definition:
pattern.hpp:116
Gecode::Int::OffsetView
Offset integer view.
Definition:
view.hpp:443
Gecode::Int::Element::Pair::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
pair.cpp:97
Gecode::Support::BitSet< Region >
Test::Int::Distinct::d
Gecode::IntSet d(v, 7)
Gecode::Int::IntView
Integer view for integer variables.
Definition:
view.hpp:129
forceinline
#define forceinline
Definition:
config.hpp:185
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:52
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:89
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition:
core.hpp:475
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition:
macros.hpp:116
Gecode::Int::IntView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition:
int.hpp:166
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:472
Gecode::Int::Element::PairValues
Value iterator for pair of iterators.
Definition:
pair.cpp:44