访问 opl 中的元组元素

问题描述 投票:0回答:2

我正在尝试在我的 .mod 文件中访问元组元素,如下所示:

元组索引类型{

int first_index;
int second_index;
};
{indexType}stu_info = ...;
execute{
   writeln(stu_info.first_index)
}

在我的 .dat 文件中,我有以下内容:

stu_info from DBRead(db,"select S_ID,MSC from table1");

但是当我运行该程序时,它会打印未定义。 我想知道如何访问 ibm cplex 中的元组元素。请帮忙。

tuples cplex
2个回答
0
投票

您需要使用

find()
方法才能获取
stu_info
实例。

所以代替:

writeln(stu_info.first_index)
。 你应该尝试:
writeln(stu_info.find(some key).first_index)

注意:为了使用它,您需要在元组中有一些字段作为键。 例如,

tuple indexType {
 key int first_index;
 int second_index;
};

0
投票

我真的很困惑,因为这对我有用:

writeln(stu_info.find(first_index).second_index);

但这并不:

int variable = stu_info.find(first_index).second_index;

以下错误消息:语法错误,意外的“(”,期待“;”

有什么建议吗?

© www.soinside.com 2019 - 2024. All rights reserved.