42 namespace Gecode {
namespace Int {
namespace Sequence {
83 template<
class View,
class Val,
bool iss>
95 bool violated(
int j,
int q,
int l,
int u)
const;
97 bool retired(
void)
const;
104 bool conlusion_scheduled(
void)
const;
108 int values(
int j,
int q)
const;
110 bool shaved(
const View& x, Val s,
int i)
const;
118 bool alternative_not_possible(
ViewArray<View>& a,Val s,
int i,
int idx)
const;
120 bool has_potential_violation(
void)
const;
122 int next_potential_violation(
void);
124 void potential_violation(
int i);
126 void set(
int idx,
int v,
int q,
int n);
128 void potential_violation(
int idx,
int q,
int n);
136 template<
class View,
class Val,
bool iss>
142 template<
class View,
class Val,
bool iss>
148 template<
class View,
class Val,
bool iss>
151 return static_cast<int>(
v.get());
154 template<
class View,
class Val,
bool iss>
157 v.add(static_cast<unsigned int>(k));
161 template<
class View,
class Val,
bool iss>
167 template<
class View,
class Val,
bool iss>
173 template<
class View,
class Val,
bool iss>
178 return includes(a[idx-1],s) || (iss && (idx-1 ==
i));
181 template<
class View,
class Val,
bool iss>
186 return excludes(a[idx-1],s) || (!iss && (i == idx-1));
190 template<
class View,
class Val,
bool iss>
195 v.init(home,static_cast<unsigned int>(a.
size()));
197 for (
int l=0;
l<a.
size();
l++ ) {
198 if ( alternative_not_possible(a,s,i,
l+1) ) {
204 potential_violation(
l+1-q);
206 if (
l <= a.
size() - q ) {
207 potential_violation(
l);
213 template<
class View,
class Val,
bool iss>
221 for (
int l=0;
l<n0;
l++ ) {
224 v.update(home,vvs.v);
229 template<
class View,
class Val,
bool iss>
238 template<
class View,
class Val,
bool iss>
246 potential_violation(0);
252 template<
class View,
class Val,
bool iss>
255 return !retired() &&
y[0] > 0;
258 template<
class View,
class Val,
bool iss>
264 template<
class View,
class Val,
bool iss>
270 template<
class View,
class Val,
bool iss>
285 template<
class View,
class Val,
bool iss>
289 potential_violation(idx-q);
291 if ( idx <= n - q - 1) {
292 potential_violation(idx);
296 template<
class View,
class Val,
bool iss>
302 potential_violation(idx,q,n);
306 template<
class View,
class Val,
bool iss>
310 int n = a.
size() + 1;
312 set(idx,
y[idx]+
v,q,
n);
314 if (
y[idx] > idx ) {
321 while ( idx > 0 && ((
y[idx]-
y[idx-1]>1) || ((
y[idx]-
y[idx-1]==1 && s_not_possible(a,s,i,idx)))) ) {
322 if ( s_not_possible(a,s,i,idx) ) {
323 set(idx-1,
y[idx],q,
n);
325 set(idx-1,
y[idx]-1,q,
n);
327 if (
y[idx-1]>idx-1 ) {
336 while ( idx < a.
size() && ((
y[idx]-
y[idx+1]>0) || ((
y[idx]-
y[idx+1]==0) && alternative_not_possible(a,s,i,idx+1))) ) {
337 if ( alternative_not_possible(a,s,i,idx+1) ) {
338 set(idx+1,
y[idx]+1,q,
n);
340 set(idx+1,
y[idx],q,
n);
349 template<
class View,
class Val,
bool iss>
352 Val s,
int i,
int q,
int j,
356 if ((j == i) && shaved(a[j],s,j)) {
359 switch (
takes(a[j],s)) {
361 if (
y[j+1]-
y[j] == 0) {
362 if (!pushup(a,s,i,q,j+1,1)) {
368 if (
y[j+1]-
y[j] > 0) {
369 if (!pushup(a,s,i,q,j,
y[j+1]-
y[j])) {
380 if ( has_potential_violation() )
388 template<
class View,
class Val,
bool iss>
392 if ( conlusion_scheduled() ) {
393 return conclude(home,a,s,i);
396 while (has_potential_violation()) {
397 int j = next_potential_violation();
398 if (violated(j,q,l,u)) {
399 int forced_to_s =
values(j,q);
400 if (forced_to_s < l) {
401 if (!pushup(a,s,i,q,j+q,l-forced_to_s))
402 return conclude(home,a,s,i);
404 if (!pushup(a,s,i,q,j,forced_to_s-u))
405 return conclude(home,a,s,i);
407 if (violated(j,q,l,u))
408 return conclude(home,a,s,i);
415 template<
class View,
class Val,
bool iss>
419 template<
class View,
class Val,
bool iss>
424 template<
class View,
class Val,
bool iss>
429 for (
int i = n; i--; ) {
430 xs[
i].init(home,x,s,i,q);
435 template<
class View,
class Val,
bool iss>
443 template<
class View,
class Val,
bool iss>
449 template<
class View,
class Val,
bool iss>
452 assert((i >= 0) && (i <
size()));
456 template<
class View,
class Val,
bool iss>
459 assert((i >= 0) && (i <
size()));
463 template<
class View,
class Val,
bool iss>
469 for (
int i=n; i--; ) {
470 xs[
i].update(home,a[i],n+1);
475 template<
class View,
class Val,
bool iss>
478 for (
int i=n; i--; ) {
484 template<
class View,
class Val,
bool iss>
488 for (
int i=n; i--; ) {
489 if (
ES_NOFIX == xs[i].advise(home,a,s,i,q,j,d) )
void init(void)
Initialize links (self-linked)
bool violated(int j, int q, int l, int u) const
Return true if sequence j has been violated.
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
void update(Space &home, ViewValSupport< View, Val, iss > &vvs, int n0)
Update.
Base-class for propagators.
An array of ViewValSupport data structures.
Propagation has computed fixpoint.
Class for view value support structure.
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
void init(Space &home, ViewArray< View > &x, Val s, int i, int q)
Initialize.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from space heap.
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
ExecStatus advise(Space &home, ViewArray< View > &a, Val s, int i, int q, int j, const Delta &d)
Advise.
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Simple bitsets for recording violations.
Execution has resulted in failure.
unsigned int size(I &i)
Size of all ranges of range iterator i.
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
SupportAdvisor(Space &home, Propagator &p, Council< SupportAdvisor > &c, int i0)
Initialize.
ExecStatus propagate(Space &home, ViewArray< View > &a, Val s, int i, int q, int l, int u)
Propagate.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
void dispose(Space &home, Council< SupportAdvisor > &c)
Dispose advisor.
Post propagator for SetVar SetOpType SetVar y
Generic domain change information to be supplied to advisors.
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
void dispose(Space &home, Council< A > &c)
Dispose the advisor.
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
TakesStatus takes(const View &x, int s)
Return whether view x takes value s.
bool retired(void) const
Check if retired.
void values(Home home, const IntVarArgs &x, IntSet y, IntPropLevel ipl=IPL_DEF)
Post constraint .
Post propagator for SetVar x
Propagation has not computed fixpoint.
static ViewValSupport * allocate(Space &, int)
Allocate an instance.
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Gecode toplevel namespace
int size(void) const
Return size of array (number of elements)
#define GECODE_NEVER
Assert that this command is never executed.
void update(IntSet &y, Space &home, IntSet &py)
Class for advising the propagator.
ViewValSupportArray(void)
Default constructor.
int size(void) const
Return the current size.