You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OPL CPLEX中基于超集条件关联元组集创建新元组集的方案咨询

OPL CPLEX 工位-任务-工具匹配元组集生成方案

需求背景

你在建模中定义了两个元组集:

  1. 存储任务、对应工具及吞吐量的元组集
tuple taskToolThTuple {string task; string tool; float throughput;};
{taskToolThTuple} taskToolTh = ...;

示例数据:

taskToolTh = {
<"task1", "tool1", 10>
<"task1", "tool2", 11>
<"task1", "tool3", 12>
<"task2", "tool1", 8>
<"task3", "tool1", 9>
<"task3", "tool3", 14>
...
};
  1. 存储工位和配备工具对应关系的元组集
tuple stationToolTuple {string station; string tool;};
{stationToolTuple } stationTool = ...;

示例数据:

stationTool = {
<"station1", "tool1">
<"station2", "tool1">
<"station2", "tool3">
<"station3", "tool2">
<"station3", "tool3">
<"station4", "tool1">
<"station4", "tool2">
<"station4", "tool3">
...
};

你需要生成包含station、tool、task、throughput字段的新元组集,仅当工位具备某任务所需全部工具时,才保留对应关联条目。原写法报错是因为OPL不支持在过滤表达式中直接使用嵌套的聚合集合运算。


纯声明式语法实现方案(无需脚本)

核心思路是把集合计数运算提前到中间元组的构造环节,避免在过滤条件中使用聚合集合,具体实现分三步:

步骤1:预计算每个任务需要的工具总数

tuple taskToolCountTuple {string task; int requiredToolCount;};
{taskToolCountTuple} taskRequiredTools = 
  {<ta, card({to | <ta,to,th> in taskToolTh})> | <ta,to,th> in taskToolTh};

步骤2:预计算每个<工位,任务>对的工具匹配数量

tuple stationTaskMatchCountTuple {string station; string task; int matchedToolCount;};
{stationTaskMatchCountTuple} stationTaskMatch = 
  {<s, ta, card({to | <ta,to,th> in taskToolTh && <s,to> in stationTool})> 
  | <s,to_s> in stationTool, <ta,to_t,th> in taskToolTh};

步骤3:生成符合条件的最终元组集

tuple StationToolTaskThTuple {string station; string tool; string task; float throughput;};
{StationToolTaskThTuple} StationToolTask = 
  {<s, to, ta, th> | 
  <ta,to,th> in taskToolTh, 
  <s,to> in stationTool,
  <ta, reqCnt> in taskRequiredTools,
  <s, ta, matchCnt> in stationTaskMatch
  : reqCnt == matchCnt};

效果验证

以上述示例数据为例:

  • task1需要3个工具,station2的匹配工具数为2,不满足相等条件,对应条目被过滤
  • task2需要1个工具,station2的匹配工具数为1,满足条件,对应条目保留
  • task3需要2个工具,station2的匹配工具数为2,满足条件,对应条目保留
    完全符合需求逻辑,且不会触发聚合集合不支持的报错。

内容的提问来源于stack exchange,提问作者tjnel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 11:06:03