Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
int-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, 2006
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 namespace Gecode { namespace Int { namespace Count {
35 
36  template<class VX, class VY>
38  LqInt<VX,VY>::LqInt(Home home, ViewArray<VX>& x, int n_s, VY y, int c)
39  : IntBase<VX,VY>(home,x,n_s,y,c) {}
40 
41  template<class VX, class VY>
44  // Eliminate decided views
45  int n_x = x.size();
46  for (int i=n_x; i--; )
47  switch (holds(x[i],y)) {
48  case RT_FALSE:
49  x[i] = x[--n_x]; break;
50  case RT_TRUE:
51  x[i] = x[--n_x]; c--; break;
52  case RT_MAYBE:
53  break;
54  default:
56  }
57  x.size(n_x);
58  if (c < 0)
59  return ES_FAILED;
60  if (c >= n_x)
61  return ES_OK;
62  // All views must be different
63  if (c == 0)
64  return post_false(home,x,y);
65  (void) new (home) LqInt<VX,VY>(home,x,n_x-c+1,y,c);
66  return ES_OK;
67  }
68 
69  template<class VX, class VY>
72  : IntBase<VX,VY>(home,p) {}
73 
74  template<class VX, class VY>
75  Actor*
77  return new (home) LqInt<VX,VY>(home,*this);
78  }
79 
80  template<class VX, class VY>
83  // Eliminate decided views from subscribed views
84  int n_x = x.size();
85  for (int i=n_s; i--; )
86  switch (holds(x[i],y)) {
87  case RT_FALSE:
88  x[i].cancel(home,*this,PC_INT_DOM);
89  x[i]=x[--n_s]; x[n_s]=x[--n_x];
90  break;
91  case RT_TRUE:
92  x[i].cancel(home,*this,PC_INT_DOM);
93  x[i]=x[--n_s]; x[n_s]=x[--n_x]; c--;
94  break;
95  case RT_MAYBE:
96  break;
97  default:
99  }
100  x.size(n_x);
101  if (c < 0)
102  return ES_FAILED;
103  if (c >= n_x)
104  return home.ES_SUBSUMED(*this);
105  // Eliminate decided views from unsubscribed views
106  for (int i=n_x; i-- > n_s; )
107  switch (holds(x[i],y)) {
108  case RT_FALSE: x[i]=x[--n_x]; break;
109  case RT_TRUE: x[i]=x[--n_x]; c--; break;
110  case RT_MAYBE: break;
111  default: GECODE_NEVER;
112  }
113  x.size(n_x);
114  if (c < 0)
115  return ES_FAILED;
116  if (c >= n_x)
117  return home.ES_SUBSUMED(*this);
118  if (c == 0) {
119  // All views must be different
120  GECODE_ES_CHECK(post_false(home,x,y));
121  return home.ES_SUBSUMED(*this);
122  }
123  // Now, there must be new subscriptions from x[n_s] up to x[n_x-c+1]
124  int m = n_x-c;
125  while (n_s <= m)
126  x[n_s++].subscribe(home,*this,PC_INT_DOM,false);
127  return ES_FIX;
128  }
129 
130 }}}
131 
132 // STATISTICS: int-prop
VY y
View to compare to.
Definition: count.hh:145
Relation may hold or not.
Definition: view.hpp:1703
ViewArray< VX > x
Views still to count.
Definition: count.hh:141
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3490
int n_s
Views from x[0] ... x[n_s-1] have subscriptions.
Definition: count.hh:143
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:115
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition: int-lq.hpp:76
Baseclass for count propagators (integer)
Definition: count.hh:138
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: array.hpp:1323
#define forceinline
Definition: config.hpp:185
Propagation has computed fixpoint.
Definition: core.hpp:476
Computation spaces.
Definition: core.hpp:1701
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition: int-lq.hpp:43
Base-class for both propagators and branchers.
Definition: core.hpp:627
Propagator for counting views (less or equal integer to number of equal views)
Definition: count.hh:232
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Gecode::IntArgs i({1, 2, 3, 4})
Execution has resulted in failure.
Definition: core.hpp:473
Relation does not hold.
Definition: view.hpp:1702
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-lq.hpp:82
int c
Number of views which are equal and have been eliminated.
Definition: count.hh:147
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to all views.
Definition: array.hpp:1331
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
LqInt(Space &home, LqInt &p)
Constructor for cloning p.
Definition: int-lq.hpp:71
ExecStatus
Definition: core.hpp:471
Post propagator for SetVar x
Definition: set.hh:767
Execution is okay.
Definition: core.hpp:475
Gecode toplevel namespace
ExecStatus post_false(Home home, VX x, ConstIntView y)
Definition: rel.hpp:194
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1138
Home class for posting propagators
Definition: core.hpp:853
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
Relation does hold.
Definition: view.hpp:1704