Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.9.1
int-eq.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, 2006
8  *
9  * Last modified:
10  * $Date: 2011-08-29 14:59:24 +0200 (Mon, 29 Aug 2011) $ by $Author: schulte $
11  * $Revision: 12359 $
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 namespace Gecode { namespace Int { namespace Count {
39 
40  template<class VX, class VY>
42  EqInt<VX,VY>::EqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c)
43  : IntBase<VX,VY>(home,x,n_s,y,c) {}
44 
45  template<class VX, class VY>
47  EqInt<VX,VY>::post(Home home, ViewArray<VX>& x, VY y, int c) {
48  // Eliminate decided views
49  int n_x = x.size();
50  for (int i=n_x; i--; )
51  switch (holds(x[i],y)) {
52  case RT_FALSE:
53  x[i] = x[--n_x]; break;
54  case RT_TRUE:
55  x[i] = x[--n_x]; c--; break;
56  case RT_MAYBE:
57  break;
58  default:
60  }
61  x.size(n_x);
62  // RHS too small or too large
63  if ((c < 0) || (c > n_x))
64  return ES_FAILED;
65  // All views must be different
66  if (c == 0)
67  return post_false(home,x,y);
68  // All views must be equal
69  if (c == n_x)
70  return post_true(home,x,y);
71  // Compute how many subscriptions must be created
72  int n_s = std::max(c,n_x-c)+1;
73  assert(n_s <= n_x);
74  (void) new (home) EqInt<VX,VY>(home,x,n_s,y,c);
75  return ES_OK;
76  }
77 
78  template<class VX, class VY>
80  EqInt<VX,VY>::EqInt(Space& home, bool share, EqInt<VX,VY>& p)
81  : IntBase<VX,VY>(home,share,p) {}
82 
83  template<class VX, class VY>
84  Actor*
85  EqInt<VX,VY>::copy(Space& home, bool share) {
86  return new (home) EqInt<VX,VY>(home,share,*this);
87  }
88 
89  template<class VX, class VY>
92  // Eliminate decided views from subscribed views
93  int n_x = x.size();
94  for (int i=n_s; i--; )
95  switch (holds(x[i],y)) {
96  case RT_FALSE:
97  x[i].cancel(home,*this,PC_INT_DOM);
98  x[i]=x[--n_s]; x[n_s]=x[--n_x];
99  break;
100  case RT_TRUE:
101  x[i].cancel(home,*this,PC_INT_DOM);
102  x[i]=x[--n_s]; x[n_s]=x[--n_x]; c--;
103  break;
104  case RT_MAYBE:
105  break;
106  default:
107  GECODE_NEVER;
108  }
109  x.size(n_x);
110  if ((c < 0) || (c > n_x))
111  return ES_FAILED;
112  // Eliminate decided views from unsubscribed views
113  for (int i=n_x; i-- > n_s; )
114  switch (holds(x[i],y)) {
115  case RT_FALSE: x[i]=x[--n_x]; break;
116  case RT_TRUE: x[i]=x[--n_x]; c--; break;
117  case RT_MAYBE: break;
118  default: GECODE_NEVER;
119  }
120  x.size(n_x);
121  if ((c < 0) || (c > n_x))
122  return ES_FAILED;
123  if (c == 0) {
124  // All views must be different
125  GECODE_ES_CHECK(post_false(home,x,y));
126  return home.ES_SUBSUMED(*this);
127  }
128  if (c == n_x) {
129  // All views must be equal
130  GECODE_ES_CHECK(post_true(home,x,y));
131  return home.ES_SUBSUMED(*this);
132  }
133  int m = std::max(c,n_x-c)+1;
134  assert(m <= n_x);
135  // Now, there must be new subscriptions from x[n_s] up to x[m-1]
136  while (n_s < m)
137  x[n_s++].subscribe(home,*this,PC_INT_DOM,false);
138  return ES_FIX;
139  }
140 
141 }}}
142 
143 // STATISTICS: int-prop
Relation may hold or not.
Definition: view.hpp:1616
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition: int-eq.hpp:47
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:96
Baseclass for count propagators (integer)
Definition: count.hh:139
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
EqInt(Space &home, bool share, EqInt &p)
Constructor for cloning p.
Definition: int-eq.hpp:80
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-eq.hpp:85
Base-class for both propagators and branchers.
Definition: core.hpp:666
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
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)
Execution has resulted in failure.
Definition: core.hpp:525
Propagator for counting views (equal integer to number of equal views)
Definition: count.hh:171
Relation does not hold.
Definition: view.hpp:1615
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-eq.hpp:91
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
Execution is okay.
Definition: core.hpp:527
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
Gecode toplevel namespace
ExecStatus post_false(Home home, VX x, ConstIntView y)
Definition: rel.hpp:175
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Relation does hold.
Definition: view.hpp:1617
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:132