-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Labels
Description
Using records makes it clearer how data is structured in a model. However, in combination with many constraint being defined over arrays of aspects, it is easy to get into situations where there is a lot of boiler-plate. I think it might make sense to add the ability to access aspects of a record on an array of records.
As an example, consider this simple packing model using the no-overlap ("diffn") constraint
include "globals.mzn";
enum Boxes = B(1..10);
set of int: Pos = 1..100;
array[Boxes] of int: box_size = [20 | b in Boxes];
array[Boxes] of record(var Pos: x, var Pos: y): box;
constraint forall(b in Boxes) (
box[b].x + box_size[b] in Pos /\
box[b].y + box_size[b] in Pos
);
constraint diffn(array1d(Boxes, [box[b].x | b in Boxes]),
array1d(Boxes, [box[b].y | b in Boxes]),
box_size,
box_size);
solve satisfy;
There is a lot of noise around writing the diffn-call. If we instead allowed box.x to represent a Boxes indexed array of var Pos, the constraint could be written like this
constraint diffn(box.x, box.y,
box_size, box_size);
With #968, the call would be less noisy, but having to do an array comprehension each time is still just busy-work.