set i1 'facility'/1*4/;
set j1 'floor'/1*2/;
set k1 'slot'/1*2/;

alias(i1,i2);

alias(j1,j2);

alias(k1,k2);

table
     D(j1,k1,j2,k2) Distance between slots k1 and k2 that are respectively on floors j1 and j2
                1.1     1.2     2.1     2.2
        1.1    1000     22      43      66
        1.2     21    1000      98      32
        2.1     43      98    1000      22
        2.2     33      78      65       1000     ;

table
     F(i1,i2) flow between facility i1 and i2 in period t secs
                1        2      3        4
        1       15      10     1.4       6
        2       5       10     100       8
        3       7       2.0     20       9
        4       9       4.0     4.6      6 ;

binary variable X(i1,j1) '1 if facility i1 is on floor j1 and 0 otherwise';
binary variable Y(i1,k1) '1 if facility i1 is on slot k1 and 0 otherwise';
positive variable Z1(i1,j1,k1,i2,j2,k2) 'links';
free variable w;

equations
objfn       objective function

condition_1(i1)
condition_2(j1,k1)
condition_3(i1,j1,k1,i2,j2,k2)
;

objfn.. sum((i1,j1,k1,i2,j2,k2), Z1(i1,j1,k1,i2,j2,k2)* F(i1,i2)*D(j1,k1,j2,k2)) =e= w ;

condition_1(i1).. sum((j1,k1), X(i1,j1)*Y(i1,k1)) =e= 1 ;
condition_2(j1,k1).. sum((i1), X(i1,j1)*Y(i1,k1)) =e= 1 ;
condition_3(i1,j1,k1,i2,j2,k2).. (4 - [X(i1,j1) + Y(i1,k1) + X(i2,j2) + Y(i2,k2)])*1000 +
                              Z1(i1,j1,k1,i2,j2,k2) =g= 1 ;

Model Problem /all/;

problem.nodlim = 1e9;
$onecho > sbb.opt
memnodes 1e6
$offecho
problem.optfile = 1;
option minlp = sbb;

Solve Problem using miqcp minimising w ;

Display w.l ;
