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
nvalues
bool-eq.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
* Copyright:
7
* Christian Schulte, 2011
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/rel.hh
>
35
#include <
gecode/int/bool.hh
>
36
37
namespace
Gecode
{
namespace
Int {
namespace
NValues {
38
39
template
<
class
VY>
40
forceinline
41
EqBool<VY>::EqBool
(
Home
home,
int
status,
ViewArray<BoolView>
&
x
, VY
y
)
42
:
BoolBase
<VY>(home,status,
x
,
y
) {}
43
44
template
<
class
VY>
45
forceinline
46
EqBool<VY>::EqBool
(
Space
& home,
EqBool<VY>
&
p
)
47
:
BoolBase
<VY>(home,
p
) {}
48
49
template
<
class
VY>
50
Actor
*
51
EqBool<VY>::copy
(
Space
& home) {
52
return
new
(home)
EqBool<VY>
(home,*
this
);
53
}
54
55
template
<
class
VY>
56
inline
ExecStatus
57
EqBool<VY>::post
(
Home
home,
ViewArray<BoolView>
&
x
, VY
y
) {
58
if
(
x
.size() == 0) {
59
GECODE_ME_CHECK
(
y
.eq(home,0));
60
return
ES_OK
;
61
}
62
63
x
.unique();
64
65
if
(
x
.size() == 1) {
66
GECODE_ME_CHECK
(
y
.eq(home,1));
67
return
ES_OK
;
68
}
69
70
GECODE_ME_CHECK
(
y
.gq(home,1));
71
GECODE_ME_CHECK
(
y
.lq(home,2));
72
73
if
(
y
.max() == 1) {
74
assert(
y
.
assigned
());
75
ViewArray<BoolView>
xc(home,
x
);
76
return
Bool::NaryEq<BoolView>::post
(home,xc);
77
}
78
79
if
(
y
.min() == 2) {
80
assert(
y
.
assigned
());
81
ViewArray<BoolView>
xc(home,
x
);
82
return
Rel::NaryNq<BoolView>::post
(home,xc);
83
}
84
85
int
n
=
x
.size();
86
int
status = 0;
87
for
(
int
i
=
n
;
i
--; )
88
if
(
x
[
i
].zero()) {
89
if
(status & VS_ONE) {
90
GECODE_ME_CHECK
(
y
.eq(home,2));
91
return
ES_OK
;
92
}
93
x
[
i
] =
x
[--
n
];
94
status |= VS_ZERO;
95
}
else
if
(
x
[
i
].
one
()) {
96
if
(status & VS_ZERO) {
97
GECODE_ME_CHECK
(
y
.eq(home,2));
98
return
ES_OK
;
99
}
100
x
[
i
] =
x
[--
n
];
101
status |= VS_ONE;
102
}
103
104
assert(status != (VS_ZERO | VS_ONE));
105
if
(
n
== 0) {
106
assert(status != 0);
107
GECODE_ME_CHECK
(
y
.eq(home,1));
108
return
ES_OK
;
109
}
110
x
.size(
n
);
111
112
(void)
new
(home)
EqBool<VY>
(home,status,
x
,
y
);
113
return
ES_OK
;
114
}
115
116
template
<
class
VY>
117
ExecStatus
118
EqBool<VY>::propagate
(
Space
& home,
const
ModEventDelta
&) {
119
if
(status == (VS_ZERO | VS_ONE)) {
120
GECODE_ME_CHECK
(
y
.eq(home,2));
121
return
home.
ES_SUBSUMED
(*
this
);
122
}
123
124
if
(
c
.empty()) {
125
assert(status != 0);
126
GECODE_ME_CHECK
(
y
.eq(home,1));
127
return
home.
ES_SUBSUMED
(*
this
);
128
}
129
130
if
(
y
.max() == 1) {
131
if
(status == VS_ZERO) {
132
// Mark that everything is done
133
status = VS_ZERO | VS_ONE;
134
for
(
Advisors
<
ViewAdvisor<BoolView>
> as(
c
); as(); ++as)
135
GECODE_ME_CHECK
(as.advisor().view().zero(home));
136
return
home.
ES_SUBSUMED
(*
this
);
137
}
138
if
(status == VS_ONE) {
139
// Mark that everything is done
140
status = VS_ZERO | VS_ONE;
141
for
(
Advisors
<
ViewAdvisor<BoolView>
> as(
c
); as(); ++as)
142
GECODE_ME_CHECK
(as.advisor().view().one(home));
143
return
home.
ES_SUBSUMED
(*
this
);
144
}
145
}
146
147
if
(
y
.min() == 2) {
148
Advisors<ViewAdvisor<BoolView>
> as(
c
);
149
assert(as());
150
ViewAdvisor<BoolView>
&
a
(as.
advisor
());
151
++as;
152
if
(!as()) {
153
// Only a single view is left
154
if
(status == VS_ZERO) {
155
GECODE_ME_CHECK
(
a
.view().one(home));
156
}
else
if
(status == VS_ONE) {
157
GECODE_ME_CHECK
(
a
.view().zero(home));
158
}
else
{
159
return
ES_FAILED
;
160
}
161
return
home.
ES_SUBSUMED
(*
this
);
162
}
163
}
164
165
return
ES_FIX
;
166
}
167
168
}}}
169
170
// STATISTICS: int-prop
Gecode::Int::NValues::EqBool::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
bool-eq.hpp:51
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Int::NValues::EqBool::EqBool
EqBool(Home home, int status, ViewArray< BoolView > &x, VY y)
Constructor for posting.
Definition:
bool-eq.hpp:41
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::Int::Bool::NaryEq::post
static ExecStatus post(Home home, ViewArray< BV > &x)
Post propagator .
Definition:
eq.hpp:131
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Advisors
Class to iterate over advisors of a council.
Definition:
core.hpp:156
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::ViewAdvisor
Advisor storing a single view
Definition:
advisor.hpp:43
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:628
Gecode::VarImpVar::assigned
bool assigned(void) const
Test whether view is assigned.
Definition:
var.hpp:111
bool.hh
Gecode::Int::NValues::EqBool::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
bool-eq.hpp:118
Gecode::Int::NValues::EqBool
Equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:327
Gecode
Gecode toplevel namespace
Gecode::Int::NValues::EqBool::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition:
bool-eq.hpp:57
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::Int::NValues::BoolBase
Number of values propagator for Boolean views base class.
Definition:
nvalues.hh:293
Test::Float::Linear::one
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition:
linear.cpp:46
Gecode::Int::Rel::NaryNq::post
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator .
Definition:
nq.hpp:118
a
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
rel.hh
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:477
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
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::ViewArray< BoolView >
Gecode::Advisors::advisor
A & advisor(void) const
Return advisor.
Definition:
core.hpp:4010
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition:
core.hpp:474
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:89
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:476
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:472