-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaseline_model.mzn
84 lines (66 loc) · 2.22 KB
/
baseline_model.mzn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
include "globals.mzn";
include "diffn.mzn";
include "data.dzn";
%width of big rectangle
int: width;
%number of circuits
int: num_circuits;
%Set of sqaures that we would fit 1..n
set of int: CIRCUIT_DIM = 1..num_circuits;
array[CIRCUIT_DIM] of int: circuitX;
array[CIRCUIT_DIM] of int: circuitY;
% CHANGED BOTH because of inconsistencies
% Lower bound for the height
int: min_height = num_circuits div width;
% Upper bound for the area
int: max_height = num_circuits * max(circuitY);
% X and Y coordinates that we are interedted in finding making sure their domain is in range [0..width] for X and [0..height] for Y
array [ CIRCUIT_DIM ] of var 0..width : X;
array [ CIRCUIT_DIM ] of var 0..max_height: Y;
%Optimal/Minimum height that we are to find
var min_height..max_height: Height;
% Constraints.
% global non-overlap constraint
constraint
forall( i, j in CIRCUIT_DIM where i < j ) (
X[i] + circuitX[i] <= X[j]
\/ X[j] + circuitX[j] <= X[i]
\/ Y[i] + circuitY[i] <= Y[j]
\/ Y[j] + circuitY[j] <= Y[i]
);
% all rows width must be lower than max width
constraint
forall( i in CIRCUIT_DIM ) (
X[i] + circuitX[i] <= width
);
constraint cumulative(
[ X[i] | i in CIRCUIT_DIM ],
[ circuitX[i] | i in CIRCUIT_DIM ],
[ circuitY[i] | i in CIRCUIT_DIM ],
Height
);
% all coloumns height must be lower than max height
constraint
forall( i in CIRCUIT_DIM ) (
Y[i] + circuitY[i] <= Height
);
constraint cumulative(
[ Y[i] | i in CIRCUIT_DIM],
[ circuitY[i] | i in CIRCUIT_DIM ],
[ circuitX[i] | i in CIRCUIT_DIM ],
width
);
% Goal/objective
solve::
int_search([ Height ]
++ [ X[num_circuits] | i in CIRCUIT_DIM ]
++ [ Y[num_circuits] | i in CIRCUIT_DIM ],
input_order, indomain_split, first_fail
)satisfy;
% output sequence
output["\n--max height = ", show(Height)];
output["\n--width =", show(width)];
output["\n--X coordinates ", show(X)];
output["\n--Y coordinates ", show(Y)];
output["\n--X dimensions ", show(circuitX)];
output["\n--Y dimensions ", show(circuitY)];