Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
36namespace 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 {
46 }
47
48 Actor*
50 return new (home) NaryEqv(home,*this);
51 }
52
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
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
int n
Number of negative literals for node type.
Base-class for both propagators and branchers.
Definition core.hpp:628
Home class for posting propagators
Definition core.hpp:856
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition bool.hpp:170
static ExecStatus post(Home home, BVA x0, BVB x1)
Post propagator .
Definition eq.hpp:60
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition eqv.cpp:81
void resubscribe(Space &home, BoolView &x0)
Update subscription.
Definition eqv.hpp:178
NaryEqv(Home home, ViewArray< BoolView > &x, int pm2)
Constructor for posting.
Definition eqv.hpp:158
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low binary)
Definition eqv.cpp:44
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition eqv.cpp:49
int pm2
Parity information mod 2.
Definition bool.hh:460
ViewArray< BoolView > x
Views not yet subscribed to.
Definition bool.hh:458
static ExecStatus post(Home home, ViewArray< BoolView > &x, int pm2)
Post propagator .
Definition eqv.cpp:54
Negated Boolean view.
Definition view.hpp:1574
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition core.hpp:4809
Computation spaces.
Definition core.hpp:1742
bool assigned(void) const
Test whether view is assigned.
Definition view.hpp:516
View arrays.
Definition array.hpp:253
int size(void) const
Return size of array (number of elements)
Definition array.hpp:1156
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
Post propagator for SetVar x
Definition set.hh:767