GAMS has strict domain checking (type checking). This has some interesting consequences. Basically all good: much better protection against errors compared to simply using integer indices 1,…,n. Consider the square matrix Ai,j:
set |
The so-called "minij" matrix looks like:
---- 7 PARAMETER A square matrix 1 2 3 4 a 1.000 1.000 1.000 1.000 b 1.000 2.000 2.000 2.000 c 1.000 2.000 3.000 3.000 d 1.000 2.000 3.000 4.000
The task to invert a parameter Ai,j, can be stated as finding a feasible solution to: B⋅A=I or ∑iBj,i⋅Ai,j′=Ij,j′∀j,j′ The first index of A is i which means the second index of B is also i.
So our GAMS code should look like:
set |
This shows:
---- 23 VARIABLE B.L inverse of A a b c d 1 2.000 -1.000 2 -1.000 2.000 -1.000 3 -1.000 2.000 -1.000 4 -1.000 1.000
The same argument holds when we write: A⋅B=I or ∑jAi,j⋅Bj,i′=Ii,i′∀i,i′ The second index of A is j which means the first index of B is also j.
The conclusion is: the inverse of A(i,j) is a symbol with signature B(j,i).
Note that usually we use a single set i and make j,k aliases. That will not reveal the above issue:
set |
---- 25 PARAMETER A square matrix a b c d a 1.000 1.000 1.000 1.000 b 1.000 2.000 2.000 2.000 c 1.000 2.000 3.000 3.000 d 1.000 2.000 3.000 4.000 ---- 25 VARIABLE B.L inverse of A a b c d a 2.000 -1.000 b -1.000 2.000 -1.000 c -1.000 2.000 -1.000 d -1.000 1.000
Similarly, numerical codes for inverting matrices don't worry about this at all: they just see everything in terms of integer index positions i,j∈{1,…,n}.
No comments:
Post a Comment