main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Jul 27 2020 00:00:00 for Gecode by
doxygen
1.8.18
gecode
int
nvalues
bool-gq.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
36
namespace
Gecode
{
namespace
Int {
namespace
NValues {
37
38
template
<
class
VY>
39
forceinline
40
GqBool<VY>::GqBool
(
Home
home,
int
status,
ViewArray<BoolView>
&
x
, VY
y
)
41
:
BoolBase
<VY>(home,status,
x
,
y
) {}
42
43
template
<
class
VY>
44
forceinline
45
GqBool<VY>::GqBool
(
Space
& home,
GqBool<VY>
&
p
)
46
:
BoolBase
<VY>(home,
p
) {}
47
48
template
<
class
VY>
49
Actor
*
50
GqBool<VY>::copy
(
Space
& home) {
51
return
new
(home)
GqBool<VY>
(home,*
this
);
52
}
53
54
template
<
class
VY>
55
inline
ExecStatus
56
GqBool<VY>::post
(
Home
home,
ViewArray<BoolView>
&
x
, VY
y
) {
57
if
(
x
.size() == 0) {
58
GECODE_ME_CHECK
(
y
.lq(home,0));
59
return
ES_OK
;
60
}
61
62
x
.unique();
63
64
if
(
x
.size() == 1) {
65
GECODE_ME_CHECK
(
y
.lq(home,1));
66
return
ES_OK
;
67
}
68
69
GECODE_ME_CHECK
(
y
.lq(home,2));
70
71
if
(
y
.max() <= 1)
72
return
ES_OK
;
73
74
if
(
y
.min() == 2) {
75
assert(
y
.
assigned
());
76
ViewArray<BoolView>
xc(home,
x
);
77
return
Rel::NaryNq<BoolView>::post
(home,xc);
78
}
79
80
int
n
=
x
.size();
81
int
status = 0;
82
for
(
int
i
=
n
;
i
--; )
83
if
(
x
[
i
].zero()) {
84
if
(status & VS_ONE)
85
return
ES_OK
;
86
x
[
i
] =
x
[--
n
];
87
status |= VS_ZERO;
88
}
else
if
(
x
[
i
].
one
()) {
89
if
(status & VS_ZERO)
90
return
ES_OK
;
91
x
[
i
] =
x
[--
n
];
92
status |= VS_ONE;
93
}
94
95
assert(status != (VS_ZERO | VS_ONE));
96
if
(
n
== 0) {
97
assert(status != 0);
98
GECODE_ME_CHECK
(
y
.lq(home,1));
99
return
ES_OK
;
100
}
101
x
.size(
n
);
102
103
(void)
new
(home)
GqBool<VY>
(home,status,
x
,
y
);
104
return
ES_OK
;
105
}
106
107
template
<
class
VY>
108
ExecStatus
109
GqBool<VY>::propagate
(
Space
& home,
const
ModEventDelta
&) {
110
if
(status == (VS_ZERO | VS_ONE))
111
return
home.
ES_SUBSUMED
(*
this
);
112
113
if
(
c
.empty()) {
114
assert(status != 0);
115
GECODE_ME_CHECK
(
y
.lq(home,1));
116
return
home.
ES_SUBSUMED
(*
this
);
117
}
118
119
if
(
y
.max() <= 1)
120
return
home.
ES_SUBSUMED
(*
this
);
121
122
if
(
y
.min() == 2) {
123
Advisors<ViewAdvisor<BoolView>
> as(
c
);
124
assert(as());
125
ViewAdvisor<BoolView>
&
a
(as.
advisor
());
126
++as;
127
if
(!as()) {
128
// Only a single view is left
129
if
(status == VS_ZERO) {
130
GECODE_ME_CHECK
(
a
.view().one(home));
131
}
else
if
(status == VS_ONE) {
132
GECODE_ME_CHECK
(
a
.view().zero(home));
133
}
else
{
134
return
ES_FAILED
;
135
}
136
return
home.
ES_SUBSUMED
(*
this
);
137
}
138
}
139
140
return
ES_FIX
;
141
}
142
143
}}}
144
145
// STATISTICS: int-prop
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::Int::NValues::GqBool::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
bool-gq.hpp:50
Gecode::Int::NValues::GqBool::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition:
bool-gq.hpp:56
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Int::NValues::GqBool::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
bool-gq.hpp:109
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::Int::NValues::GqBool
Greater or equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:391
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
Gecode
Gecode toplevel namespace
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
Gecode::Int::NValues::GqBool::GqBool
GqBool(Home home, int status, ViewArray< BoolView > &x, VY y)
Constructor for posting.
Definition:
bool-gq.hpp:40
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