[ library(gfd) | Reference Manual | Alphabetic Index ]

disjoint2(+Rectangles)

Constrains the position (and possibly size) of the rectangles in Rectangles so that none overlaps.
Rectangles
Collection of rect{} structures specifying the position and size of rectangles on a grid.

Description

A two dimensional disjunctive constraint that constrains the replacement of a collection of rectangles specified by Rectangles to not overlap in their areas.

Each rectangle is defined by a rect named structure, using the following fields:

x:
The x co-ordinate of the left side of the rectangle
y:
The y co-ordinate of the bottom side of the rectangle.
w:
The width of the rectangle
h:
The height of the rectangle
x, y, w, h can be domain variables or integers. If w and h are integers, then the rectangle is of a fixed size. Note the rect{} structure has an additional 'o' field, which is ignored for this constraint as it is only used for disjoint2_optional/1.

Note that the constraint is implemented by different Gecode propagators, depending on if all the rectangles are of fixed size or not. If at least one rectangle is not of fixed size, then the Gecode propagator requires additional variables for the right and top sides of the rectangles, plus additional constraints

        
      Xright #= Xleft + Width
      Ytop   #= Ybot + Height
for each rectangles. These are posted as part of the constraint (the Xright and Ytop variables are not accessible by the user).

Any input variables which are not already domain variables will be converted into domain variables with default bounds.

A version of this constraint, generalised from two to multi- dimension, is known as diffn in the Global Constraint Catalog.

This constraint is implemented using Gecode's nooverlap() constraint.

Examples

[eclipse 17]: disjoint2([rect{x:2,y:1,w:2,h:3},rect{x:4,y:3,w:4,h:3},
                   rect{x:9,w:2,y:4,h:3}]).    % succeed

See Also

disjoint2_optional / 1, lists : collection_to_list / 2