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

disjoint2_optional(+Rectangles)

Constrains the position (and possibly size) of the (possibly optional) 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. The placement of each rectangle can be optional, i.e. they may not need to be placed.

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
b:
Boolean specifying if rectangle is placed or not
x, y, w, h can be domain variables or integers. If w and h are integers, then the rectangle is of a fixed size. o is a 0/1 integer or domain variable, 1 specifies that the rectangle needs to be placed, and 0 that it is not placed.

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, and without optional placement, is known as diffn in the Global Constraint Catalog. It is implemented using Gecode's nooverlap() constraint (variant with optional placement).

See Also

disjoint2 / 1, eclipse_6 : collection_to_list / 2, lists : collection_to_list / 2