-
Notifications
You must be signed in to change notification settings - Fork 36
/
placement.mzn
executable file
·55 lines (39 loc) · 1.25 KB
/
placement.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
include "globals.mzn";
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% INPUT DATA
int: numBins;
set of int: sBin = 1..numBins;
int: numSlots;
set of int: sSlot = 1..numSlots;
set of int: sSlot_ = 0..numSlots;
int: numDescriptors;
set of int: sDescriptor = 1..numDescriptors;
array[sDescriptor] of int: weights;
int: chainLen;
set of int: sChain = 1..chainLen;
array[sChain] of sDescriptor: chain;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DECISION VARIABLES AND CONSTRAINTS
array[sChain] of var sBin: placement;
array[sBin] of var sSlot_: occupacy;
constraint forall (bin in sBin)
(
occupacy[bin] = sum(c in sChain where placement[c]=bin) (weights[chain[c]])
);
constraint forall (bin in sBin)
(
occupacy[bin] <= numSlots
);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% OBJECTIVE FUNCTION
var int: reward = sum(bin in sBin) (pow(2,occupacy[bin]));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SOLVE
solve maximize reward;
%solve minimize reward;
%solve satisfy;
output ["\nService = ",show(chain),
"\nPlacement = ",show(placement),
"\nReward = ",show(reward),
"\nOccupacy = ", show(occupacy),
];