- if (u1=1, u2=0, u3=1, u4=1) then s=10
- if (u1=0, u2=1, u3=0, u4=1) then s=100
- if...
Code: Select all
determinant corresponding Value
1-0-1-1 10
0-1-0-1 100
...
Moderator: aileen
Code: Select all
determinant corresponding Value
1-0-1-1 10
0-1-0-1 100
...
Code: Select all
set i / 1*4 /
s / 1*5 /
table data(s,*)
1 2 3 4 val
1 0 1 1 0 23
2 1 0 0 1 -5
3 1 0 1 0 16
4 0 1 0 1 4
5 1 1 1 0 111
;
parameter c(i) "cost of i when on";
c(i) = -uniformInt(1,10);
display c;
variable
b(i) "binary selection",
x(s) "indicator that s is active",
z "obj";
binary variables b,x;
equation
defz "obj",
bigm_defx(s) "identification of binary setting of b",
indic_defx(s) "identification of binary setting of b"
;
defz.. z =e= sum(i, c(i)*b(i)) + sum(s, data(s,'val')*x(s));
bigm_defx(s).. sum(i$(1=data(s,i)), b(i)) + sum(i$(0=data(s,i)), 1-b(i)) =g= card(i)*x(s);
indic_defx(s).. sum(i$(1=data(s,i)), b(i)) + sum(i$(0=data(s,i)), 1-b(i)) =e= card(i);
model bigm /defz, bigm_defx/;
option mip=cplex, optcr=0;
solve bigm using mip max z;
display z.l, b.l, x.l;
model indic /defz, indic_defx/;
$echo indic indic_defx(s)$x(s) 1 > cplex.opt
option mip=cplex, optcr=0; indic.optfile=1;
solve indic using mip max z;
display z.l, b.l, x.l;