Generated on Sat Feb 7 2015 02:01:25 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13068 $
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/rel.hh>
39 
40 namespace Gecode { namespace Int { namespace NValues {
41 
42  template<class VY>
44  GqBool<VY>::GqBool(Home home, int status, ViewArray<BoolView>& x, VY y)
45  : BoolBase<VY>(home,status,x,y) {}
46 
47  template<class VY>
49  GqBool<VY>::GqBool(Space& home, bool share, GqBool<VY>& p)
50  : BoolBase<VY>(home,share,p) {}
51 
52  template<class VY>
53  Actor*
54  GqBool<VY>::copy(Space& home, bool share) {
55  return new (home) GqBool<VY>(home,share,*this);
56  }
57 
58  template<class VY>
59  inline ExecStatus
61  if (x.size() == 0) {
62  GECODE_ME_CHECK(y.lq(home,0));
63  return ES_OK;
64  }
65 
66  x.unique(home);
67 
68  if (x.size() == 1) {
69  GECODE_ME_CHECK(y.lq(home,1));
70  return ES_OK;
71  }
72 
73  GECODE_ME_CHECK(y.lq(home,2));
74 
75  if (y.max() <= 1)
76  return ES_OK;
77 
78  if (y.min() == 2) {
79  assert(y.assigned());
80  ViewArray<BoolView> xc(home,x);
81  return Rel::NaryNq<BoolView>::post(home,xc);
82  }
83 
84  int n = x.size();
85  int status = 0;
86  for (int i=n; i--; )
87  if (x[i].zero()) {
88  if (status & VS_ONE)
89  return ES_OK;
90  x[i] = x[--n];
91  status |= VS_ZERO;
92  } else if (x[i].one()) {
93  if (status & VS_ZERO)
94  return ES_OK;
95  x[i] = x[--n];
96  status |= VS_ONE;
97  }
98 
99  assert(status != (VS_ZERO | VS_ONE));
100  if (n == 0) {
101  assert(status != 0);
102  GECODE_ME_CHECK(y.lq(home,1));
103  return ES_OK;
104  }
105  x.size(n);
106 
107  (void) new (home) GqBool<VY>(home,status,x,y);
108  return ES_OK;
109  }
110 
111  template<class VY>
112  ExecStatus
114  if (status == (VS_ZERO | VS_ONE))
115  return home.ES_SUBSUMED(*this);
116 
117  if (c.empty()) {
118  assert(status != 0);
119  GECODE_ME_CHECK(y.lq(home,1));
120  return home.ES_SUBSUMED(*this);
121  }
122 
123  if (y.max() <= 1)
124  return home.ES_SUBSUMED(*this);
125 
126  if (y.min() == 2) {
128  assert(as());
130  ++as;
131  if (!as()) {
132  // Only a single view is left
133  if (status == VS_ZERO) {
134  GECODE_ME_CHECK(a.view().one(home));
135  } else if (status == VS_ONE) {
136  GECODE_ME_CHECK(a.view().zero(home));
137  } else {
138  return ES_FAILED;
139  }
140  return home.ES_SUBSUMED(*this);
141  }
142  }
143 
144  return ES_FIX;
145  }
146 
147 }}}
148 
149 // STATISTICS: int-prop
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator .
Definition: nq.hpp:122
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition: linear.cpp:50
A & advisor(void) const
Return advisor.
Definition: core.hpp:3408
Class to iterate over advisors of a council.
Definition: core.hpp:227
Propagation has computed fixpoint.
Definition: core.hpp:528
void unique(const Space &home)
Remove all duplicate views from array (changes element order)
Definition: array.hpp:1498
Computation spaces.
Definition: core.hpp:1362
Advisor storing a single view
Definition: advisor.hpp:47
Base-class for both propagators and branchers.
Definition: core.hpp:666
static ExecStatus post(Home home, ViewArray< BoolView > &x, VY y)
Post propagator for .
Definition: bool-gq.hpp:60
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: bool-gq.hpp:54
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:525
Number of values propagator for Boolean views base class.
Definition: nvalues.hh:299
GqBool(Home home, int status, ViewArray< BoolView > &x, VY y)
Constructor for posting.
Definition: bool-gq.hpp:44
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
Greater or equal to number of values propagator for Boolean views.
Definition: nvalues.hh:395
Execution is okay.
Definition: core.hpp:527
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: bool-gq.hpp:113
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Gecode toplevel namespace
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.