簡體   English   中英

將元組中的集合傳輸到 CPLEX 中的數組?

[英]Transfer set in tuple to array in CPLEX?

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

我可以將兩個元組中的最后一組提取為 2D 數組,並將第一個元組作為Routes的索引嗎? 如果索引未顯示在第一個矩陣中,則在矩陣中將其設為 0

意思是,

Arr=[
[8,0,5],
[0,7,9]
]
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]]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM