将元组中的传输设置为CPLEX中的数组吗?

问题描述 投票:-1回答:1
{route} Routes ={
<1,{1,3},{8,5}>,
<2,{2,3},{7,9}>
};

我可以引出两个元组作为2D数组中的最后一个集合,而第一个元组作为Routes中的索引吗?如果索引未在第一个矩阵中显示,则在矩阵中将其设为0

哪个意思,

Arr=[
[8,0,5],
[0,7,9]
]
arrays algorithm tuples cplex opl
1个回答
1
投票
tuple route
{
key int r;
{int} s1;
{int} s2;
}

{route} Routes ={
<1,{1,3},{8,5}>,
<2,{2,3},{7,9}>
};

sorted {int} indexes1={i.r | i in Routes};
sorted {int} indexes2=union (i in Routes) i.s1;

int res[i in indexes1][j in indexes2]=(j in item(Routes,<i>).s1)
    ?item(item(Routes,<i>).s2,ord(item(Routes,<i>).s1,j))
    :0;

execute
{
writeln(indexes1);
writeln(indexes2);
writeln(res);
} 

给予

{1 2}
 {1 2 3}
 [[8 0 5]
         [0 7 9]]
© www.soinside.com 2019 - 2024. All rights reserved.