Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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  * 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 Sequence {
39 
40  template<class View, class Val>
43  int q0, int l0, int u0)
44  : Propagator(home), x(x0), s(s0), q(q0), l(l0), u(u0),
45  vvsamax(home,x,s0,q0), vvsamin(home,x,s0,q0), ac(home),
46  tofail(false) {
47  home.notice(*this,AP_DISPOSE);
48  for (int i=x.size(); i--; ) {
49  if (undecided(x[i],s)) {
50  x[i].subscribe(home,*new (home) SupportAdvisor<View>(home,*this,ac,i));
51  } else {
52  x[i].schedule(home,*this,x[i].assigned() ? ME_INT_VAL : ME_INT_BND);
53  }
54  }
55  }
56 
57  template<class View, class Val>
60  : Propagator(home,p), s(p.s), q(p.q), l(p.l), u(p.u),
61  vvsamax(), vvsamin(), tofail(p.tofail) {
62  x.update(home,p.x);
63  ac.update(home,p.ac);
64  vvsamax.update(home,p.vvsamax);
65  vvsamin.update(home,p.vvsamin);
66  }
67 
68  template<class View,class Val>
72  ExecStatus status = vvsamax.advise(home,x,s,q,a.i,d);
73  if ( ES_NOFIX == vvsamin.advise(home,x,s,q,a.i,d) ) {
74  status = ES_NOFIX;
75  }
76 
77  if (!undecided(x[a.i],s)) {
78  if (!x[a.i].assigned())
79  x[a.i].cancel(home,a);
80 
81  if ( ES_NOFIX == status ) {
82  return home.ES_NOFIX_DISPOSE(ac,a);
83  } else {
84  return home.ES_FIX_DISPOSE(ac,a);
85  }
86  }
87 
88  if ((status == ES_FAILED) && disabled()) {
89  tofail = true;
90  return ES_FIX;
91  }
92 
93  return status;
94  }
95 
96  template<class View, class Val>
97  forceinline size_t
99  home.ignore(*this,AP_DISPOSE);
100  ac.dispose(home);
101  s.~Val();
102  (void) Propagator::dispose(home);
103  return sizeof(*this);
104  }
105 
106  template<class View, class Val>
108  Sequence<View,Val>::check(ViewArray<View>& x, Val s, int q, int l, int u) {
109  Region r;
110  // could do this with an array of length q...
111  int* upper = r.alloc<int>(x.size()+1);
112  int* lower = r.alloc<int>(x.size()+1);
113  upper[0] = 0;
114  lower[0] = 0;
115  for ( int j=0; j<x.size(); j++ ) {
116  upper[j+1] = upper[j];
117  lower[j+1] = lower[j];
118  if (includes(x[j],s)) {
119  upper[j+1] += 1;
120  } else if (excludes(x[j],s)) {
121  lower[j+1] += 1;
122  }
123  if ( j+1 >= q && (q - l < lower[j+1] - lower[j+1-q] || upper[j+1] - upper[j+1-q] > u) ) {
124  return ES_FAILED;
125  }
126  }
127  return ES_OK;
128  }
129 
130  template<class View, class Val>
131  ExecStatus
132  Sequence<View,Val>::post(Home home, ViewArray<View>& x, Val s, int q, int l, int u) {
133  GECODE_ES_CHECK(check(x,s,q,l,u));
134  Sequence<View,Val>* p = new (home) Sequence<View,Val>(home,x,s,q,l,u);
135 
136  GECODE_ES_CHECK(p->vvsamax.propagate(home,x,s,q,l,u));
137  GECODE_ES_CHECK(p->vvsamin.propagate(home,x,s,q,l,u));
138 
139  return ES_OK;
140  }
141 
142  template<class View, class Val>
143  Actor*
145  return new (home) Sequence<View,Val>(home,*this);
146  }
147 
148  template<class View, class Val>
149  PropCost
151  return PropCost::cubic(PropCost::HI,x.size());
152  }
153 
154  template<class View, class Val>
155  void
157  for (int i=x.size(); i--; )
158  if (!undecided(x[i],s))
159  x[i].schedule(home,*this,x[i].assigned() ? ME_INT_VAL : ME_INT_BND);
160  if (tofail)
161  View::schedule(home,*this,ME_INT_BND);
162  }
163 
164  template<class View, class Val>
165  ExecStatus
167  if (tofail)
168  return ES_FAILED;
169 
170  GECODE_ES_CHECK(vvsamax.propagate(home,x,s,q,l,u));
171  GECODE_ES_CHECK(vvsamin.propagate(home,x,s,q,l,u));
172 
173  for (int i=x.size(); i--; )
174  if (undecided(x[i],s))
175  return ES_FIX;
176 
177  return home.ES_SUBSUMED(*this);
178  }
179 
180 }}}
181 
182 // STATISTICS: int-prop
183 
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
Definition: set-op.hpp:72
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3482
ExecStatus advise(Space &home, ViewArray< View > &a, Val s, int q, int j, const Delta &d)
Advise.
Definition: view.hpp:482
Actor must always be disposed.
Definition: core.hpp:561
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:380
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:106
Base-class for propagators.
Definition: core.hpp:1023
Base-class for advisors.
Definition: core.hpp:1251
ExecStatus ES_NOFIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be run
Definition: core.hpp:3806
static ExecStatus post(Home home, ViewArray< View > &x, Val s, int q, int l, int u)
Post propagator for.
Definition: int.hpp:132
Handle to region.
Definition: region.hpp:53
void update(Space &home, ViewValSupportArray< View, Val, iss > &x)
Cloning.
Definition: view.hpp:461
#define forceinline
Definition: config.hpp:185
Propagation has computed fixpoint.
Definition: core.hpp:476
Computation spaces.
Definition: core.hpp:1701
Base-class for both propagators and branchers.
Definition: core.hpp:627
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:91
ExecStatus propagate(Space &home, ViewArray< View > &a, Val s, int q, int l, int u)
Propagate.
Definition: view.hpp:473
Single _a(2, 3)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int.hpp:166
Execution has resulted in failure.
Definition: core.hpp:473
Sequence propagator for array of integers
Definition: sequence.hh:101
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 advise(Space &home, Advisor &_a, const Delta &d)
Advise function.
Definition: int.hpp:70
bool disabled(void) const
Whether propagator is currently disabled.
Definition: core.hpp:3395
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
Expensive.
Definition: core.hpp:513
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition: int.hpp:144
ExecStatus ES_FIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed
Definition: core.hpp:3799
View arrays.
Definition: array.hpp:224
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3176
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: int.hpp:150
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:765
static ExecStatus check(ViewArray< View > &x, Val s, int q, int l, int u)
Check for consistency.
Definition: int.hpp:108
static PropCost cubic(PropCost::Mod m, unsigned int n)
Cubic complexity for modifier m and size measure n.
Definition: core.hpp:4697
Generic domain change information to be supplied to advisors.
Definition: core.hpp:203
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:3993
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3209
Propagation cost.
Definition: core.hpp:485
ExecStatus
Definition: core.hpp:471
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:43
virtual void reschedule(Space &home)
Schedule function.
Definition: int.hpp:156
Post propagator for SetVar x
Definition: set.hh:765
Execution is okay.
Definition: core.hpp:475
Propagation has not computed fixpoint.
Definition: core.hpp:474
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Definition: set-op.hpp:89
Gecode toplevel namespace
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: int.hpp:98
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1199
Home class for posting propagators
Definition: core.hpp:853
Sequence(Space &home, Sequence &p)
Constructor for cloning p.
Definition: int.hpp:59
Class for advising the propagator.
Definition: view.hpp:44