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
nvalues
bool-lq.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
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include <
gecode/int/bool.hh
>
39
40
namespace
Gecode
{
namespace
Int {
namespace
NValues {
41
42
template
<
class
VY>
43
forceinline
44
LqBool<VY>::LqBool
(
Home
home,
int
status,
ViewArray<BoolView>
&
x
, VY
y
)
45
:
BoolBase
<VY>(home,status,
x
,
y
) {}
46
47
template
<
class
VY>
48
forceinline
49
LqBool<VY>::LqBool
(
Space
& home,
bool
share,
LqBool<VY>
&
p
)
50
:
BoolBase
<VY>(home,share,
p
) {}
51
52
template
<
class
VY>
53
Actor
*
54
LqBool<VY>::copy
(
Space
& home,
bool
share) {
55
return
new
(home)
LqBool<VY>
(home,share,*
this
);
56
}
57
58
template
<
class
VY>
59
inline
ExecStatus
60
LqBool<VY>::post
(
Home
home,
ViewArray<BoolView>
&
x
, VY
y
) {
61
if
(
x
.size() == 0) {
62
GECODE_ME_CHECK
(
y
.gq(home,0));
63
return
ES_OK
;
64
}
65
66
x
.unique(home);
67
68
GECODE_ME_CHECK
(
y
.gq(home,1));
69
70
if
(
x
.size() == 1)
71
return
ES_OK
;
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
return
ES_OK
;
81
82
int
n
=
x
.size();
83
int
status = 0;
84
for
(
int
i
=
n
;
i
--; )
85
if
(
x
[
i
].zero()) {
86
if
(status & VS_ONE) {
87
GECODE_ME_CHECK
(
y
.gq(home,2));
88
return
ES_OK
;
89
}
90
x
[
i
] =
x
[--
n
];
91
status |= VS_ZERO;
92
}
else
if
(
x
[
i
].
one
()) {
93
if
(status & VS_ZERO) {
94
GECODE_ME_CHECK
(
y
.gq(home,2));
95
return
ES_OK
;
96
}
97
x
[
i
] =
x
[--
n
];
98
status |= VS_ONE;
99
}
100
101
assert(status != (VS_ZERO | VS_ONE));
102
if
(
n
== 0) {
103
assert((status != 0) && (
y
.min() >= 1));
104
return
ES_OK
;
105
}
106
107
x
.size(
n
);
108
109
(void)
new
(home)
LqBool<VY>
(home,status,
x
,
y
);
110
return
ES_OK
;
111
}
112
113
template
<
class
VY>
114
ExecStatus
115
LqBool<VY>::propagate
(
Space
& home,
const
ModEventDelta
&) {
116
if
(status == (VS_ZERO | VS_ONE)) {
117
GECODE_ME_CHECK
(
y
.gq(home,2));
118
return
home.
ES_SUBSUMED
(*
this
);
119
}
120
121
if
(
c
.empty()) {
122
assert((status != 0) && (
y
.min() >= 1));
123
return
home.
ES_SUBSUMED
(*
this
);
124
}
125
126
if
(
y
.max() == 1) {
127
if
(status == VS_ZERO) {
128
// Mark that everything is done
129
status = VS_ZERO | VS_ONE;
130
for
(
Advisors
<
ViewAdvisor<BoolView>
> as(
c
); as(); ++as)
131
GECODE_ME_CHECK
(as.advisor().view().zero(home));
132
return
home.
ES_SUBSUMED
(*
this
);
133
}
134
if
(status == VS_ONE) {
135
// Mark that everything is done
136
status = VS_ZERO | VS_ONE;
137
for
(
Advisors
<
ViewAdvisor<BoolView>
> as(
c
); as(); ++as)
138
GECODE_ME_CHECK
(as.advisor().view().one(home));
139
return
home.
ES_SUBSUMED
(*
this
);
140
}
141
}
142
143
if
(
y
.min() == 2)
144
return
home.
ES_SUBSUMED
(*
this
);
145
146
return
ES_FIX
;
147
}
148
149
}}}
150
151
// STATISTICS: int-prop
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Int::Bool::NaryEq::post
static ExecStatus post(Home home, ViewArray< BV > &x)
Post propagator .
Definition:
eq.hpp:135
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
Gecode::Int::NValues::LqBool::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
bool-lq.hpp:115
Gecode::Advisors
Class to iterate over advisors of a council.
Definition:
core.hpp:233
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Int::NValues::LqBool::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition:
bool-lq.hpp:60
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::ViewAdvisor
Advisor storing a single view
Definition:
advisor.hpp:47
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:696
Gecode::VarImpVar::assigned
bool assigned(void) const
Test whether view is assigned.
Definition:
var.hpp:123
bool.hh
Gecode
Gecode toplevel namespace
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::Int::NValues::BoolBase
Number of values propagator for Boolean views base class.
Definition:
nvalues.hh:299
Gecode::Int::NValues::LqBool::copy
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition:
bool-lq.hpp:54
Test::Float::Linear::one
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition:
linear.cpp:50
Gecode::Int::NValues::LqBool::LqBool
LqBool(Home home, int status, ViewArray< BoolView > &x, VY y)
Constructor for posting.
Definition:
bool-lq.hpp:44
Gecode::Int::NValues::LqBool
Less or equal to number of values propagator for Boolean views.
Definition:
nvalues.hh:365
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:545
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:56
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::ViewArray< BoolView >
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:544
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:540