CPLEX OPL返回带有条件的集合索引

时间:2018-10-24 09:56:49

标签: set tuples cplex opl

我有一个如下的元组,我想返回其ActivePeriod值为“ YES”的第一个元素的TimePeriodID。试图使用first和minl&ord函数,但是没有用。任何帮助将非常感激。谢谢。

tuple timeperiod {
  string TimePeriodID;
  string TimePeriodName;
  float CurrencyRate;
  float Rank;
  string ActivePeriod;
}
{timeperiod} TimePeriods = ...;

1 个答案:

答案 0 :(得分:-1)

tuple timeperiod {
  string TimePeriodID;
  string TimePeriodName;
  float CurrencyRate;
  float Rank;
  string ActivePeriod;
}
{timeperiod} TimePeriods = {<"A","B",1.0,2.3,"NO">,<"V","B",4.0,2.3,"YES">,<"D","B",4.0,2.3,"YES">};

string answer=first({i | i in TimePeriods : i.ActivePeriod=="YES"}).TimePeriodID;

execute
{
writeln(answer);
}

给予

V