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

Function cumulative

gecode/int/cumulative.cpp:43–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41
42 template<class Cap>
43 void
44 cumulative(Home home, Cap c, const TaskTypeArgs& t,
45 const IntVarArgs& s, const IntArgs& p, const IntArgs& u,
46 IntPropLevel ipl) {
47 if ((s.size() != p.size()) || (s.size() != u.size()) ||
48 (s.size() != t.size()))
49 throw ArgumentSizeMismatch("Int::cumulative");
50 long long int w = 0;
51 for (int i=0; i<p.size(); i++) {
52 Limits::nonnegative(p[i],"Int::cumulative");
53 Limits::nonnegative(u[i],"Int::cumulative");
54 Limits::check(static_cast<long long int>(s[i].max()) + p[i],
55 "Int::cumulative");
56 mul_check(p[i],u[i]);
57 w += s[i].width();
58 }
59 mul_check(c.max(),w,s.size());
60 GECODE_POST;
61
62 int minU = INT_MAX; int minU2 = INT_MAX; int maxU = INT_MIN;
63 for (int i=0; i<u.size(); i++) {
64 if (u[i] < minU) {
65 minU2 = minU;
66 minU = u[i];
67 } else if (u[i] < minU2)
68 minU2 = u[i];
69 if (u[i] > maxU)
70 maxU = u[i];
71 }
72 bool disjunctive =
73 (minU > c.max()/2) || (minU2 > c.max()/2 && minU+minU2>c.max());
74 if (disjunctive) {
75 GECODE_ME_FAIL(c.gq(home,maxU));
76 unary(home,t,s,p,ipl);
77 } else {
78 bool fixp = true;
79 for (int i=0; i<t.size(); i++)
80 if (t[i] != TT_FIXP) {
81 fixp = false; break;
82 }
83 int nonOptionals = 0;
84 for (int i=0; i<u.size(); i++)
85 if (u[i]>0) nonOptionals++;
86 if (fixp) {
87 TaskArray<ManFixPTask> tasks(home,nonOptionals);
88 int cur = 0;
89 for (int i=0; i<s.size(); i++)
90 if (u[i] > 0)
91 tasks[cur++].init(s[i],p[i],u[i]);
92 GECODE_ES_FAIL(manpost(home,c,tasks,ipl));
93 } else {
94 TaskArray<ManFixPSETask> tasks(home,nonOptionals);
95 int cur = 0;
96 for (int i=0; i<s.size(); i++)
97 if (u[i] > 0)
98 tasks[cur++].init(t[i],s[i],p[i],u[i]);
99 GECODE_ES_FAIL(manpost(home,c,tasks,ipl));
100 }

Callers 7

postMethod · 0.85
postMethod · 0.85
postMethod · 0.85
postMethod · 0.85
p_cumulative_optFunction · 0.85
p_cumulativesFunction · 0.85
p_nooverlapFunction · 0.85

Calls 13

mul_checkFunction · 0.85
unaryFunction · 0.85
ConstIntViewClass · 0.85
IntViewClass · 0.70
checkFunction · 0.50
sizeMethod · 0.45
maxMethod · 0.45
widthMethod · 0.45
gqMethod · 0.45
initMethod · 0.45
oneMethod · 0.45
assignedMethod · 0.45

Tested by

no test coverage detected