arrays - 将元组中的集合传输到 CPLEX 中的数组?
问题描述
{route} Routes ={
<1,{1,3},{8,5}>,
<2,{2,3},{7,9}>
};
我可以将两个元组中的最后一组提取为二维数组,并将第一个元组作为索引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]]
推荐阅读
- php - Codeigniter 3 索引方法行为异常
- c++ - 如何在 cpp 的 xmlXPathRegisterNs (libxml2) 中添加多个命名空间
- java - 如何删除分隔符内的空间?
- javascript - 如何水平创建导航菜单的溢出-x 自动
- html - golang服务器提供时html视频标签不播放m3u8文件
- python - 如何改成sigmoid学习多标签分类
- php - 如何反转数组数据?
- influxdb - 写入 Influx DB 结果点超出保留策略已删除=1
- visual-studio - 与 GCC 相比,Visual Studio 是否更好地支持 C++ 中的多线程?
- javascript - Vuejs 子组件中的道具值无法绑定到元素属性