## Creating table with variables

Problems with modeling
AMIIT
User
Posts: 7
Joined: 1 month ago

### Creating table with variables

I have 8 variables, which can take either a 0 or 1 as value. These variables are the diagonal elements of a matrix. I want to write a program that can first make such a matrix and second use it for some calculations.
Attaching an example code:

positive variables
F1, F2, F3, F4, F5, F6, F7, F8;

Variables
Z;

Set
i flows /a, b, c, d, e, f, g, h/
j cmaa /x, y, z/;

Alias (i,k)
(k,k2)
(k,k3);
Alias (j,k4)
(j,k5)
(j,k6);

Parameter
C(i, j)/

a.x 1, a.y 0, a.z 0
b.x 1, b.y 1, b.z -1
c.x 1, c.y 1, c.z -1
d.x 1, d.y 1, d.z -1
e.x 0, e.y 1, e.z 0
f.x 1, f.y 0, f.z -1
g.x 0, g.y 1, g.z -1
h.x 0, h.y 0, h.z 1
/;

display C;

Parameter
Q(i, i)/

a.a 0, a.b 0, a.c 0, a.d 0, a.e 0, a.f 0, a.g 0, a.h 0
b.a 0, b.b 0, b.c 0, b.d 0, b.e 0, b.f 0, b.g 0, b.h 0
c.a 0, c.b 0, c.c 0, c.d 0, c.e 0, c.f 0, c.g 0, c.h 0
d.a 0, d.b 0, d.c 0, d.d 0, d.e 0, d.f 0, d.g 0, d.h 0
e.a 0, e.b 0, e.c 0, e.d 0, e.e 0, e.f 0, e.g 0, e.h 0
f.a 0, f.b 0, f.c 0, f.d 0, f.e 0, f.f 1, f.g 0, f.h 0
g.a 0, g.b 0, g.c 0, g.d 0, g.e 0, g.f 0, g.g 1, g.h 0
h.a 0, h.b 0, h.c 0, h.d 0, h.e 0, h.f 0, h.g 0, h.h 1

/;

display Q;

parameter Ct(j,i);

Ct(j,i) = C(i,j);

display Ct;

Parameter A(j,j);

loop(k, A(j,j) = sum((k2,k3),Ct(j,k3)*Q(k3,k2)*C(k2,j)));

display A;

Parameter invA(j,j);

execute '=invert.exe a.gdx j A b.gdx invA';

display invA;

parameter F(i,i);

loop(k6, F(i,i) = sum((k4,k5), C(i,k5)*invA(k5,k4)*Ct(k4,i)));

display F;

scalar D;
D = sum(i,F(i,i))

display D;

The diagonal elements of matrix Q are supposed to be the variables. I will be giving a condition where any of the 3 out of 8 variables can be 1 (here F6,F7 and F8 are 1) and then the calculations have to follow. I have to minimize D value subject to the above mentioned condition. How will I execute this? Also is there a way to optimize this code?