Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more comments #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions packing/rotation/sbprgeost.mzn
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
int: n; % number of blocks
% --- Parameters ---

int: n; % number of blocks (also called "shapes")
set of int: BLOCK = 1..n;
int: m; % number of rectangle/offsets

int: m; % number of rectangle/offsets into the 'd' array
set of int: ROFF = 1..m;
array[ROFF,1..4] of int: d; % defns
array[int] of set of ROFF: shape;
array[ROFF,1..4] of int: d; % geometries of rectangles that can be used to compose rotated shapes; 2nd dimension is one of (x,y,w,h)

array[int] of set of ROFF: shape; % array of set of index from ROFF: shapes and their rotations

int: h; % width of river
int: maxl; % maximum length of river


% --- Decision variables ---

array[BLOCK] of var 0..maxl: x;
array[BLOCK] of var 0..h: y;

var 0..maxl: l; % length of river used

solve minimize l;


% --------------------------

% extract the offsets and sizes
array[ROFF,1..2] of int: rsize =
array2d(ROFF, 1..2,
[d[i,j] | i in ROFF, j in 3..4]);
array[ROFF,1..2] of int: roff =
array2d(ROFF, 1..2,
[d[i,j] | i in ROFF, j in 1..2]);

% pack the x and y coordinates
array[BLOCK,1..2] of var int: coord;
constraint forall(i in BLOCK)
(coord[i,1] = x[i] /\ coord[i,2] = y[i]);

% set up the "kind" constraints
array[BLOCK] of var int: kind;
array[BLOCK] of set of int: shapeind;
constraint forall(i in BLOCK)(kind[i] in shapeind[i]);

include "geost.mzn";
constraint geost_bb(2,
rsize,
roff,
shape,
coord,
kind,
rsize, % given: 1st dimension: rectangle index (∈ ROFF), 2nd dimension: 1 (maps to width), 2 (maps to height)
roff, % given: 1st dimension: rectangle index (∈ ROFF), 2nd dimension: 1 (maps to x), 2 (maps to y)
shape, % given: array of set of index (∈ ROFF): shapes and their rotations (a bit less than 4 * card(BLOCK) in length)
coord, % sought: 1st dimension: shape index (∈ BLOCK), 2nd dimension: 1 (maps to x), 2 (maps to y)
kind, % sought: a mapping from shape index (∈ BLOCK) to one of the allowed (rotated) shape description for that index
[ 0,0 ],
[ l,h ]);


output ["l = \(l);\nx = \(x);\ny = \(y);\nkind = \(kind);\n"];
output ["l = \(l);\nx = \(x);\ny = \(y);\nkind = \(kind);\n"];