main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
int
extensional
base.hpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Mikael Lagerkvist <lagerkvist@gecode.org>
5
*
6
* Contributing authors:
7
* Christian Schulte <schulte@gecode.org>
8
*
9
* Copyright:
10
* Mikael Lagerkvist, 2007
11
* Christian Schulte, 2008
12
*
13
* Last modified:
14
* $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
15
* $Revision: 15137 $
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
namespace
Gecode
{
namespace
Int {
namespace
Extensional {
42
/*
43
* The propagator proper
44
*
45
*/
46
47
template
<
class
View,
bool
subscribe>
48
forceinline
49
Base<View,subscribe>::Base
(
Home
home,
ViewArray<View>
& x0,
50
const
TupleSet
&
t
)
51
:
Propagator
(home),
x
(x0), tupleSet(
t
), last_data(NULL) {
52
if
(
subscribe
)
53
x
.subscribe(home, *
this
,
PC_INT_DOM
);
54
55
assert(ts()->finalized());
56
57
init_last(home, ts()->last, ts()->tuple_data);
58
59
home.
notice
(*
this
,
AP_DISPOSE
);
60
}
61
62
template
<
class
View,
bool
subscribe>
63
forceinline
64
Base<View,subscribe>::Base
(
Space
& home,
bool
share,
Base<View,subscribe>
&
p
)
65
:
Propagator
(home,share,
p
), last_data(NULL) {
66
x
.update(home, share,
p
.x);
67
tupleSet.update(home, share,
p
.tupleSet);
68
69
init_last(home,
p
.last_data,
p
.ts()->tuple_data);
70
}
71
72
template
<
class
View,
bool
subscribe>
73
forceinline
void
74
Base<View,subscribe>::init_last
(
Space
& home,
Tuple
** source,
Tuple
*
base
) {
75
if
(last_data == NULL) {
76
int
literals =
static_cast<
int
>
(ts()->domsize*
x
.size());
77
last_data = home.
alloc
<
Tuple
*>(literals);
78
for
(
int
i
= literals;
i
--; )
79
last_data[
i
] = ts()->tuple_data+(source[
i
]-
base
);
80
}
81
}
82
83
template
<
class
View,
bool
subscribe>
84
forceinline
TupleSet::TupleSetI
*
85
Base<View,subscribe>::ts
(
void
) {
86
return
tupleSet.implementation();
87
}
88
89
template
<
class
View,
bool
subscribe>
90
void
91
Base<View,subscribe>::reschedule
(
Space
& home) {
92
if
(
subscribe
)
93
x
.reschedule(home, *
this
,
PC_INT_DOM
);
94
}
95
96
template
<
class
View,
bool
subscribe>
97
PropCost
98
Base<View,subscribe>::cost
(
const
Space
&,
const
ModEventDelta
&)
const
{
99
return
PropCost::quadratic(PropCost::HI,
x
.size());
100
}
101
102
#define GECODE_LAST_TUPLE(l) (*(l))
103
104
template
<
class
View,
bool
subscribe>
105
forceinline
Tuple
106
Base<View,subscribe>::last
(
int
i
,
int
n
) {
107
return
GECODE_LAST_TUPLE
(last_data[(
i
*ts()->domsize) +
n
]);
108
}
109
110
template
<
class
View,
bool
subscribe>
111
forceinline
Tuple
112
Base<View,subscribe>::last_next
(
int
i
,
int
n
) {
113
assert(last(
i
,
n
) != NULL);
114
assert(last(
i
,
n
)[
i
] ==
n
+ts()->
min
);
115
int
pos
= (
i
*
static_cast<
int
>
(ts()->domsize)) +
n
;
116
++(last_data[
pos
]);
117
if
(last(
i
,
n
)[
i
] != (
n
+ts()->min))
118
last_data[
pos
] = ts()->nullpointer;
119
return
last(
i
,
n
);
120
}
121
122
123
template
<
class
View,
bool
subscribe>
124
forceinline
void
125
Base<View,subscribe>::init_dom
(
Space
& home,
Domain
dom
) {
126
unsigned
int
domsize = ts()->domsize;
127
for
(
int
i
=
x
.size();
i
--; ) {
128
dom
[
i
].init(home, domsize);
129
for
(
ViewValues<View>
vv(
x
[
i
]); vv(); ++vv)
130
dom
[
i
].set(
static_cast<
unsigned
int
>
(vv.val()-ts()->
min
));
131
}
132
}
133
134
template
<
class
View,
bool
subscribe>
135
forceinline
bool
136
Base<View,subscribe>::valid
(
Tuple
t
,
Domain
dom
) {
137
for
(
int
i
=
x
.size();
i
--; )
138
if
(!
dom
[
i
].get(
static_cast<
unsigned
int
>
(
t
[
i
]-ts()->
min
)))
139
return
false
;
140
return
true
;
141
}
142
#undef GECODE_LAST_TUPLE
143
template
<
class
View,
bool
subscribe>
144
forceinline
Tuple
145
Base<View,subscribe>::find_support
(
Domain
dom
,
int
i
,
int
n
) {
146
Tuple
l
= last(
i
,
n
);
147
while
((
l
!= NULL) && !
valid
(
l
,
dom
))
148
l
= last_next(
i
,
n
);
149
return
l
;
150
}
151
152
153
template
<
class
View,
bool
subscribe>
154
forceinline
size_t
155
Base<View,subscribe>::dispose
(
Space
& home) {
156
home.
ignore
(*
this
,
AP_DISPOSE
);
157
(void) Propagator::dispose(home);
158
if
(
subscribe
)
159
x
.cancel(home,*
this
,
PC_INT_DOM
);
160
// take care of last_data
161
unsigned
int
literals = ts()->domsize*
x
.size();
162
home.
rfree
(last_data,
sizeof
(
Tuple
*)*literals);
163
(void) tupleSet.~TupleSet();
164
return
sizeof
(*this);
165
}
166
167
}}}
168
169
// STATISTICS: int-prop
170
Gecode::Home::notice
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition:
core.hpp:3321
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
GECODE_LAST_TUPLE
#define GECODE_LAST_TUPLE(l)
Definition:
base.hpp:102
Gecode::FloatVal::min
FloatVal min(const FloatVal &x, const FloatVal &y)
Return minimum of x and y.
Definition:
val.hpp:402
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:234
Gecode::Int::ViewValues
Value iterator for integer views.
Definition:
view.hpp:94
Gecode::Float::Limits::valid
bool valid(const FloatVal &n)
Return whether float n is a valid number.
Definition:
limits.hpp:43
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Int::Extensional::Base
Base for domain consistent extensional propagation
Definition:
extensional.hh:244
Gecode
Gecode toplevel namespace
Gecode::Propagator
Base-class for propagators.
Definition:
core.hpp:1092
Gecode::Int::Extensional::Base::Base
Base(Space &home, bool share, Base< View, subscribe > &p)
Constructor for cloning p.
Definition:
base.hpp:64
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Gecode::Int::Count::reschedule
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition:
rel.hpp:96
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::AP_DISPOSE
@ AP_DISPOSE
Actor must always be disposed.
Definition:
core.hpp:630
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition:
dom.cpp:44
Gecode::Support::BitSetBase
Basic bitset support.
Definition:
bitset-base.hpp:178
Gecode::Space::alloc
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
Definition:
core.hpp:2868
Gecode::Search::Config::base
const double base
Base for geometric restart sequence.
Definition:
search.hh:122
Gecode::Int::Extensional::Tuple
TupleSet::Tuple Tuple
Definition:
extensional.hh:229
Gecode::TupleSet
Class represeting a set of tuples.
Definition:
int.hh:2161
Pentominoes::pos
int pos(int h, int w, int h1, int w1)
Gecode::PropCost
Propagation cost.
Definition:
core.hpp:554
l
NNF * l
Left subtree.
Definition:
bool-expr.cpp:244
Gecode::Space::rfree
void rfree(void *p, size_t s)
Free memory previously allocated with alloc (might be reused later)
Definition:
core.hpp:2834
Gecode::Space::ignore
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition:
core.hpp:4141
Gecode::ViewArray
View arrays.
Definition:
array.hpp:234
Gecode::Int::Count::subscribe
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition:
rel.hpp:75
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Int::PC_INT_DOM
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition:
var-type.hpp:100
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236
Gecode::TupleSet::TupleSetI
Data stored for a Table.
Definition:
int.hh:2173