You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Idea: Accessing aspects of arrays of records directly #970
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
This is pretty high on the to-do list (and should be easy to do). You don't even need #968, because box.x will have the same index set as box, so no additional coercion will be required.
Activity
guidotack commentedon Nov 19, 2025
This is pretty high on the to-do list (and should be easy to do). You don't even need #968, because
box.xwill have the same index set asbox, so no additional coercion will be required.Enable projection of arrays of tuples and records using field access …
nicola-gigante commentedon Nov 28, 2025
Hi all,
this would really simplify my life a lot!
I see there's a commit doing that, do you think it will be merged in a release soon?