Michael
Michael

Reputation: 575

Calculate specific matrix in GAMS

Consider the following data in GAMS:

Set i / 0*3 /;

Parameters
    r(i)
    /   2 0.272727
        3 0.8  /
    s(i)
    /   2 0.727273
        3 0.2  /;

I want to calculate the following matrix (from this link):

Text

So I will end up with the following matrix:

Text

How to do that in GAMS?

Upvotes: 0

Views: 46

Answers (1)

Lutz
Lutz

Reputation: 2292

In your question the matrix you expect is missing, but I guess, you are looking for something like $-conditions in GAMS and want to do something like this:

Set i / 0*3 /;

Parameters
    r(i)
    /   2 0.272727
        3 0.8  /
    s(i)
    /   2 0.727273
        3 0.2  /;
        
Alias (i,j);
Parameter u(i,j);

u(i,j) =   r(i)$(ord(i)=ord(j)+1)
         + 2   $(ord(i)=ord(j)  )
         + s(i)$(ord(i)=ord(j)-1);

Upvotes: 1

Related Questions