Generated on Thu Apr 5 2018 19:44:19 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  * Last modified:
14  * $Date$
15  * $Revision$
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  tofail(false) {
51  home.notice(*this,AP_DISPOSE);
52  for (int i=x.size(); i--; ) {
53  if (undecided(x[i],s)) {
54  x[i].subscribe(home,*new (home) SupportAdvisor<View>(home,*this,ac,i));
55  } else {
56  x[i].schedule(home,*this,x[i].assigned() ? ME_INT_VAL : ME_INT_BND);
57  }
58  }
59  }
60 
61  template<class View, class Val>
64  : Propagator(home,p), s(p.s), q(p.q), l(p.l), u(p.u),
65  vvsamax(), vvsamin(), tofail(p.tofail) {
66  x.update(home,p.x);
67  ac.update(home,p.ac);
68  vvsamax.update(home,p.vvsamax);
69  vvsamin.update(home,p.vvsamin);
70  }
71 
72  template<class View,class Val>
76  ExecStatus status = vvsamax.advise(home,x,s,q,a.i,d);
77  if ( ES_NOFIX == vvsamin.advise(home,x,s,q,a.i,d) ) {
78  status = ES_NOFIX;
79  }
80 
81  if (!undecided(x[a.i],s)) {
82  if (!x[a.i].assigned())
83  x[a.i].cancel(home,a);
84 
85  if ( ES_NOFIX == status ) {
86  return home.ES_NOFIX_DISPOSE(ac,a);
87  } else {
88  return home.ES_FIX_DISPOSE(ac,a);
89  }
90  }
91 
92  if ((status == ES_FAILED) && disabled()) {
93  tofail = true;
94  return ES_FIX;
95  }
96 
97  return status;
98  }
99 
100  template<class View, class Val>
101  forceinline size_t
103  home.ignore(*this,AP_DISPOSE);
104  ac.dispose(home);
105  s.~Val();
106  (void) Propagator::dispose(home);
107  return sizeof(*this);
108  }
109 
110  template<class View, class Val>
112  Sequence<View,Val>::check(ViewArray<View>& x, Val s, int q, int l, int u) {
113  Region r;
114  // could do this with an array of length q...
115  int* upper = r.alloc<int>(x.size()+1);
116  int* lower = r.alloc<int>(x.size()+1);
117  upper[0] = 0;
118  lower[0] = 0;
119  for ( int j=0; j<x.size(); j++ ) {
120  upper[j+1] = upper[j];
121  lower[j+1] = lower[j];
122  if (includes(x[j],s)) {
123  upper[j+1] += 1;
124  } else if (excludes(x[j],s)) {
125  lower[j+1] += 1;
126  }
127  if ( j+1 >= q && (q - l < lower[j+1] - lower[j+1-q] || upper[j+1] - upper[j+1-q] > u) ) {
128  return ES_FAILED;
129  }
130  }
131  return ES_OK;
132  }
133 
134  template<class View, class Val>
135  ExecStatus
136  Sequence<View,Val>::post(Home home, ViewArray<View>& x, Val s, int q, int l, int u) {
137  GECODE_ES_CHECK(check(x,s,q,l,u));
138  Sequence<View,Val>* p = new (home) Sequence<View,Val>(home,x,s,q,l,u);
139 
140  GECODE_ES_CHECK(p->vvsamax.propagate(home,x,s,q,l,u));
141  GECODE_ES_CHECK(p->vvsamin.propagate(home,x,s,q,l,u));
142 
143  return ES_OK;
144  }
145 
146  template<class View, class Val>
147  Actor*
149  return new (home) Sequence<View,Val>(home,*this);
150  }
151 
152  template<class View, class Val>
153  PropCost
155  return PropCost::cubic(PropCost::HI,x.size());
156  }
157 
158  template<class View, class Val>
159  void
161  for (int i=x.size(); i--; )
162  if (!undecided(x[i],s))
163  x[i].schedule(home,*this,x[i].assigned() ? ME_INT_VAL : ME_INT_BND);
164  if (tofail)
165  View::schedule(home,*this,ME_INT_BND);
166  }
167 
168  template<class View, class Val>
169  ExecStatus
171  if (tofail)
172  return ES_FAILED;
173 
174  GECODE_ES_CHECK(vvsamax.propagate(home,x,s,q,l,u));
175  GECODE_ES_CHECK(vvsamin.propagate(home,x,s,q,l,u));
176 
177  for (int i=x.size(); i--; )
178  if (undecided(x[i],s))
179  return ES_FIX;
180 
181  return home.ES_SUBSUMED(*this);
182  }
183 
184 }}}
185 
186 // STATISTICS: int-prop
187 
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
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3433
ExecStatus advise(Space &home, ViewArray< View > &a, Val s, int q, int j, const Delta &d)
Advise.
Definition: view.hpp:486
Actor must always be disposed.
Definition: core.hpp:554
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:384
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:1016
Base-class for advisors.
Definition: core.hpp:1218
ExecStatus ES_NOFIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed and its propagator must be run
Definition: core.hpp:3757
static ExecStatus post(Home home, ViewArray< View > &x, Val s, int q, int l, int u)
Post propagator for.
Definition: int.hpp:136
Handle to region.
Definition: region.hpp:57
void update(Space &home, ViewValSupportArray< View, Val, iss > &x)
Cloning.
Definition: view.hpp:465
#define forceinline
Definition: config.hpp:182
Propagation has computed fixpoint.
Definition: core.hpp:469
Computation spaces.
Definition: core.hpp:1668
Base-class for both propagators and branchers.
Definition: core.hpp:620
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:95
ExecStatus propagate(Space &home, ViewArray< View > &a, Val s, int q, int l, int u)
Propagate.
Definition: view.hpp:477
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)
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int.hpp:170
Execution has resulted in failure.
Definition: core.hpp:466
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 advise(Space &home, Advisor &_a, const Delta &d)
Advise function.
Definition: int.hpp:74
bool disabled(void) const
Whether propagator is currently disabled.
Definition: core.hpp:3358
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
Expensive.
Definition: core.hpp:506
virtual Actor * copy(Space &home)
Perform copying during cloning.
Definition: int.hpp:148
ExecStatus ES_FIX_DISPOSE(Council< A > &c, A &a)
Advisor a must be disposed
Definition: core.hpp:3750
View arrays.
Definition: array.hpp:228
void notice(Actor &a, ActorProperty p, bool duplicate=false)
Notice actor property.
Definition: core.hpp:3139
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition: int.hpp:154
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
static ExecStatus check(ViewArray< View > &x, Val s, int q, int l, int u)
Check for consistency.
Definition: int.hpp:112
static PropCost cubic(PropCost::Mod m, unsigned int n)
Cubic complexity for modifier m and size measure n.
Definition: core.hpp:4625
Generic domain change information to be supplied to advisors.
Definition: core.hpp:205
void ignore(Actor &a, ActorProperty p, bool duplicate=false)
Ignore actor property.
Definition: core.hpp:3944
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:3172
Propagation cost.
Definition: core.hpp:478
ExecStatus
Definition: core.hpp:464
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
virtual void reschedule(Space &home)
Schedule function.
Definition: int.hpp:160
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
Propagation has not computed fixpoint.
Definition: core.hpp:467
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Definition: set-op.hpp:93
Gecode toplevel namespace
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: int.hpp:102
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1203
Home class for posting propagators
Definition: core.hpp:846
Sequence(Space &home, Sequence &p)
Constructor for cloning p.
Definition: int.hpp:63
Class for advising the propagator.
Definition: view.hpp:48