MCPcopy Create free account
hub / github.com/Gecode/gecode / sequence

Function sequence

gecode/int/sequence.cpp:46–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44 using namespace Int;
45
46 void
47 sequence(Home home, const IntVarArgs& x, const IntSet &s,
48 int q, int l, int u, IntPropLevel) {
49 Limits::check(s.min(),"Int::sequence");
50 Limits::check(s.max(),"Int::sequence");
51
52 if (x.size() == 0)
53 throw TooFewArguments("Int::sequence");
54
55 Limits::check(q,"Int::sequence");
56 Limits::check(l,"Int::sequence");
57 Limits::check(u,"Int::sequence");
58
59 if (same(x))
60 throw ArgumentSame("Int::sequence");
61
62 if ((q < 1) || (q > x.size()))
63 throw OutOfLimits("Int::sequence");
64
65 GECODE_POST;
66
67 // Normalize l and u
68 l=std::max(0,l); u=std::min(q,u);
69
70 // Lower bound of values taken can never exceed upper bound
71 if (u < l) {
72 home.fail(); return;
73 }
74
75 // Already subsumed as any number of values taken is okay
76 if ((0 == l) && (q == u))
77 return;
78
79 // All variables must take a value in s
80 if (l == q) {
81 for (int i=0; i<x.size(); i++) {
82 IntView xv(x[i]);
83 IntSetRanges ris(s);
84 GECODE_ME_FAIL(xv.inter_r(home,ris,false));
85 }
86 return;
87 }
88
89 // No variable can take a value in s
90 if (0 == u) {
91 for (int i=0; i<x.size(); i++) {
92 IntView xv(x[i]);
93 IntSetRanges ris(s);
94 GECODE_ME_FAIL(xv.minus_r(home,ris,false));
95 }
96 return;
97 }
98
99 ViewArray<IntView> xv(home,x);
100 if (s.size() == 1) {
101 GECODE_ES_FAIL(
102 (Sequence::Sequence<IntView,int>::post
103 (home,xv,s.min(),q,l,u)));

Callers

nothing calls this directly

Calls 13

maxFunction · 0.70
minFunction · 0.70
checkFunction · 0.50
sameFunction · 0.50
postFunction · 0.50
minMethod · 0.45
maxMethod · 0.45
sizeMethod · 0.45
failMethod · 0.45
inter_rMethod · 0.45
minus_rMethod · 0.45
zeroMethod · 0.45

Tested by

no test coverage detected