main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
gecode
int
bool
eqv.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, 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/bool.hh
>
35
36
namespace
Gecode
{
namespace
Int {
namespace
Bool {
37
38
/*
39
* N-ary Boolean equivalence propagator
40
*
41
*/
42
43
PropCost
44
NaryEqv::cost
(
const
Space
&,
const
ModEventDelta
&)
const
{
45
return
PropCost::binary
(
PropCost::LO
);
46
}
47
48
Actor
*
49
NaryEqv::copy
(
Space
& home) {
50
return
new
(home)
NaryEqv
(home,*
this
);
51
}
52
53
ExecStatus
54
NaryEqv::post
(
Home
home,
ViewArray<BoolView>
&
x
,
int
pm2) {
55
int
n
=
x
.
size
();
56
for
(
int
i
=
n
;
i
--; )
57
if
(
x
[
i
].
assigned
()) {
58
pm2
^=
x
[
i
].val();
59
x
[
i
] =
x
[--
n
];
60
}
61
if
(
n
== 0)
62
return
(
pm2
== 1) ?
ES_OK
:
ES_FAILED
;
63
if
(
n
== 1) {
64
GECODE_ME_CHECK
(
x
[0].eq(home,1^
pm2
));
65
return
ES_OK
;
66
}
67
if
(
n
== 2) {
68
if
(
pm2
== 1) {
69
return
Bool::Eq<BoolView,BoolView>::post
(home,
x
[0],
x
[1]);
70
}
else
{
71
NegBoolView
nx(
x
[1]);
72
return
Bool::Eq<BoolView,NegBoolView>::post
(home,
x
[0],nx);
73
}
74
}
75
x
.
size
(
n
);
76
(void)
new
(home)
NaryEqv
(home,
x
,
pm2
);
77
return
ES_OK
;
78
}
79
80
ExecStatus
81
NaryEqv::propagate
(
Space
& home,
const
ModEventDelta
&) {
82
resubscribe
(home,
x0
);
83
resubscribe
(home,
x1
);
84
if
(
x
.
size
() == 0) {
85
if
(
x0
.
assigned
() &&
x1
.
assigned
()) {
86
return
(
pm2
== 1) ? home.
ES_SUBSUMED
(*
this
) :
ES_FAILED
;
87
}
else
if
(
x0
.
assigned
()) {
88
GECODE_ME_CHECK
(
x1
.
eq
(home,1^
pm2
));
89
return
home.
ES_SUBSUMED
(*
this
);
90
}
else
if
(
x1
.
assigned
()) {
91
GECODE_ME_CHECK
(
x0
.
eq
(home,1^
pm2
));
92
return
home.
ES_SUBSUMED
(*
this
);
93
}
94
}
95
return
ES_FIX
;
96
}
97
98
}}}
99
100
// STATISTICS: int-prop
Gecode::Int::NegBoolView
Negated Boolean view.
Definition:
view.hpp:1574
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Int::Bool::NaryEqv::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
eqv.cpp:49
Gecode::VarImpView::assigned
bool assigned(void) const
Test whether view is assigned.
Definition:
view.hpp:516
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Int::Bool::NaryEqv::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
eqv.cpp:81
Gecode::PropCost::binary
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition:
core.hpp:4809
Gecode::Int::Precede::assigned
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition:
single.hpp:43
Gecode::Int::Bool::Eq::post
static ExecStatus post(Home home, BVA x0, BVB x1)
Post propagator .
Definition:
eq.hpp:60
Gecode::Int::Bool::NaryEqv::pm2
int pm2
Parity information mod 2.
Definition:
bool.hh:460
Gecode::PropCost::LO
@ LO
Cheap.
Definition:
core.hpp:513
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:628
Gecode::Int::Bool::NaryEqv::x
ViewArray< BoolView > x
Views not yet subscribed to.
Definition:
bool.hh:458
bool.hh
Gecode
Gecode toplevel namespace
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::BinaryPropagator< BoolView, PC_BOOL_VAL >::x1
BoolView x1
Definition:
pattern.hpp:87
Gecode::Int::BoolView::eq
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition:
bool.hpp:170
Gecode::Int::Bool::NaryEqv::post
static ExecStatus post(Home home, ViewArray< BoolView > &x, int pm2)
Post propagator .
Definition:
eqv.cpp:54
Gecode::Int::Bool::NaryEqv::NaryEqv
NaryEqv(Home home, ViewArray< BoolView > &x, int pm2)
Constructor for posting.
Definition:
eqv.hpp:158
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:477
Gecode::ViewArray::size
int size(void) const
Return size of array (number of elements)
Definition:
array.hpp:1156
Gecode::Int::Bool::NaryEqv::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low binary)
Definition:
eqv.cpp:44
Gecode::Int::Bool::NaryEqv::resubscribe
void resubscribe(Space &home, BoolView &x0)
Update subscription.
Definition:
eqv.hpp:178
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:52
Gecode::ViewArray< BoolView >
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
Gecode::BinaryPropagator< BoolView, PC_BOOL_VAL >::x0
BoolView x0
Two views.
Definition:
pattern.hpp:87
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:472