60 return new (home)
Pack(home,*
this);
102 }
else if (
_eq >= 0) {
127 int* s = region.
alloc<
int>(m);
129 for (
int j=0; j<m; j++)
136 for (
int i=0; i<n; i++)
137 if (
bs[i].assigned()) {
138 int j =
bs[i].bin().val();
139 l[j].offset(
l[j].offset() -
bs[i].
size());
143 s[j.val()] +=
bs[i].size();
148 for (
int i=0; i<n; i++) {
149 assert(!
bs[i].assigned());
151 s[j.val()] +=
bs[i].size();
157 for (
int j=0; j<m; j++) {
160 min -=
l[j].max();
max -=
l[j].min();
164 for (
bool mod =
true;
mod; ) {
166 for (
int j=0; j<m; j++) {
167 int lj_min =
l[j].min();
168 me =
l[j].gq(home,
min +
l[j].
max());
172 max += lj_min -
l[j].min();
mod =
true;
174 int lj_max =
l[j].max();
175 me =
l[j].lq(home,
max +
l[j].
min());
179 min += lj_max -
l[j].max();
mod =
true;
185 assert(
l.assigned());
194 for (
int i=0; i<n; i++) {
196 if (
bs[i].
size() >
l[j.val()].max())
198 if (s[j.val()] -
bs[i].size() <
l[j.val()].min())
203 if (
bs[i].assigned()) {
204 int j =
bs[i].bin().val();
205 l[j].offset(
l[j].offset() -
bs[i].
size());
231 for (
int j=0; j<m; j++)
235 for (
int i=0; i<n; i++) {
236 assert(!
bs[i].assigned());
241 for (
int j=0; j<m; j++) {
259 for (
int i=0; i<n; i++) {
260 assert(!
bs[i].assigned());
265 if (
nosum(s[j.val()],
266 l[j.val()].min() -
bs[i].size(),
267 l[j.val()].max() -
bs[i].size()))
270 if (
nosum(s[j.val()],
l[j.val()].min(),
l[j.val()].max()))
274 if (
bs[i].assigned()) {
275 int j =
bs[i].bin().val();
276 l[j].offset(
l[j].offset() -
bs[i].
size());
291 int n_bins =
l.size();
292 int n_weights_reductions = n_bins +
bs.size();
293 int* weights_base_reduction =
294 region.
alloc<
int>(n_weights_reductions);
295 int* weights_current_reduction =
296 region.
alloc<
int>(n_weights_reductions);
301 int capacity_base_reduction = 0;
303 capacity_base_reduction, delta_reductions);
307 int& delta = delta_reductions[r_idx];
308 long long int capacity_ll =
309 static_cast<long long int>(capacity_base_reduction) + delta;
311 if ((capacity_ll > 0) &&
312 (capacity_ll <= std::numeric_limits<int>::max())) {
313 int capacity =
static_cast<int>(capacity_ll);
315 int n_not_zero_weights = 0;
317 int*
weights = weights_current_reduction;
318 for (
int w_idx = 0; w_idx < n_weights_reductions; w_idx += 1) {
320 weights_base_reduction[w_idx] + (w_idx < n_bins ? delta : 0);
321 n_not_zero_weights += weight != 0;
322 max_weight = std::max(max_weight, weight);
330 n_not_zero_weights, max_weight);
331 if (lower_bound > n_bins)
337 n_not_zero_weights, max_weight);
338 if (lower_bound > n_bins)
346 n_not_zero_weights, max_weight);
347 if (lower_bound > n_bins)
353 n_not_zero_weights, max_weight,
true);
354 if (lower_bound > n_bins)
360 n_not_zero_weights, max_weight,
true);
361 if (lower_bound > n_bins)
367 n_not_zero_weights, max_weight);
368 if (lower_bound > n_bins)
388 for (
int i=0; i<
bs.size(); i++) {
396 while ((n > 0) && (
bs[n-1].
size() == 0))
400 if (
bs.size() == 0) {
402 for (
int i=0; i<
l.size(); i++)
405 }
else if (
l.size() == 0) {
410 for (
int j=0; j<
l.size(); j++) {
422 int* weights_base_reduction,
423 int& capacity_base_reduction,
424 int* delta_reductions) {
426 int n_weights_reductions =
l.size() +
bs.size();
427 for (
int w_idx = 0; w_idx < n_weights_reductions; w_idx += 1)
428 weights_base_reduction[w_idx] = 0;
431 int n_bins =
l.size();
432 int n_items =
bs.size();
433 capacity_base_reduction = 0;
434 for (
int b_idx = 0; b_idx < n_bins; b_idx += 1)
435 capacity_base_reduction =
436 std::max(capacity_base_reduction,
l[b_idx].
max());
437 for (
int b_idx = 0; b_idx < n_bins; b_idx += 1)
438 weights_base_reduction[b_idx] =
439 capacity_base_reduction -
l[b_idx].
max();
440 for (
int i_idx = 0; i_idx < n_items; i_idx += 1) {
441 bool i_assigned =
bs[i_idx].bin().assigned();
442 int i_weight =
bs[i_idx].size();
444 int b_idx =
bs[i_idx].bin().val();
445 weights_base_reduction[b_idx] += i_weight;
447 weights_base_reduction[n_bins + i_idx] = i_weight;
452 int smallest_virtual_weight = std::numeric_limits<int>::max();
453 for (
int b_idx = 0; b_idx < n_bins; b_idx += 1)
454 smallest_virtual_weight =
455 std::min(smallest_virtual_weight, weights_base_reduction[b_idx]);
456 delta_reductions[0] = -smallest_virtual_weight;
457 delta_reductions[1] = 0;
458 delta_reductions[2] = capacity_base_reduction -
459 smallest_virtual_weight - smallest_virtual_weight + 1;
Base-class for both propagators and branchers.
static ModEvent me(const ModEventDelta &med)
Home class for posting propagators
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.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
ViewArray< Item > bs
Items with bin and size.
int t
Total size of all items.
static int const n_reductions
Reductions.
virtual Actor * copy(Space &home)
Copy propagator during cloning.
bool nosum(const SizeSet &s, int a, int b, int &ap, int &bp)
Detect non-existence of sums in a .. b.
static ExecStatus post(Home home, ViewArray< OffsetView > &l, ViewArray< Item > &bs, IntPropLevel ipl=IPL_DEF)
Post propagator for loads l and items bs.
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Pack(Home home, ViewArray< OffsetView > &l, ViewArray< Item > &bs, IntPropLevel ipl)
Constructor for posting.
static void calc_reductions(const ViewArray< Item > &bs, const ViewArray< OffsetView > &l, int *weights_base_reduction, int &capacity_base_reduction, int *delta_reductions)
virtual void reschedule(Space &home)
Schedule function.
Size sets with one element discarded.
void minus(int s)
Discard size s.
void add(int s)
Add new size s.
int * _nq
Values (sorted) to be pruned from view.
int _n_nq
Number of values to be pruned.
TellCache(Region ®ion, int m)
Initialize cache for at most m values.
ExecStatus tell(Space &home, IntView x)
Perform tell to view x and reset cache.
void eq(int j)
Record that view must be equal to j, return false if not possible.
int _eq
Value to which view should be assigned.
void nq(int j)
Record that view must be different from j.
Integer view for integer variables.
ModEvent minus_v(Space &home, I &i, bool depends=true)
Remove from domain the values described by i.
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Value iterator for integer views.
Value iterator for array of integers
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
size_t size
The size of the propagator (used during subsumption).
ModEventDelta modeventdelta(void) const
Return the modification event delta.
ModEventDelta med
A set of modification events (used during propagation).
void free(void)
Free allocate memory.
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
static ModEvent me(const ModEventDelta &med)
const int capacity[n_warehouses]
Capacity of a single warehouse.
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
int ModEventDelta
Modification event deltas.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
bool me_failed(ModEvent me)
Check whether modification event me is failed.
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
bool me_modified(ModEvent me)
Check whether modification event me describes variable modification.
IntPropLevel
Propagation levels for integer propagators.
@ IPL_BASIC
Use basic propagation algorithm.
@ IPL_ADVANCED
Use advanced propagation algorithm.
void weights(Home home, IntSharedArray elements, IntSharedArray weights, SetVar x, IntVar y)
Post propagator for .
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.
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable).
const Gecode::ModEvent ME_INT_NONE
Domain operation has not changed domain.
void quicksort(Type *l, Type *r, Less &less)
Standard quick sort.
Gecode toplevel namespace
void mod(Home home, IntVar x0, IntVar x1, IntVar x2, IntPropLevel ipl=IPL_DEF)
Post propagator for .
IntPropLevel ba(IntPropLevel ipl)
Extract basic or advanced from propagation level.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
@ ES_OK
Execution is okay.
@ ES_FAILED
Execution has resulted in failure.
@ ES_NOFIX
Propagation has not computed fixpoint.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int ModEvent
Type for modification events.