Hey all.
I had previously posted a problem of mine, to which I was advised to re-formulate the problem.
Link to previous problem https://newforum.gams.com/t/defining-vaiables-as-vector/3589/8
I am trying to formulate the problem given in the screenshot and code, below.
Pls ignore all the display commands and the disorderliness. I am quite new to GAMS and I am still learning a lot.
Set
i /1*8/
j /1*3/
g /1,2/;
Alias (i,k)
(i,k1)
(i,k2)
(i,k3)
(i,ip);
Alias (j,k4)
(j,k5)
(j,k6)
(j,w)
(j,u);
Variables
L
Z1
cost final cost;
Binary variable
F(i,i) each variable;
cost.l = 350;
F.l(i,i) = 1;
display F.l;
Parameter
IM(i,i) identity matrix;
IM(i,i) = 1;
display IM;
Parameter
C(i, j) C matrix/
1.1 1, 1.2 0, 1.3 0
2.1 1, 2.2 1, 2.3 -1
3.1 1, 3.2 1, 3.3 -1
4.1 1, 4.2 1, 4.3 -1
5.1 0, 5.2 1, 5.3 0
6.1 1, 6.2 0, 6.3 -1
7.1 0, 7.2 1, 7.3 -1
8.1 0, 8.2 0, 8.3 1
/;
display C;
parameter Ct(j,i);
Ct(j,i) = C(i,j);
display Ct;
Parameter Q(i,i);
loop(k1, Q(k1,ip) = sum((i), F.l(k1,i)*IM(i,ip)));
display Q;
Parameter A(w,u) ;
loop(k, A(w,u) = sum((k2,k3),Ct(w,k3)*Q(k3,k2)*C(k2,u)));
display A;
Parameter invA(j,j);
execute_unload 'a.gdx', j, A;
execute '=invert.exe a.gdx j A b.gdx invA';
execute_load 'b.gdx', invA;
display invA;
parameter AA(i,i);
loop(k6, AA(i,i) = sum((k4,k5), C(i,k5)*invA(k5,k4)*Ct(k4,i)));
display AA;
scalar t trace;
t = sum(i,AA(i,i))
display t;
Parameter Y(i,i) Random variable;
Y(i,i) = 0;
Parameter P(i,i) cost per sensor;
P(i,i) = 100;
Parameter TR;
TR = sum(i, Y(i,i));
equation
obj
con1
con2;
obj.. L =e= t/2;
con1.. TR =L= t;
con2.. cost =G= sum((i,ip), F(i,ip)*P(ip,i));
model m /all/;
option qcp = mosek;
m.dictfile = 1;
m.optfile = 1;
$echo SDPSOLUFILE sdpsol.gdx > mosek.opt
Solve m minimizing L using QCP;
display L.l;
Let me explain how the problem works. So basically I need to get values of F11 - F88, which gives me the minimum cost and trace( L value). Also I have given the constraint in such a way that only at most 3 of the F values will be 1 at a time. What the program needs to do is check for all combinations of F11-F88 to get the optimal combination of values. Also the F variable should ideally be a binary variable, as it should only take 0 or 1 as its values.
As you can see from the code, C matrix is defined as such. The F matrix has its diagonal elements as 8 different variables(F11-F88), whose values I’ve for the moment given as 1. It should actually have different values corresponding to the minimizing equation.
Y is an intermediate variable not important.
My first question is, how do I code the semi-definiteness part? These are the constraints that involve the Y variable. Second, is there any way to optimize this code better?
Thank you in advance.