Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
int.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * David Rijsman <David.Rijsman@quintiq.com>
5  *
6  * Contributing authors:
7  * Christian Schulte <schulte@gecode.org>
8  *
9  * Copyright:
10  * David Rijsman, 2009
11  * Christian Schulte, 2009
12  *
13  * Last modified:
14  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $
15  * $Revision: 13068 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 namespace Gecode { namespace Int { namespace Sequence {
43 
44  template<class View, class Val>
47  int q0, int l0, int u0)
48  : Propagator(home), x(x0), s(s0), q(q0), l(l0), u(u0),
49  vvsamax(home,x,s0,q0), vvsamin(home,x,s0,q0), ac(home) {
50  home.notice(*this,AP_DISPOSE);
51  for (int i=x.size(); i--; ) {
52  if (undecided(x[i],s)) {
53  x[i].subscribe(home,*new (home) SupportAdvisor<View>(home,*this,ac,i));
54  } else {
55  x[i].schedule(home,*this,x[i].assigned() ? ME_INT_VAL : ME_INT_BND);
56  }
57  }
58  }
59 
60  namespace {
62  template<class Val>
63  class UpdateVal {
64  public:
65  static void update(Val& n, Space& home, bool share, Val& old);
66  };
68  template<>
69  class UpdateVal<int> {
70  public:
71  static void update(int& n, Space&, bool, int& old) {
72  n = old;
73  }
74  };
76  template<>
77  class UpdateVal<IntSet> {
78  public:
79  static void update(IntSet& n, Space& home, bool share,
80  IntSet& old) {
81  n.update(home,share,old);
82  }
83  };
84  }
85 
86  template<class View, class Val>
89  : Propagator(home,share,p), q(p.q), l(p.l), u(p.u),
90  vvsamax(), vvsamin() {
91  UpdateVal<Val>::update(s,home,share,p.s);
92  x.update(home,share,p.x);
93  ac.update(home,share,p.ac);
94  vvsamax.update(home,share,p.vvsamax);
95  vvsamin.update(home,share,p.vvsamin);
96  }
97 
98  template<class View,class Val>
101  SupportAdvisor<View>& a = static_cast<SupportAdvisor<View>&>(_a);
102  ExecStatus status = vvsamax.advise(home,x,s,q,a.i,d);
103  if ( ES_NOFIX == vvsamin.advise(home,x,s,q,a.i,d) ) {
104  status = ES_NOFIX;
105  }
106 
107  if (!undecided(x[a.i],s)) {
108  if (!x[a.i].assigned())
109  x[a.i].cancel(home,a);
110 
111  if ( ES_NOFIX == status ) {
112  return home.ES_NOFIX_DISPOSE(ac,a);
113  } else {
114  return home.ES_FIX_DISPOSE(ac,a);
115  }
116  }
117 
118  return status;
119  }
120 
121  template<class View, class Val>
122  forceinline size_t
124  home.ignore(*this,AP_DISPOSE);
125  ac.dispose(home);
126  s.~Val();
127  (void) Propagator::dispose(home);
128  return sizeof(*this);
129  }
130 
131  template<class View, class Val>
133  Sequence<View,Val>::check(Space& home, ViewArray<View>& x, Val s, int q, int l, int u) {
134  Region r(home);
135  // could do this with an array of length q...
136  int* upper = r.alloc<int>(x.size()+1);
137  int* lower = r.alloc<int>(x.size()+1);
138  upper[0] = 0;
139  lower[0] = 0;
140  for ( int j=0; j<x.size(); j++ ) {
141  upper[j+1] = upper[j];
142  lower[j+1] = lower[j];
143  if (includes(x[j],s)) {
144  upper[j+1] += 1;
145  } else if (excludes(x[j],s)) {
146  lower[j+1] += 1;
147  }
148  if ( j+1 >= q && (q - l < lower[j+1] - lower[j+1-q] || upper[j+1] - upper[j+1-q] > u) ) {
149  return ES_FAILED;
150  }
151  }
152  return ES_OK;
153  }
154 
155  template<class View, class Val>
156  ExecStatus
157  Sequence<View,Val>::post(Home home, ViewArray<View>& x, Val s, int q, int l, int u) {
158  GECODE_ES_CHECK(check(home,x,s,q,l,u));
159  Sequence<View,Val>* p = new (home) Sequence<View,Val>(home,x,s,q,l,u);
160 
161  GECODE_ES_CHECK(p->vvsamax.propagate(home,x,s,q,l,u));
162  GECODE_ES_CHECK(p->vvsamin.propagate(home,x,s,q,l,u));
163 
164  return ES_OK;
165  }
166 
167  template<class View, class Val>
168  Actor*
169  Sequence<View,Val>::copy(Space& home, bool share) {
170  return new (home) Sequence<View,Val>(home,share,*this);
171  }
172 
173  template<class View, class Val>
174  PropCost
176  return PropCost::cubic(PropCost::HI,x.size());
177  }
178 
179  template<class View, class Val>
180  ExecStatus
182  GECODE_ES_CHECK(vvsamax.propagate(home,x,s,q,l,u));
183  GECODE_ES_CHECK(vvsamin.propagate(home,x,s,q,l,u));
184 
185  for (int i=x.size(); i--; )
186  if (undecided(x[i],s))
187  return ES_FIX;
188 
189  return home.ES_SUBSUMED(*this);
190  }
191 
192 }}}
193 
194 // STATISTICS: int-prop
195 
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
Definition: set-op.hpp:76
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
Actor must always be disposed.
Definition: core.hpp:610
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:326
bool undecided(const View &x, int s)
Test whether no decision on inclusion or exclusion of values of view x in s can be made...
Definition: set-op.hpp:110
Base-class for propagators.
Definition: core.hpp:755
Expensive.
Definition: core.hpp:564
Base-class for advisors.
Definition: core.hpp:926
ExecStatus ES_NOFIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be run
Definition: core.hpp:3285
Handle to region.
Definition: region.hpp:61
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Base-class for both propagators and branchers.
Definition: core.hpp:666
Gecode::IntSet d(v, 7)
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:84
ExecStatus propagate(Space &home, ViewArray< View > &a, Val s, int q, int l, int u)
Propagate.
Definition: view.hpp:478
Single _a(2, 3)
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
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Sequence propagator for array of integers
Definition: sequence.hh:105
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
const Gecode::ModEvent ME_INT_BND
Domain operation has changed the minimum or maximum of the domain.
Definition: var-type.hpp:65
ExecStatus ES_FIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed
Definition: core.hpp:3278
View arrays.
Definition: array.hpp:234
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:2849
void check(const FloatVal &n, const char *l)
Check whether float n is a valid number, otherwise throw out of limits exception with information l...
Definition: limits.hpp:48
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
static PropCost cubic(PropCost::Mod m, unsigned int n)
Cubic complexity for modifier m and size measure n.
Definition: core.hpp:4023
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Generic domain change information to be supplied to advisors.
Definition: core.hpp:275
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.cpp:169
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:2877
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:132
Execution is okay.
Definition: core.hpp:527
Propagation has not computed fixpoint.
Definition: core.hpp:526
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Definition: set-op.hpp:93
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.
Class for advising the propagator.
Definition: view.hpp:48
void update(Space &home, bool share, ViewValSupportArray< View, Val, iss > &x)
Cloning.
Definition: view.hpp:466