gams:implement_a_lookup-table

Q: *In my case the determinant is the summation of the variables from U1 to Ux that have been introduced as a binary variable to GAMS, in each iteration during the optimization the GAMS is putting this variables 0 > or 1 but the structure of these variables should be considered in the optimization process for example:*

- if we have (u1=1, u2=0, u3=1, u4=0 then s=10
- if (u1=0, u2=1, u3=0, u4=1 then s=100
- if…..

or:

determinant corresponding Value 1-0-1-1 10 0-1-0-1 100 ......

*and so on this setting of variables (Ux in this example) in each iteration will be changed to reach to the optimal point but each setting of variables has a cost (corresponding Value) which is corresponding in the “look up table” so this cost should be considered in the objective function.*

Please have a look at the code below. The second model requires a decent GAMS/CPLEX license:

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;

gams/implement_a_lookup-table.txt · Last modified: 2008/11/11 11:35 by admin