99 :
n(0),
t(0),
s(region.alloc<int>(n_max)) {}
102 t += s0;
s[
n++] = s0;
143 return s[(i <
p) ? i : i+1];
160 for (
int i=0; i<
bs.size(); i++)
168 bs.update(home,p.
bs);
176 return sizeof(*this);
179 template<
class SizeSet>
182 if ((a <= 0) || (b >= s.
total()))
187 while (sc + s[n-kp] < a) {
192 int sa=0, sb = s[n-kp];
193 while ((sa < a) && (sb <= b)) {
199 while (sa + sc >= a) {
202 sb += s[n-kp] - s[n-kp-k-1];
206 ap = sa + sc; bp = sb;
210 template<
class SizeSet>
214 return nosum(s, a, b, ap, bp);
220 int const c0 = w > c - w;
221 int const c1 = w == c - w;
222 int const c2 = w < c - w;
225 int const v0 = 2 * ((c /
l) - ((c - w) /
l));
226 int const v1 = c /
l;
227 int const v2 = 2 * (w /
l);
229 return (c0 * v0) + (c1 * v1) + (c2 * v2);
235 int const c0 = w <
l;
236 int const c1 = (
l <= w) && (w <= c -
l);
237 int const c2 = c -
l < w;
244 return (c0 * v0) + (c1 * v1) + (c2 * v2);
250 int const p =
l - (c %
l);
253 int const c0 = w %
l <= c %
l;
254 int const c1 = w %
l > c %
l;
257 int const v0 = (w /
l) * p;
258 int const v1 = (w /
l) * p + (w %
l) - (c %
l);
260 return (c0 * v0) + (c1 * v1);
266 return v > 0 ? v - 1 : 0;
271 int const c0 = w > c - w;
272 int const c1 = w == c - w;
273 int const c2 = w < c - w;
279 int const v0 = 2 * t0 - 2 * t2;
281 int const v2 = 2 * t1;
283 return (c0 * v0) + (c1 * v1) + (c2 * v2);
289 int const c0 = w * (
l + 1) % c == 0;
290 int const c1 = w * (
l + 1) % c != 0;
293 int const v0 = w *
l;
294 int const v1 = ((w * (
l + 1)) / c) * c;
296 return (c0 * v0) + (c1 * v1);
302 int const c0 = w <
l;
303 int const c1 = (
l <= w) && (w <= c - 2 *
l);
304 int const c2 = (c - 2 *
l < w) && (w < 2 *
l);
308 int const v1 = c / 3;
309 int const v2 = c / 2;
311 return (c0 * v0) + (c1 * v1) + (c2 * v2);
317 int const c0 = w < 2 *
l;
318 int const c1 = 2 *
l <= w;
324 return (c0 * v0) + (c1 * v1);
354 return {c / 4 + 1, c / 3};
359 int n_not_zero_weights,
int max_weight) {
360 long long int n =
static_cast<long long int>(n_not_zero_weights) *
361 static_cast<long long int>(max_weight);
364 std::min(
static_cast<int>(std::numeric_limits<int>::max() / n),
366 return {lambda_range.
min, l_max};
372 template<
int f(
int,
int,
int)>
377 long long int sum_transformed_weights = 0;
378 for (
int w_idx = 0; w_idx < n_weights; w_idx += 1)
385 return static_cast<int>
387 static_cast<long long int>(transformed_capacity)));
390 template<
int f(
int,
int,
int), LambdaRange l(
int)>
393 int capacity,
int n_not_zero_weights,
394 int max_weight,
bool sanitize) {
400 if (lambda_range.
min >= lambda_range.
max)
407 for (
int lambda = lambda_range.
min + l_step;
408 lambda < lambda_range.
max; ) {
409 int cur_lower_bound =
412 lower_bound = std::max(lower_bound, cur_lower_bound);
413 if (lambda > lambda_range.
max - l_step)
virtual size_t dispose(Space &home)
Delete actor and return its size.
Home class for posting propagators
Item combining bin and size information.
IntView bin(void) const
Return bin of item.
void update(Space &home, Item &i)
Update item during cloning.
Item(void)
Default constructor.
int size(void) const
Return size of item.
static LambdaRange l_rad2(int c)
static int f_bj1(int w, int l, int c)
ViewArray< OffsetView > l
Views for load of bins.
static int calc_dff_lower_bound(const int *weights, int n_weights, int capacity, int n_not_zero_weights, int max_weight, bool sanitize=false)
IntPropLevel ipl
Propagation level.
static LambdaRange sanitize_lambda_range(LambdaRange lambda, int n_weights, int max_weight)
static int f_mt(int w, int l, int c)
ViewArray< Item > bs
Items with bin and size.
int t
Total size of all items.
static int f_rad2(int w, int l, int c)
static int calc_dff_lower_bound_single_lambda(const int *weights, int n_weights, int capacity, int lambda)
Lower bound.
static int const n_lambda_samples
static LambdaRange l_ccm1(int c)
static int f_ccm1(int w, int l, int c)
Dual Feasible Functions.
static LambdaRange l_bj1(int c)
bool nosum(const SizeSet &s, int a, int b, int &ap, int &bp)
Detect non-existence of sums in a .. b.
static int f_vb2(int w, int l, int c)
static LambdaRange l_mt(int c)
static int f_vb2_base(int w, int l, int c)
static LambdaRange l_vb2(int c)
Pack(Home home, ViewArray< OffsetView > &l, ViewArray< Item > &bs, IntPropLevel ipl)
Constructor for posting.
static int f_rad2_base(int w, int l, int c)
static LambdaRange l_fs1(int c)
static int f_fs1(int w, int l, int c)
virtual size_t dispose(Space &home)
Destructor.
int operator[](int i) const
Return size of item i.
void minus(int s)
Discard size s.
SizeSetMinusOne(void)
Default constructor.
int p
Position of discarded item.
int total(void) const
Return total size.
int card(void) const
Return cardinality of set (number of entries).
int t
Total size of the set.
SizeSet(void)
Default constructor.
void add(int s)
Add new size s.
int total(void) const
Return total size.
int operator[](int i) const
Return size of item i.
int n
Number of size entries in the set.
int * s
Array of sizes (will have more elements).
int card(void) const
Return cardinality of set (number of entries).
Integer view for integer variables.
Propagator(Home home)
Constructor for posting.
IntPropLevel
Propagation levels for integer propagators.
@ IPL_ADVANCED
Use advanced propagation algorithm.
@ IPL_DEF
Simple propagation levels.
void weights(Home home, IntSharedArray elements, IntSharedArray weights, SetVar x, IntVar y)
Post propagator for .
bool operator<(const Item &i, const Item &j)
Order, also for sorting according to size.
bool operator!=(const Item &i, const Item &j)
Whether two items are not the same.
bool operator==(const Item &i, const Item &j)
Whether two items are the same.
IntType ceil_div_pp(IntType x, IntType y)
Compute where x and y are non-negative.
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Gecode toplevel namespace
IntPropLevel ba(IntPropLevel ipl)
Extract basic or advanced from propagation level.
const int capacity[n_warehouses]
Capacity of a single warehouse.