使用循环语句@for(AZ(i,j):t(i,j)=k(j,i));互换i,j位置,即置换.
例子:
MODEL:
sets:
row/1..5/;
col/1..5/;
AZ(row,col):k,t;
endsets
data:
k=1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
1 1 1 1 1;
enddata
@for(AZ(i,j):t(i,j)=k(j,i));
END
运行结果:
Feasible solution found.
Total solver iterations: 0
Variable Value
K( 1, 1) 1.000000
K( 1, 2) 2.000000
K( 1, 3) 3.000000
K( 1, 4) 4.000000
K( 1, 5) 5.000000
K( 2, 1) 2.000000
K( 2, 2) 3.000000
K( 2, 3) 4.000000
K( 2, 4) 5.000000
K( 2, 5) 6.000000
K( 3, 1) 3.000000
K( 3, 2) 4.000000
K( 3, 3) 5.000000
K( 3, 4) 6.000000
K( 3, 5) 7.000000
K( 4, 1) 4.000000
K( 4, 2) 5.000000
K( 4, 3) 6.000000
K( 4, 4) 7.000000
K( 4, 5) 8.000000
K( 5, 1) 1.000000
K( 5, 2) 1.000000
K( 5, 3) 1.000000
K( 5, 4) 1.000000
K( 5, 5) 1.000000
T( 1, 1) 1.000000
T( 1, 2) 2.000000
T( 1, 3) 3.000000
T( 1, 4) 4.000000
T( 1, 5) 1.000000
T( 2, 1) 2.000000
T( 2, 2) 3.000000
T( 2, 3) 4.000000
T( 2, 4) 5.000000
T( 2, 5) 1.000000
T( 3, 1) 3.000000
T( 3, 2) 4.000000
T( 3, 3) 5.000000
T( 3, 4) 6.000000
T( 3, 5) 1.000000
T( 4, 1) 4.000000
T( 4, 2) 5.000000
T( 4, 3) 6.000000
T( 4, 4) 7.000000
T( 4, 5) 1.000000
T( 5, 1) 5.000000
T( 5, 2) 6.000000
T( 5, 3) 7.000000
T( 5, 4) 8.000000
T( 5, 5) 1.000000
Row Slack or Surplus
1 0.000000
2 0.000000
3 0.000000
4 0.000000
5 0.000000
6 0.000000
7 0.000000
8 0.000000
9 0.000000
10 0.000000
11 0.000000
12 0.000000
13 0.000000
14 0.000000
15 0.000000
16 0.000000
17 0.000000
18 0.000000
19 0.000000
20 0.000000
21 0.000000
22 0.000000
23 0.000000
24 0.000000
25 0.000000
符合