【问题标题】:Transfer set in tuple to array in CPLEX?将元组中的集合传输到 CPLEX 中的数组?
【发布时间】:2019-11-05 09:14:33
【问题描述】:
{route} Routes ={
<1,{1,3},{8,5}>,
<2,{2,3},{7,9}>
};

我可以将两个元组中的最后一个集合提取为二维数组,并将第一个元组作为来自Routes 的索引吗?如果索引没有显示在第一个矩阵中,则在矩阵中将其设为 0

这意味着,

Arr=[
[8,0,5],
[0,7,9]
]

【问题讨论】:

  • 我不确定在每种情况下在哪里插入“0”。但是,如果您可以精确地制定规则,那么程序就可以执行它。所以试一试,发布你的代码以及你卡在哪里。

标签: arrays algorithm tuples cplex opl


【解决方案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]]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 2017-02-05
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多